Browse Source

Merge pull request #43 from devmil/feature/select_all

adds "selectAll" to TerminalUiInteraction
xuty 4 years ago
parent
commit
9a2ca47105

+ 22 - 2
lib/terminal/terminal.dart

@@ -63,6 +63,7 @@ class Terminal with Observable implements TerminalUiInteraction {
   }
 
   bool _dirty = false;
+  @override
   bool get dirty {
     if (_dirty) {
       _dirty = false;
@@ -84,6 +85,7 @@ class Terminal with Observable implements TerminalUiInteraction {
   int get viewHeight => _viewHeight;
 
   int get visibleHeight => min(_viewHeight, buffer.height);
+  @override
   int get invisibleHeight => buffer.height - visibleHeight;
 
   /// ### Insert/Replace Mode (IRM)
@@ -95,9 +97,10 @@ class Terminal with Observable implements TerminalUiInteraction {
   /// replacing the character at the cursor position.
   ///
   /// You can set or reset insert/replace mode as follows.
-  bool _replaceMode = true;
+  bool _replaceMode = true; // ignore: unused_field
 
-  bool _screenMode = false; // DECSCNM (black on white background)
+  bool _screenMode =
+      false; // ignore: unused_field, // DECSCNM (black on white background)
   bool _autoWrapMode = true;
   bool get autoWrapMode => _autoWrapMode;
 
@@ -151,6 +154,7 @@ class Terminal with Observable implements TerminalUiInteraction {
   bool _bracketedPasteMode = false;
 
   bool _showCursor = true;
+  @override
   bool get showCursor => _showCursor;
 
   /// DECCKM – Cursor Keys Mode (DEC Private)
@@ -195,15 +199,19 @@ class Terminal with Observable implements TerminalUiInteraction {
   final BellHandler onBell;
   final TitleChangeHandler onTitleChange;
   final IconChangeHandler onIconChange;
+  @override
   final PlatformBehavior platform;
 
   Buffer get buffer {
     return _buffer;
   }
 
+  @override
   int get cursorX => buffer.cursorX;
+  @override
   int get cursorY => buffer.cursorY;
 
+  @override
   void setScrollOffsetFromBottom(int scrollOffset) {
     final oldOffset = _buffer.scrollOffsetFromBottom;
     _buffer.setScrollOffsetFromBottom(scrollOffset);
@@ -217,6 +225,7 @@ class Terminal with Observable implements TerminalUiInteraction {
   /// interpreted.
   ///
   /// See also: [Buffer.write]
+  @override
   void write(String text) {
     _queue.addAll(text.runes);
     _processInput();
@@ -233,6 +242,7 @@ class Terminal with Observable implements TerminalUiInteraction {
     refresh();
   }
 
+  @override
   List<BufferLine> getVisibleLines() {
     return _buffer.getVisibleLines();
   }
@@ -280,6 +290,7 @@ class Terminal with Observable implements TerminalUiInteraction {
     }
   }
 
+  @override
   void refresh() {
     _dirty = true;
     notifyListeners();
@@ -357,6 +368,7 @@ class Terminal with Observable implements TerminalUiInteraction {
   /// Resize the terminal screen. [newWidth] and [newHeight] should be greater
   /// than 0. Text reflow is currently not implemented and will be avaliable in
   /// the future.
+  @override
   void resize(
       int newWidth, int newHeight, int newPixelWidth, int newPixelHeight) {
     backend?.resize(newWidth, newHeight, newPixelWidth, newPixelHeight);
@@ -380,6 +392,7 @@ class Terminal with Observable implements TerminalUiInteraction {
     buffer.resetVerticalMargins();
   }
 
+  @override
   void keyInput(
     TerminalKey key, {
     bool ctrl = false,
@@ -575,6 +588,7 @@ class Terminal with Observable implements TerminalUiInteraction {
     return builder.toString();
   }
 
+  @override
   void paste(String data) {
     if (bracketedPasteMode) {
       data = '\x1b[200~$data\x1b[201~';
@@ -702,4 +716,10 @@ class Terminal with Observable implements TerminalUiInteraction {
 
   @override
   bool get isTerminated => _isTerminated;
+
+  @override
+  void selectAll() {
+    _selection.init(Position(0, 0));
+    _selection.update(Position(terminalWidth, bufferHeight));
+  }
 }

+ 28 - 8
lib/terminal/terminal_isolate.dart

@@ -20,11 +20,12 @@ enum _IsolateCommand {
   write,
   refresh,
   clearSelection,
+  selectAll,
   mouseTap,
   mouseDoubleTap,
   mousePanStart,
   mousePanUpdate,
-  setScrollOffsetFromTop,
+  setScrollOffsetFromBottom,
   resize,
   onInput,
   keyInput,
@@ -90,21 +91,24 @@ void terminalMain(SendPort port) async {
         _terminal?.refresh();
         break;
       case _IsolateCommand.clearSelection:
-        _terminal?.selection!.clear();
+        _terminal?.clearSelection();
+        break;
+      case _IsolateCommand.selectAll:
+        _terminal?.selectAll();
         break;
       case _IsolateCommand.mouseTap:
-        _terminal?.mouseMode.onTap(_terminal, msg[1]);
+        _terminal?.onMouseTap(msg[1]);
         break;
       case _IsolateCommand.mouseDoubleTap:
-        _terminal?.mouseMode.onDoubleTap(_terminal, msg[1]);
+        _terminal?.onMouseDoubleTap(msg[1]);
         break;
       case _IsolateCommand.mousePanStart:
-        _terminal?.mouseMode.onPanStart(_terminal, msg[1]);
+        _terminal?.onPanStart(msg[1]);
         break;
       case _IsolateCommand.mousePanUpdate:
-        _terminal?.mouseMode.onPanUpdate(_terminal, msg[1]);
+        _terminal?.onPanUpdate(msg[1]);
         break;
-      case _IsolateCommand.setScrollOffsetFromTop:
+      case _IsolateCommand.setScrollOffsetFromBottom:
         _terminal?.setScrollOffsetFromBottom(msg[1]);
         break;
       case _IsolateCommand.resize:
@@ -405,26 +409,37 @@ class TerminalIsolate with Observable implements TerminalUiInteraction {
     _sendPort?.send([_IsolateCommand.clearSelection]);
   }
 
+  @override
+  void selectAll() {
+    _sendPort?.send([_IsolateCommand.selectAll]);
+  }
+
+  @override
   void onMouseTap(Position position) {
     _sendPort?.send([_IsolateCommand.mouseTap, position]);
   }
 
+  @override
   void onMouseDoubleTap(Position position) {
     _sendPort?.send([_IsolateCommand.mouseDoubleTap, position]);
   }
 
+  @override
   void onPanStart(Position position) {
     _sendPort?.send([_IsolateCommand.mousePanStart, position]);
   }
 
+  @override
   void onPanUpdate(Position position) {
     _sendPort?.send([_IsolateCommand.mousePanUpdate, position]);
   }
 
+  @override
   void setScrollOffsetFromBottom(int offset) {
-    _sendPort?.send([_IsolateCommand.setScrollOffsetFromTop, offset]);
+    _sendPort?.send([_IsolateCommand.setScrollOffsetFromBottom, offset]);
   }
 
+  @override
   int convertViewLineToRawLine(int viewLine) {
     if (_lastState == null) {
       return 0;
@@ -437,14 +452,17 @@ class TerminalIsolate with Observable implements TerminalUiInteraction {
     return viewLine + (_lastState!.bufferHeight - _lastState!.viewHeight);
   }
 
+  @override
   void write(String text) {
     _sendPort?.send([_IsolateCommand.write, text]);
   }
 
+  @override
   void paste(String data) {
     _sendPort?.send([_IsolateCommand.paste, data]);
   }
 
+  @override
   void resize(
       int newWidth, int newHeight, int newPixelWidth, int newPixelHeight) {
     _sendPort?.send([
@@ -456,10 +474,12 @@ class TerminalIsolate with Observable implements TerminalUiInteraction {
     ]);
   }
 
+  @override
   void raiseOnInput(String text) {
     _sendPort?.send([_IsolateCommand.onInput, text]);
   }
 
+  @override
   void keyInput(
     TerminalKey key, {
     bool ctrl = false,

+ 3 - 0
lib/terminal/terminal_ui_interaction.dart

@@ -68,6 +68,9 @@ abstract class TerminalUiInteraction with Observable {
   /// clears the selection
   void clearSelection();
 
+  /// select the whole buffer
+  void selectAll();
+
   /// notify the Terminal about a mouse tap
   void onMouseTap(Position position);