From b422b728eb45f6b22d29329646f2d17cab359dc9 Mon Sep 17 00:00:00 2001 From: Andrei Toterman Date: Thu, 5 Dec 2024 16:23:35 +0100 Subject: [PATCH] [gui] add zoom in terminal --- src/client/gui/lib/platform/linux.dart | 7 ++ src/client/gui/lib/platform/macos.dart | 7 ++ src/client/gui/lib/platform/windows.dart | 7 ++ src/client/gui/lib/vm_details/terminal.dart | 115 ++++++++++++------ .../gui/lib/vm_details/terminal_tabs.dart | 1 + 5 files changed, 98 insertions(+), 39 deletions(-) diff --git a/src/client/gui/lib/platform/linux.dart b/src/client/gui/lib/platform/linux.dart index eaf69140e6e..b778e7bbaf6 100644 --- a/src/client/gui/lib/platform/linux.dart +++ b/src/client/gui/lib/platform/linux.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import '../settings/autostart_notifiers.dart'; +import '../vm_details/terminal.dart'; import 'platform.dart'; class LinuxPlatform extends MpPlatform { @@ -32,6 +33,12 @@ class LinuxPlatform extends MpPlatform { CopySelectionTextIntent.copy, SingleActivator(LogicalKeyboardKey.keyV, control: true, shift: true): PasteTextIntent(SelectionChangedCause.keyboard), + SingleActivator(LogicalKeyboardKey.equal, control: true): + IncreaseTerminalFontIntent(), + SingleActivator(LogicalKeyboardKey.minus, control: true): + DecreaseTerminalFontIntent(), + SingleActivator(LogicalKeyboardKey.digit0, control: true): + ResetTerminalFontIntent(), }; @override diff --git a/src/client/gui/lib/platform/macos.dart b/src/client/gui/lib/platform/macos.dart index f4a7991bb43..8cf1e4100a0 100644 --- a/src/client/gui/lib/platform/macos.dart +++ b/src/client/gui/lib/platform/macos.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import '../settings/autostart_notifiers.dart'; +import '../vm_details/terminal.dart'; import 'platform.dart'; class MacOSPlatform extends MpPlatform { @@ -31,6 +32,12 @@ class MacOSPlatform extends MpPlatform { CopySelectionTextIntent.copy, SingleActivator(LogicalKeyboardKey.keyV, meta: true): PasteTextIntent(SelectionChangedCause.keyboard), + SingleActivator(LogicalKeyboardKey.equal, meta: true): + IncreaseTerminalFontIntent(), + SingleActivator(LogicalKeyboardKey.minus, meta: true): + DecreaseTerminalFontIntent(), + SingleActivator(LogicalKeyboardKey.digit0, meta: true): + ResetTerminalFontIntent(), }; @override diff --git a/src/client/gui/lib/platform/windows.dart b/src/client/gui/lib/platform/windows.dart index f23fcc91e22..4b6a41903b1 100644 --- a/src/client/gui/lib/platform/windows.dart +++ b/src/client/gui/lib/platform/windows.dart @@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart'; import 'package:win32/win32.dart'; import '../settings/autostart_notifiers.dart'; +import '../vm_details/terminal.dart'; import 'platform.dart'; class WindowsPlatform extends MpPlatform { @@ -34,6 +35,12 @@ class WindowsPlatform extends MpPlatform { CopySelectionTextIntent.copy, SingleActivator(LogicalKeyboardKey.keyV, control: true, shift: true): PasteTextIntent(SelectionChangedCause.keyboard), + SingleActivator(LogicalKeyboardKey.equal, control: true): + IncreaseTerminalFontIntent(), + SingleActivator(LogicalKeyboardKey.minus, control: true): + DecreaseTerminalFontIntent(), + SingleActivator(LogicalKeyboardKey.digit0, control: true): + ResetTerminalFontIntent(), }; @override diff --git a/src/client/gui/lib/vm_details/terminal.dart b/src/client/gui/lib/vm_details/terminal.dart index 476b5b15e0c..c194ed1b9b9 100644 --- a/src/client/gui/lib/vm_details/terminal.dart +++ b/src/client/gui/lib/vm_details/terminal.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:isolate'; +import 'dart:math'; import 'package:async/async.dart'; import 'package:dartssh2/dartssh2.dart'; @@ -160,9 +161,27 @@ class VmTerminal extends ConsumerStatefulWidget { ConsumerState createState() => _VmTerminalState(); } +class IncreaseTerminalFontIntent extends Intent { + const IncreaseTerminalFontIntent(); +} + +class DecreaseTerminalFontIntent extends Intent { + const DecreaseTerminalFontIntent(); +} + +class ResetTerminalFontIntent extends Intent { + const ResetTerminalFontIntent(); +} + class _VmTerminalState extends ConsumerState { + static const defaultFontSize = 13.0; + static const minFontSize = 2.5; + static const maxFontSize = 36.0; + static const fontSizeStep = 0.5; + final scrollController = ScrollController(); final focusNode = FocusNode(); + var fontSize = defaultFontSize; @override void initState() { @@ -228,45 +247,63 @@ class _VmTerminalState extends ConsumerState { ); } - return RawScrollbar( - controller: scrollController, - thickness: 9, - child: ClipRect( - child: TerminalView( - terminal, - scrollController: scrollController, - focusNode: focusNode, - shortcuts: mpPlatform.terminalShortcuts, - hardwareKeyboardOnly: true, - padding: const EdgeInsets.all(4), - textStyle: TerminalStyle( - fontFamily: 'UbuntuMono', - fontFamilyFallback: ['NotoColorEmoji', 'FreeSans'], - ), - theme: const TerminalTheme( - cursor: Color(0xFFE5E5E5), - selection: Color(0x80E5E5E5), - foreground: Color(0xffffffff), - background: Color(0xff380c2a), - black: Color(0xFF000000), - white: Color(0xFFE5E5E5), - red: Color(0xFFCD3131), - green: Color(0xFF0DBC79), - yellow: Color(0xFFE5E510), - blue: Color(0xFF2472C8), - magenta: Color(0xFFBC3FBC), - cyan: Color(0xFF11A8CD), - brightBlack: Color(0xFF666666), - brightRed: Color(0xFFF14C4C), - brightGreen: Color(0xFF23D18B), - brightYellow: Color(0xFFF5F543), - brightBlue: Color(0xFF3B8EEA), - brightMagenta: Color(0xFFD670D6), - brightCyan: Color(0xFF29B8DB), - brightWhite: Color(0xFFFFFFFF), - searchHitBackground: Color(0XFFFFFF2B), - searchHitBackgroundCurrent: Color(0XFF31FF26), - searchHitForeground: Color(0XFF000000), + return Actions( + actions: { + IncreaseTerminalFontIntent: CallbackAction( + onInvoke: (_) => setState(() { + fontSize = min(fontSize + fontSizeStep, maxFontSize); + }), + ), + DecreaseTerminalFontIntent: CallbackAction( + onInvoke: (_) => setState(() { + fontSize = max(fontSize - fontSizeStep, minFontSize); + }), + ), + ResetTerminalFontIntent: CallbackAction( + onInvoke: (_) => setState(() => fontSize = defaultFontSize), + ), + }, + child: RawScrollbar( + controller: scrollController, + thickness: 9, + child: ClipRect( + child: TerminalView( + terminal, + scrollController: scrollController, + focusNode: focusNode, + shortcuts: mpPlatform.terminalShortcuts, + hardwareKeyboardOnly: true, + padding: const EdgeInsets.all(4), + textStyle: TerminalStyle( + fontFamily: 'UbuntuMono', + fontFamilyFallback: ['NotoColorEmoji', 'FreeSans'], + fontSize: fontSize, + ), + theme: const TerminalTheme( + cursor: Color(0xFFE5E5E5), + selection: Color(0x80E5E5E5), + foreground: Color(0xffffffff), + background: Color(0xff380c2a), + black: Color(0xFF000000), + white: Color(0xFFE5E5E5), + red: Color(0xFFCD3131), + green: Color(0xFF0DBC79), + yellow: Color(0xFFE5E510), + blue: Color(0xFF2472C8), + magenta: Color(0xFFBC3FBC), + cyan: Color(0xFF11A8CD), + brightBlack: Color(0xFF666666), + brightRed: Color(0xFFF14C4C), + brightGreen: Color(0xFF23D18B), + brightYellow: Color(0xFFF5F543), + brightBlue: Color(0xFF3B8EEA), + brightMagenta: Color(0xFFD670D6), + brightCyan: Color(0xFF29B8DB), + brightWhite: Color(0xFFFFFFFF), + searchHitBackground: Color(0XFFFFFF2B), + searchHitBackgroundCurrent: Color(0XFF31FF26), + searchHitForeground: Color(0XFF000000), + ), ), ), ), diff --git a/src/client/gui/lib/vm_details/terminal_tabs.dart b/src/client/gui/lib/vm_details/terminal_tabs.dart index 881987136d6..591cb2eb513 100644 --- a/src/client/gui/lib/vm_details/terminal_tabs.dart +++ b/src/client/gui/lib/vm_details/terminal_tabs.dart @@ -149,6 +149,7 @@ class TerminalTabs extends ConsumerWidget { ); final shell = VmTerminal( + key: GlobalObjectKey(shellId), name, shellId, isCurrent: index == currentIndex,