Explorar el Código

Merge branch 'master' of https://github.com/TerminalStudio/xterm.dart

xuty hace 5 años
padre
commit
eee60d02c0

+ 17 - 0
CHANGELOG.md

@@ -1,3 +1,20 @@
+## [1.2.0] - 2021-2-15
+
+* Pass TerminalView's autofocus to the InputListener that it creates. [#10](https://github.com/TerminalStudio/xterm.dart/pull/10), thanks [@timburks](https://github.com/timburks)
+
+## [1.2.0-pre] - 2021-1-20
+
+* add the ability to use fonts from the google_fonts package [#9](https://github.com/TerminalStudio/xterm.dart/pull/9)
+
+## [1.1.1+1] - 2020-10-4
+
+* Update readme
+
+
+## [1.1.1] - 2020-10-4
+
+* Add brightWhite to TerminalTheme
+
 ## [1.1.0] - 2020-9-29
 
 * Fix web support.

+ 13 - 6
README.md

@@ -13,7 +13,7 @@
 
 > This package requires Flutter version >=1.22.0
 
-### Screenshots
+## Screenshots
 
 <table>
   <tr>
@@ -34,7 +34,7 @@
   </tr>
 </table>
 
-### Features
+## Features
 
 - 📦 **Works out of the box** No special configuration required.
 - 🚀 **Fast** Renders at 60fps.
@@ -42,7 +42,7 @@
 - ✂️ **Customizable** 
 - ✔ **Frontend independent**: The terminal core can work without flutter frontend.
 
-### Getting Started
+## Getting Started
 
 **1.** Add this to your package's pubspec.yaml file:
 
@@ -86,12 +86,19 @@ terminal.write('Hello, world!');
 
 **Done!**
 
-### Example
+## Example
 
-**ssh example**: https://github.com/TerminalStudio/xterm.dart/blob/master/example/lib/ssh.dart
+- **local pty example**: [Terminal Lite](https://github.com/TerminalStudio/xterm.dart)
 
+- **ssh example**: https://github.com/TerminalStudio/xterm.dart/blob/master/example/lib/ssh.dart
 <img width="400px" src="https://raw.githubusercontent.com/TerminalStudio/xterm.dart/master/media/example-ssh.png">
 
-### License
+## Features and bugs
+
+Please file feature requests and bugs at the [issue tracker](https://github.com/TerminalStudio/xterm.dart/issues).
+
+Contributions are always welcome!
+
+## License
 
 This project is licensed under an MIT license.

+ 2 - 0
lib/frontend/input_behavior.dart

@@ -7,6 +7,8 @@ abstract class InputBehavior {
 
   bool get acceptKeyStroke;
 
+  TextEditingValue get initEditingState;
+
   void onKeyStroke(RawKeyEvent event, Terminal terminal);
 
   TextEditingValue onTextEdit(TextEditingValue value, Terminal terminal);

+ 3 - 0
lib/frontend/input_behavior_default.dart

@@ -10,6 +10,9 @@ class InputBehaviorDefault extends InputBehavior {
   @override
   bool get acceptKeyStroke => true;
 
+  @override
+  TextEditingValue get initEditingState => TextEditingValue.empty;
+
   @override
   void onKeyStroke(RawKeyEvent event, Terminal terminal) {
     if (event is! RawKeyDownEvent) {

+ 8 - 8
lib/frontend/input_behavior_mobile.dart

@@ -7,14 +7,17 @@ import 'package:xterm/xterm.dart';
 class InputBehaviorMobile extends InputBehaviorDefault {
   const InputBehaviorMobile();
 
-  static const _placeholder = '  ';
+  final acceptKeyStroke = false;
 
-  bool get acceptKeyStroke => false;
+  final initEditingState = const TextEditingValue(
+    text: '  ',
+    selection: TextSelection.collapsed(offset: 1),
+  );
 
   TextEditingValue onTextEdit(TextEditingValue value, Terminal terminal) {
-    if (value.text.length > _placeholder.length) {
+    if (value.text.length > initEditingState.text.length) {
       terminal.onInput(value.text.substring(1, value.text.length - 1));
-    } else if (value.text.length < _placeholder.length) {
+    } else if (value.text.length < initEditingState.text.length) {
       terminal.keyInput(TerminalKey.backspace);
     } else {
       if (value.selection.baseOffset < 1) {
@@ -24,10 +27,7 @@ class InputBehaviorMobile extends InputBehaviorDefault {
       }
     }
 
-    return TextEditingValue(
-      text: _placeholder,
-      selection: TextSelection.collapsed(offset: 1),
-    );
+    return initEditingState;
   }
 
   void onAction(TextInputAction action, Terminal terminal) {

+ 3 - 1
lib/frontend/input_listener.dart

@@ -24,6 +24,7 @@ class InputListener extends StatefulWidget {
     this.autofocus = false,
     this.listenKeyStroke = true,
     this.readOnly = false,
+    this.initEditingState = TextEditingValue.empty,
   });
 
   final Widget child;
@@ -35,6 +36,7 @@ class InputListener extends StatefulWidget {
   final FocusNode focusNode;
   final bool listenKeyStroke;
   final bool readOnly;
+  final TextEditingValue initEditingState;
 
   @override
   InputListenerState createState() => InputListenerState();
@@ -167,7 +169,7 @@ class InputListenerState extends State<InputListener>
         Matrix4.translationValues(dx, dy, 0.0),
       );
 
-      _conn.setEditingState(TextEditingValue.empty);
+      _conn.setEditingState(widget.initEditingState);
     }
   }
 

+ 31 - 67
lib/frontend/terminal_view.dart

@@ -53,11 +53,15 @@ class TerminalView extends StatefulWidget {
 
     final text = Text(
       testString,
-      style: TextStyle(
-        fontFamily: 'monospace',
-        fontFamilyFallback: style.fontFamily,
-        fontSize: style.fontSize,
-      ),
+      style: (style.textStyleProvider != null)
+          ? style.textStyleProvider(
+              fontSize: style.fontSize,
+            )
+          : TextStyle(
+              fontFamily: 'monospace',
+              fontFamilyFallback: style.fontFamily,
+              fontSize: style.fontSize,
+            ),
     );
 
     final size = textSize(text);
@@ -150,7 +154,8 @@ class _TerminalViewState extends State<TerminalView> {
       onAction: onAction,
       onFocus: onFocus,
       focusNode: widget.focusNode,
-      autofocus: false,
+      autofocus: widget.autofocus,
+      initEditingState: widget.inputBehavior.initEditingState,
       child: MouseRegion(
         cursor: SystemMouseCursors.text,
         child: LayoutBuilder(builder: (context, constraints) {
@@ -315,8 +320,6 @@ class TerminalPainter extends CustomPainter {
     }
 
     paintText(canvas);
-    // print(textLayoutCacheV2.length);
-    // or paintTextFast(canvas);
 
     paintSelection(canvas);
   }
@@ -411,55 +414,6 @@ class TerminalPainter extends CustomPainter {
     }
   }
 
-  void paintTextFast(Canvas canvas) {
-    final lines = terminal.getVisibleLines();
-
-    for (var i = 0; i < lines.length; i++) {
-      final line = lines[i];
-      final offsetY = i * charSize.cellHeight;
-      final cellCount = math.min(terminal.viewWidth, line.length);
-
-      final builder = StringBuffer();
-      for (var i = 0; i < cellCount; i++) {
-        final cell = line.getCell(i);
-
-        if (cell.attr == null || cell.width == 0) {
-          continue;
-        }
-
-        if (cell.codePoint == null) {
-          builder.write(' ');
-        } else {
-          builder.writeCharCode(cell.codePoint);
-        }
-
-        // final offsetX = i * charSize.effectWidth;
-        // paintCell(canvas, cell, offsetX, offsetY);
-      }
-
-      final style = TextStyle(
-        // color: color,
-        // fontWeight: cell.attr.bold ? FontWeight.bold : FontWeight.normal,
-        // fontStyle: cell.attr.italic ? FontStyle.italic : FontStyle.normal,
-        fontSize: view.style.fontSize,
-        letterSpacing: charSize.letterSpacing,
-        fontFeatures: [FontFeature.tabularFigures()],
-        // decoration:
-        //     cell.attr.underline ? TextDecoration.underline : TextDecoration.none,
-        fontFamilyFallback: view.style.fontFamily,
-      );
-
-      final span = TextSpan(
-        text: builder.toString(),
-        style: style,
-      );
-
-      final tp = textLayoutCache.getOrPerformLayout(span);
-
-      tp.paint(canvas, Offset(0, offsetY));
-    }
-  }
-
   void paintCell(Canvas canvas, Cell cell, double offsetX, double offsetY) {
     if (cell.codePoint == null || cell.attr.invisible) {
       return;
@@ -475,16 +429,26 @@ class TerminalPainter extends CustomPainter {
       color = color.withOpacity(0.5);
     }
 
-    final style = TextStyle(
-        color: color,
-        fontWeight: cell.attr.bold ? FontWeight.bold : FontWeight.normal,
-        fontStyle: cell.attr.italic ? FontStyle.italic : FontStyle.normal,
-        fontSize: view.style.fontSize,
-        decoration: cell.attr.underline
-            ? TextDecoration.underline
-            : TextDecoration.none,
-        fontFamily: 'monospace',
-        fontFamilyFallback: view.style.fontFamily);
+    final style = (view.style.textStyleProvider != null)
+        ? view.style.textStyleProvider(
+            color: color,
+            fontWeight: cell.attr.bold ? FontWeight.bold : FontWeight.normal,
+            fontStyle: cell.attr.italic ? FontStyle.italic : FontStyle.normal,
+            fontSize: view.style.fontSize,
+            decoration: cell.attr.underline
+                ? TextDecoration.underline
+                : TextDecoration.none,
+          )
+        : TextStyle(
+            color: color,
+            fontWeight: cell.attr.bold ? FontWeight.bold : FontWeight.normal,
+            fontStyle: cell.attr.italic ? FontStyle.italic : FontStyle.normal,
+            fontSize: view.style.fontSize,
+            decoration: cell.attr.underline
+                ? TextDecoration.underline
+                : TextDecoration.none,
+            fontFamily: 'monospace',
+            fontFamilyFallback: view.style.fontFamily);
 
     final span = TextSpan(
       text: String.fromCharCode(cell.codePoint),

+ 2 - 0
lib/terminal/platform.dart

@@ -2,7 +2,9 @@ class PlatformBehavior {
   const PlatformBehavior({this.oscTerminators});
 
   final Set<int> oscTerminators;
+}
 
+class PlatformBehaviors {
   static const unix = PlatformBehavior(oscTerminators: {0x07, 0x5c});
   static const windows = PlatformBehavior(oscTerminators: {0x07, 0x00});
 }

+ 2 - 3
lib/terminal/sgr.dart

@@ -1,7 +1,6 @@
 import 'package:xterm/theme/terminal_color.dart';
 import 'package:xterm/terminal/csi.dart';
 import 'package:xterm/terminal/terminal.dart';
-import 'package:xterm/theme/terminal_color_ref.dart';
 
 // reference to color
 class Cr implements TerminalColor {
@@ -133,7 +132,7 @@ void sgrHandler(CSI csi, Terminal terminal) {
         terminal.cellAttr.fgColor = Cr(() => terminal.theme.brightCyan);
         break;
       case '97':
-        terminal.cellAttr.fgColor = Cr(() => terminal.theme.white);
+        terminal.cellAttr.fgColor = Cr(() => terminal.theme.brightWhite);
         break;
       case '49':
         terminal.cellAttr.bgColor = Cr(() => terminal.theme.background);
@@ -184,7 +183,7 @@ void sgrHandler(CSI csi, Terminal terminal) {
         terminal.cellAttr.bgColor = Cr(() => terminal.theme.brightCyan);
         break;
       case '107':
-        terminal.cellAttr.bgColor = Cr(() => terminal.theme.white);
+        terminal.cellAttr.bgColor = Cr(() => terminal.theme.brightWhite);
         break;
       case '38': // set foreground
         final color = parseAnsiColour(params.sublist(i), terminal);

+ 1 - 1
lib/terminal/terminal.dart

@@ -30,7 +30,7 @@ class Terminal with Observable {
     this.onBell,
     this.onTitleChange,
     this.onIconChange,
-    this.platform = PlatformBehavior.unix,
+    this.platform = PlatformBehaviors.unix,
     this.theme = TerminalThemes.defaultTheme,
     int maxLines,
   }) {

+ 27 - 0
lib/theme/terminal_style.dart

@@ -1,3 +1,6 @@
+import 'dart:ui' as ui;
+import 'package:flutter/material.dart';
+
 class TerminalStyle {
   static const defaultFontFamily = [
     'Monaco',
@@ -28,10 +31,34 @@ class TerminalStyle {
     this.fontSize = 14,
     this.fontWidthScaleFactor = 1.0,
     this.fontHeightScaleFactor = 1.1,
+    this.textStyleProvider,
   });
 
   final List<String> fontFamily;
   final double fontSize;
   final double fontWidthScaleFactor;
   final double fontHeightScaleFactor;
+  final TextStyleProvider textStyleProvider;
 }
+
+typedef TextStyleProvider = Function({
+  TextStyle textStyle,
+  Color color,
+  Color backgroundColor,
+  double fontSize,
+  FontWeight fontWeight,
+  FontStyle fontStyle,
+  double letterSpacing,
+  double wordSpacing,
+  TextBaseline textBaseline,
+  double height,
+  Locale locale,
+  Paint foreground,
+  Paint background,
+  List<ui.Shadow> shadows,
+  List<ui.FontFeature> fontFeatures,
+  TextDecoration decoration,
+  Color decorationColor,
+  TextDecorationStyle decorationStyle,
+  double decorationThickness,
+});

+ 3 - 1
lib/theme/terminal_theme.dart

@@ -22,6 +22,7 @@ class TerminalTheme {
     @required this.brightBlue,
     @required this.brightMagenta,
     @required this.brightCyan,
+    @required this.brightWhite,
   });
 
   final TerminalColor cursor;
@@ -36,6 +37,7 @@ class TerminalTheme {
   final TerminalColor blue;
   final TerminalColor magenta;
   final TerminalColor cyan;
+  final TerminalColor white;
 
   final TerminalColor brightBlack;
   final TerminalColor brightRed;
@@ -44,5 +46,5 @@ class TerminalTheme {
   final TerminalColor brightBlue;
   final TerminalColor brightMagenta;
   final TerminalColor brightCyan;
-  final TerminalColor white;
+  final TerminalColor brightWhite;
 }

+ 4 - 2
lib/theme/terminal_themes.dart

@@ -8,13 +8,13 @@ class TerminalThemes {
     foreground: TerminalColor(0xffcccccc),
     background: TerminalColor(0xff1e1e1e),
     black: TerminalColor(0xff000000),
-    white: TerminalColor(0xffe5e5e5),
     red: TerminalColor(0xffcd3131),
     green: TerminalColor(0xff0dbc79),
     yellow: TerminalColor(0xffe5e510),
     blue: TerminalColor(0xff2472c8),
     magenta: TerminalColor(0xffbc3fbc),
     cyan: TerminalColor(0xff11a8cd),
+    white: TerminalColor(0xffe5e5e5),
     brightBlack: TerminalColor(0xff666666),
     brightRed: TerminalColor(0xfff14c4c),
     brightGreen: TerminalColor(0xff23d18b),
@@ -22,6 +22,7 @@ class TerminalThemes {
     brightBlue: TerminalColor(0xff3b8eea),
     brightMagenta: TerminalColor(0xffd670d6),
     brightCyan: TerminalColor(0xff29b8db),
+    brightWhite: TerminalColor(0xffffffff),
   );
 
   static const whiteOnBlack = TerminalTheme(
@@ -30,13 +31,13 @@ class TerminalThemes {
     foreground: TerminalColor(0xffffffff),
     background: TerminalColor(0xff000000),
     black: TerminalColor(0xff000000),
-    white: TerminalColor(0xffe5e5e5),
     red: TerminalColor(0xffcd3131),
     green: TerminalColor(0xff0dbc79),
     yellow: TerminalColor(0xffe5e510),
     blue: TerminalColor(0xff2472c8),
     magenta: TerminalColor(0xffbc3fbc),
     cyan: TerminalColor(0xff11a8cd),
+    white: TerminalColor(0xffe5e5e5),
     brightBlack: TerminalColor(0xff666666),
     brightRed: TerminalColor(0xfff14c4c),
     brightGreen: TerminalColor(0xff23d18b),
@@ -44,5 +45,6 @@ class TerminalThemes {
     brightBlue: TerminalColor(0xff3b8eea),
     brightMagenta: TerminalColor(0xffd670d6),
     brightCyan: TerminalColor(0xff29b8db),
+    brightWhite: TerminalColor(0xffffffff),
   );
 }

+ 1 - 1
pubspec.yaml

@@ -1,6 +1,6 @@
 name: xterm
 description: xterm.dart is a fast and fully-featured terminal emulator for Flutter applications, with support for mobile and desktop platforms.
-version: 1.1.0
+version: 1.2.0
 homepage: https://github.com/TerminalStudio/xterm.dart
 
 environment:

+ 13 - 0
script/color_test.py

@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+import sys
+terse = "-t" in sys.argv[1:] or "--terse" in sys.argv[1:]
+write = sys.stdout.write
+for i in range(2 if terse else 10):
+    for j in range(30, 38):
+        for k in range(40, 48):
+            if terse:
+                write("\33[%d;%d;%dm%d;%d;%d\33[m " % (i, j, k, i, j, k))
+            else:
+                write("%d;%d;%d: \33[%d;%d;%dm Hello, World! \33[m \n" %
+                      (i, j, k, i, j, k,))
+        write("\n")

+ 1 - 0
script/color_test.sh

@@ -0,0 +1 @@
+msgcat --color=test

+ 17 - 0
script/color_test_1.sh

@@ -0,0 +1,17 @@
+#!/bin/bash
+
+T='gYw'
+
+echo -e "\n                 40m     41m     42m     43m     44m     45m     46m     47m    100m    101m    102m    103m    104m    105m    106m    107m";
+
+for FGs in '    m' '   1m' \
+           '  30m' '1;30m' '  31m' '1;31m' '  32m' '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' '  36m' '1;36m' '  37m' '1;37m' \
+           '  90m' '1;90m' '  91m' '1;91m' '  92m' '1;92m' '  93m' '1;93m' '  94m' '1;94m' '  95m' '1;95m' '  96m' '1;96m' '  97m' '1;97m';
+  do FG=${FGs// /}
+  echo -en " $FGs \033[$FG  $T  "
+  for BG in 40m 41m 42m 43m 44m 45m 46m 47m 100m 101m 102m 103m 104m 105m 106m 107m;
+    do echo -en "$EINS \033[$FG\033[$BG  $T  \033[0m";
+  done
+  echo;
+done
+echo