Skip to content

Commit

Permalink
[gui] add zoom in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-toterman committed Dec 9, 2024
1 parent 5d9a452 commit 5b6f110
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 39 deletions.
7 changes: 7 additions & 0 deletions src/client/gui/lib/platform/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/client/gui/lib/platform/macos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/client/gui/lib/platform/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
115 changes: 76 additions & 39 deletions src/client/gui/lib/vm_details/terminal.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:isolate';
import 'dart:math';

import 'package:async/async.dart';
import 'package:dartssh2/dartssh2.dart';
Expand Down Expand Up @@ -160,9 +161,27 @@ class VmTerminal extends ConsumerStatefulWidget {
ConsumerState<VmTerminal> createState() => _VmTerminalState();
}

class IncreaseTerminalFontIntent extends Intent {
const IncreaseTerminalFontIntent();
}

class DecreaseTerminalFontIntent extends Intent {
const DecreaseTerminalFontIntent();
}

class ResetTerminalFontIntent extends Intent {
const ResetTerminalFontIntent();
}

class _VmTerminalState extends ConsumerState<VmTerminal> {
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() {
Expand Down Expand Up @@ -228,45 +247,63 @@ class _VmTerminalState extends ConsumerState<VmTerminal> {
);
}

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<IncreaseTerminalFontIntent>(
onInvoke: (_) => setState(() {
fontSize = min(fontSize + fontSizeStep, maxFontSize);
}),
),
DecreaseTerminalFontIntent: CallbackAction<DecreaseTerminalFontIntent>(
onInvoke: (_) => setState(() {
fontSize = max(fontSize - fontSizeStep, minFontSize);
}),
),
ResetTerminalFontIntent: CallbackAction<ResetTerminalFontIntent>(
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),
),
),
),
),
Expand Down
1 change: 1 addition & 0 deletions src/client/gui/lib/vm_details/terminal_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class TerminalTabs extends ConsumerWidget {
);

final shell = VmTerminal(
key: GlobalObjectKey(shellId),
name,
shellId,
isCurrent: index == currentIndex,
Expand Down

0 comments on commit 5b6f110

Please sign in to comment.