terminalstudio / flutter_pty Goto Github PK
View Code? Open in Web Editor NEWPty for Flutter. Provides the ability to create processes with pseudo terminal file descriptors.
Home Page: https://pub.dev/packages/flutter_pty
License: MIT License
Pty for Flutter. Provides the ability to create processes with pseudo terminal file descriptors.
Home Page: https://pub.dev/packages/flutter_pty
License: MIT License
The following error occurred when using powershell.exe
the process exited with exit code 4294901760
hello friends, I have a project which contains a windows terminal (CMD).
The following packages I use:
https://pub.dev/packages/flutter_pty
https://pub.dev/packages/xterm
However, there are several obstacles including:
1. can't ping google.com (gambar 1)
2. can't stream YouTube via ffmpeg (gambar 2)
out of curiosity I tried to clone the example project from the packages I was using
https://github.com/TerminalStudio/flutter_pty
without changing anything, but the result is the same (gambar 3)
anyone can help?
Add the following code in android{}
of build.gradle
// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) {
namespace 'com.example.flutter_pty'
}
First, there seems to be a typo in CMakeLists.txt which calls for "flutter_pty.cc" but the file is called "flutter_pty.c"
After fixing that, building on Linux fails with a missing library:
> flutter run -d linux
Launching lib/main.dart on Linux in debug mode...
/home/user/Development/flutter_pty/example/linux/flutter/ephemeral/.plugin_symlinks/flutter_pty/src/flutter_pty.h:11:10: fatal error: 'util.h' file not found
Building Linux application...
Exception: Build process failed
Hi there,
I was excited to discover xterm
and flutter_pty
today. Thanks for all of your work.
I'm trying to connect xterm
and flutter_pty
and I'm having a difficult time getting the input to render to the screen. I'm guessing I haven't implemented LocalTerminalBackend#out
correctly.
Also, wherever I try to call pty.output.listen
I get the following error:
Exception has occurred.
StateError (Bad state: Stream has already been listened to.)
Here's my code:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_pty/flutter_pty.dart';
import 'package:xterm/flutter.dart';
import 'package:xterm/xterm.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'xterm / flutter_pty demo',
home: LocalTerminal(),
);
}
}
class LocalTerminalBackend implements TerminalBackend {
LocalTerminalBackend();
final pty = Pty.start('bash');
@override
void init() {
// NOOP
}
@override
void write(String input) => pty.write(const Utf8Encoder().convert(input));
@override
Stream<String> get out =>
pty.output.map((data) => String.fromCharCodes(data));
@override
void resize(int width, int height, int pixelWidth, int pixelHeight) =>
pty.resize(width, height);
@override
void ackProcessed() {
// NOOP
}
@override
Future<int> get exitCode => pty.exitCode;
@override
void terminate() => pty.kill();
}
class LocalTerminal extends StatefulWidget {
const LocalTerminal({Key? key}) : super(key: key);
@override
_LocalTerminalState createState() => _LocalTerminalState();
}
class _LocalTerminalState extends State<LocalTerminal> {
late Terminal terminal;
@override
void initState() {
super.initState();
terminal = Terminal(maxLines: 10000, backend: LocalTerminalBackend());
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: TerminalView(
terminal: terminal,
),
),
);
}
}
I'm sure I'm doing something wrong. Any help getting this working is greatly appreciated. Thanks!
When I use "powershell.exe" instead of "cmd.exe", an error is reported.
Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d
Even if I start with cmd.exe and enter "powershell" in it, the same error is reported
My Code:
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_pty/flutter_pty.dart';
import 'package:xterm/xterm.dart';
class TerminalTabView extends StatefulWidget {
const TerminalTabView({super.key});
@override
State<TerminalTabView> createState() => _TerminalTabViewState();
}
class _TerminalTabViewState extends State<TerminalTabView> {
final TerminalController _terminalController = TerminalController();
late final Pty _pty;
late final Terminal _terminal = Terminal(maxLines: 10000);
@override
void initState() {
WidgetsBinding.instance.endOfFrame.then(
(_) {
if (mounted) {
_startPty();
}
},
);
}
void _startPty() {
_pty = Pty.start(
shell,
columns: _terminal.viewWidth,
rows: _terminal.viewHeight,
);
_pty.output
.cast<List<int>>()
.transform(const Utf8Decoder())
.listen(_terminal.write);
_pty.exitCode.then((code) {
_terminal.write('the process exited with exit code $code');
});
_terminal.onOutput = (data) {
_pty.write(const Utf8Encoder().convert(data));
};
_terminal.onResize = (w, h, pw, ph) {
_pty.resize(h, w);
};
}
String get shell {
if (Platform.isMacOS || Platform.isLinux) {
return Platform.environment['SHELL'] ?? 'bash';
}
if (Platform.isWindows) {
return 'cmd.exe';
}
return 'sh';
}
@override
Widget build(BuildContext context) {
return Container(
color: const Color.fromRGBO(30, 30, 30, 1.0),
child: Padding(
padding: const EdgeInsets.all(20),
child: TerminalView(
_terminal,
controller: _terminalController,
autofocus: true,
onSecondaryTapDown: (details, offset) async {},
),
),
);
}
}
I think you should use "ClosePseudoConsole" in "flutter_pty_win.c" , in function start_wait_exit_thread , here is the code:
static DWORD WINAPI wait_exit_thread(LPVOID arg)
{
WaitExitOptions *options = (WaitExitOptions *)arg;
DWORD exit_code = 0;
WaitForSingleObject(options->pid, INFINITE);
GetExitCodeProcess(options->pid, &exit_code);
CloseHandle(options->pid);
CloseHandle(options->hMutex);
ClosePseudoConsole(options->hpty); // To close the PseudoConsole
Dart_PostInteger_DL(options->port, exit_code);
return 0;
}
static void start_wait_exit_thread(HANDLE pid, Dart_Port port, HANDLE mutex, HPCON hpty)
{
WaitExitOptions *options = malloc(sizeof(WaitExitOptions));
options->pid = pid;
options->port = port;
options->hMutex = mutex;
options->hpty = hpty; // add htpy
DWORD thread_id;
HANDLE thread = CreateThread(NULL, 0, wait_exit_thread, options, 0, &thread_id);
if (thread == NULL)
{
free(options);
}
}
If not close the Pseudo , when close the port , there is a conhost process can not be kill.
I tried your library and used in app to run exe binary but always permission denied, I did chmod 777 but it doesn't work how to do it?
I get this:
C:/Users/jens/scoop/apps/dart/3.1.0/bin/dart.exe --enable-asserts C:\Users\jens\MyProjects\flutter-learn\dart-pty-test\bin\dart_pty_test.dart
Unhandled exception:
Invalid argument(s): Failed to load dynamic library 'flutter_pty.dll': error code 126
#0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:43)
#1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:22:12)
#2 _dylib.<anonymous closure> (package:flutter_pty/flutter_pty.dart:20:27)
#3 _dylib (package:flutter_pty/flutter_pty.dart:23:2)
#4 _dylib (package:flutter_pty/flutter_pty.dart)
#5 _bindings (package:flutter_pty/flutter_pty.dart:25:38)
#6 _bindings (package:flutter_pty/flutter_pty.dart)
#7 _init.<anonymous closure> (package:flutter_pty/flutter_pty.dart:28:10)
#8 _init (package:flutter_pty/flutter_pty.dart:29:2)
#9 _init (package:flutter_pty/flutter_pty.dart)
#10 _ensureInitialized (package:flutter_pty/flutter_pty.dart:32:7)
#11 new Pty.start (package:flutter_pty/flutter_pty.dart:57:5)
#12 main (file:///C:/Users/jens/MyProjects/flutter-learn/dart-pty-test/bin/dart_pty_test.dart:8:19)
#13 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
#14 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
Process finished with exit code 255
with:
import 'dart:convert';
import 'package:flutter_pty/flutter_pty.dart';
void main() {
final pty = Pty.start('powershell');
pty.output.listen((event) {
print(utf8.decode(event));
});
pty.resize(30, 80);
pty.kill();
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.