Explorar el Código

update example

xuty hace 4 años
padre
commit
a95e7474ea

BIN
example/fonts/CascadiaMonoPL.ttf


+ 115 - 0
example/lib/isolate.dart

@@ -0,0 +1,115 @@
+import 'dart:async';
+
+import 'package:flutter/material.dart';
+import 'package:xterm/flutter.dart';
+import 'package:xterm/xterm.dart';
+import 'package:xterm/isolate.dart';
+
+void main() {
+  runApp(MyApp());
+}
+
+class MyApp extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    return MaterialApp(
+      title: 'xterm.dart demo',
+      theme: ThemeData(
+        primarySwatch: Colors.blue,
+        visualDensity: VisualDensity.adaptivePlatformDensity,
+      ),
+      home: MyHomePage(),
+    );
+  }
+}
+
+class MyHomePage extends StatefulWidget {
+  MyHomePage({Key key}) : super(key: key);
+
+  @override
+  _MyHomePageState createState() => _MyHomePageState();
+}
+
+class FakeTerminalBackend implements TerminalBackend {
+  Completer<int> _exitCodeCompleter;
+  // ignore: close_sinks
+  StreamController<String> _outStream;
+
+  FakeTerminalBackend();
+
+  @override
+  Future<int> get exitCode => _exitCodeCompleter.future;
+
+  @override
+  void init() {
+    _exitCodeCompleter = Completer<int>();
+    _outStream = StreamController<String>();
+    _outStream.sink.add('xterm.dart demo');
+    _outStream.sink.add('\r\n');
+    _outStream.sink.add('\$ ');
+  }
+
+  @override
+  Stream<String> get out => _outStream.stream;
+
+  @override
+  void resize(int width, int height) {
+    // NOOP
+  }
+
+  @override
+  void write(String input) {
+    if (input.length <= 0) {
+      return;
+    }
+    // in a "real" terminal emulation you would connect onInput to the backend
+    // (like a pty or ssh connection) that then handles the changes in the
+    // terminal.
+    // As we don't have a connected backend here we simulate the changes by
+    // directly writing to the terminal.
+    if (input == '\r') {
+      _outStream.sink.add('\r\n');
+      _outStream.sink.add('\$ ');
+    } else if (input.codeUnitAt(0) == 127) {
+      // Backspace handling
+      _outStream.sink.add('\b \b');
+    } else {
+      _outStream.sink.add(input);
+    }
+  }
+
+  @override
+  void terminate() {
+    //NOOP
+  }
+
+  @override
+  void ackProcessed() {
+    //NOOP
+  }
+}
+
+class _MyHomePageState extends State<MyHomePage> {
+  TerminalIsolate terminal;
+
+  @override
+  void initState() {
+    super.initState();
+    terminal = TerminalIsolate(
+      backend: FakeTerminalBackend(),
+      maxLines: 10000,
+    );
+    terminal.start();
+  }
+
+  void onInput(String input) {}
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      body: SafeArea(
+        child: TerminalView(terminal: terminal),
+      ),
+    );
+  }
+}

+ 6 - 5
example/lib/main.dart

@@ -3,7 +3,6 @@ import 'dart:async';
 import 'package:flutter/material.dart';
 import 'package:xterm/flutter.dart';
 import 'package:xterm/xterm.dart';
-import 'package:xterm/isolate.dart';
 
 void main() {
   runApp(MyApp());
@@ -90,16 +89,15 @@ class FakeTerminalBackend implements TerminalBackend {
 }
 
 class _MyHomePageState extends State<MyHomePage> {
-  TerminalIsolate terminal;
+  Terminal terminal;
 
   @override
   void initState() {
     super.initState();
-    terminal = TerminalIsolate(
+    terminal = Terminal(
       backend: FakeTerminalBackend(),
       maxLines: 10000,
     );
-    terminal.start();
   }
 
   void onInput(String input) {}
@@ -108,7 +106,10 @@ class _MyHomePageState extends State<MyHomePage> {
   Widget build(BuildContext context) {
     return Scaffold(
       body: SafeArea(
-        child: TerminalView(terminal: terminal),
+        child: TerminalView(
+          terminal: terminal,
+          style: TerminalStyle(fontFamily: ['Cascadia Mono']),
+        ),
       ),
     );
   }

+ 4 - 4
example/pubspec.lock

@@ -14,7 +14,7 @@ packages:
       name: async
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.5.0"
+    version: "2.6.1"
   boolean_selector:
     dependency: transitive
     description:
@@ -171,7 +171,7 @@ packages:
       name: source_span
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "1.8.0"
+    version: "1.8.1"
   stack_trace:
     dependency: transitive
     description:
@@ -206,7 +206,7 @@ packages:
       name: test_api
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "0.2.19"
+    version: "0.3.0"
   tweetnacl:
     dependency: transitive
     description:
@@ -243,7 +243,7 @@ packages:
       path: ".."
       relative: true
     source: path
-    version: "2.0.0"
+    version: "2.3.0-pre"
 sdks:
   dart: ">=2.12.0 <3.0.0"
   flutter: ">=2.0.0"

+ 4 - 0
example/pubspec.yaml

@@ -81,3 +81,7 @@ flutter:
   #
   # For details regarding fonts from package dependencies,
   # see https://flutter.dev/custom-fonts/#from-packages
+  fonts:
+    - family: Cascadia Mono
+      fonts:
+        - asset: fonts/CascadiaMonoPL.ttf