Terminal theme: pure black, square, monospace, IRC-style chat lines
build / build (push) Successful in 16m14s
build / build (push) Successful in 16m14s
A fourth theme choice "Term" next to System/Light/Dark: - black surfaces, green accent, JetBrains Mono, no rounded corners, compact density and paddings, no ink splash (lib/theme/terminal_theme.dart, built on MeshTheme's dark theme with the shapes overridden); - channel and direct chats render each message as one IRC line across the whole width: "14:02 <nick> text [2 hops] ✓", no avatar, no bubble, own messages on the left too. Route, region, repeat and delivery status follow the text inline; the tracing path stays on its own line. The upstream bubble code is untouched: both chat screens branch to a separate builder when MeshStyle.of(context).terminal, so the nightly upstream merge does not collide with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b519922d51
commit
55386df69f
9 files changed
+762
-6
No files matched your search
+5
-1
@@ -35,6 +35,7 @@ import 'services/ui_view_state_service.dart';
|
||||
import 'services/timeout_prediction_service.dart';
|
||||
import 'storage/prefs_manager.dart';
|
||||
import 'theme/mesh_theme.dart';
|
||||
import 'theme/terminal_theme.dart';
|
||||
import 'utils/app_logger.dart';
|
||||
import 'widgets/image_send_codec_binding.dart';
|
||||
|
||||
@@ -460,7 +461,9 @@ class _MeshCoreAppState extends State<MeshCoreApp> with WidgetsBindingObserver {
|
||||
settingsService.settings.languageOverride,
|
||||
),
|
||||
theme: MeshTheme.light(),
|
||||
darkTheme: MeshTheme.dark(),
|
||||
darkTheme: settingsService.settings.themeMode == 'terminal'
|
||||
? terminalTheme()
|
||||
: MeshTheme.dark(),
|
||||
themeMode: _themeModeFromSetting(
|
||||
settingsService.settings.themeMode,
|
||||
),
|
||||
@@ -487,6 +490,7 @@ class _MeshCoreAppState extends State<MeshCoreApp> with WidgetsBindingObserver {
|
||||
case 'light':
|
||||
return ThemeMode.light;
|
||||
case 'dark':
|
||||
case 'terminal':
|
||||
return ThemeMode.dark;
|
||||
default:
|
||||
return ThemeMode.system;
|
||||
|
||||
@@ -194,6 +194,8 @@ class AppSettingsScreen extends StatelessWidget {
|
||||
value: 'dark',
|
||||
label: Text(context.l10n.appSettings_themeDark),
|
||||
),
|
||||
// tth fork: untranslated on purpose, it is a name.
|
||||
const ButtonSegment(value: 'terminal', label: Text('Term')),
|
||||
],
|
||||
selected: {settingsService.settings.themeMode},
|
||||
onSelectionChanged: (selection) {
|
||||
|
||||
@@ -55,6 +55,8 @@ import '../widgets/sync_progress_overlay.dart';
|
||||
import '../widgets/translated_message_content.dart';
|
||||
import '../widgets/unread_divider.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import '../widgets/terminal_message_line.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'app_settings_screen.dart';
|
||||
@@ -504,7 +506,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
child: ListView.builder(
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(8),
|
||||
padding: MeshStyle.of(context).terminal
|
||||
? const EdgeInsets.symmetric(horizontal: 4)
|
||||
: const EdgeInsets.all(8),
|
||||
itemCount: itemCount,
|
||||
itemBuilder: (context, index) {
|
||||
// Loading indicator now appears at end (bottom) of reversed list
|
||||
@@ -611,6 +615,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
double textScale,
|
||||
bool urlImagesEnabled,
|
||||
) {
|
||||
if (MeshStyle.of(context).terminal) {
|
||||
return _buildTerminalMessage(message, textScale, urlImagesEnabled);
|
||||
}
|
||||
final settingsService = context.watch<AppSettingsService>();
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final regionOnHopsLine = settingsService.settings.regionOnHopsLine;
|
||||
@@ -2383,6 +2390,168 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
return region.startsWith('#') ? region.substring(1) : region;
|
||||
}
|
||||
|
||||
/// tth fork, terminal theme: the message as an IRC line across the whole
|
||||
/// width — no avatar, no bubble, own messages on the left as well.
|
||||
Widget _buildTerminalMessage(
|
||||
ChannelMessage message,
|
||||
double textScale,
|
||||
bool urlImagesEnabled,
|
||||
) {
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
final enableTracing = settings.enableMessageTracing;
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
final poi = parseMarkerText(message.text);
|
||||
final isFailed = message.status == ChannelMessageStatus.failed;
|
||||
final textColor = isFailed ? scheme.error : scheme.onSurface;
|
||||
final metaColor = scheme.onSurfaceVariant;
|
||||
final nick = isOutgoing
|
||||
? (connector.selfName ?? message.senderName)
|
||||
: message.senderName;
|
||||
final displayText =
|
||||
message.translatedText != null &&
|
||||
message.translatedText!.trim().isNotEmpty
|
||||
? message.translatedText!.trim()
|
||||
: message.text;
|
||||
final originalText = isOutgoing
|
||||
? message.originalText
|
||||
: (displayText != message.text ? message.text : null);
|
||||
final displayPath = message.pathBytes.isNotEmpty
|
||||
? message.pathBytes
|
||||
: (message.pathVariants.isNotEmpty
|
||||
? message.pathVariants.first
|
||||
: Uint8List(0));
|
||||
final displayPathHashWidth =
|
||||
message.pathHashWidth ?? connector.pathHashByteWidth;
|
||||
final metaStyle = MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
letterSpacing: 0,
|
||||
);
|
||||
|
||||
final trailing = <Widget>[
|
||||
if (displayPath.isNotEmpty)
|
||||
TerminalRouteTag(
|
||||
isDirect: (message.pathLength ?? -1) >= 0,
|
||||
hops: _displayHopCount(
|
||||
displayPath,
|
||||
displayPathHashWidth,
|
||||
message.pathLength,
|
||||
),
|
||||
color: metaColor,
|
||||
textScale: textScale,
|
||||
),
|
||||
if (message.region?.isNotEmpty ?? false)
|
||||
Text('#${_displayRegion(message.region!)}', style: metaStyle),
|
||||
if (message.hasFutureTimestamp)
|
||||
FutureTimestampIndicator(size: 14 * textScale),
|
||||
if (enableTracing && !isOutgoing && message.repeatCount > 0)
|
||||
Text('↻${message.repeatCount}', style: metaStyle),
|
||||
if (isOutgoing)
|
||||
MessageStatusIcon(
|
||||
size: 14 * textScale,
|
||||
isAcked: false,
|
||||
isChannel: true,
|
||||
repeatCount: message.repeatCount,
|
||||
resendProgress: connector.channelResendProgress(message.messageId),
|
||||
hopShortfall: connector.channelHopShortfall(message.messageId),
|
||||
isPending: message.status == ChannelMessageStatus.pending,
|
||||
isFailed: isFailed,
|
||||
onColor: metaColor,
|
||||
),
|
||||
];
|
||||
|
||||
final body = GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onLongPress: () => _showMessageActions(message),
|
||||
onSecondaryTapUp: PlatformInfo.isDesktop
|
||||
? (_) => _showMessageActions(message)
|
||||
: null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (message.replyToMessageId != null)
|
||||
_buildReplyPreview(message, textScale),
|
||||
TerminalMessageLine(
|
||||
time: formatChatTime(context, message.timestamp),
|
||||
nick: nick,
|
||||
nickColor: senderNameColor(nick),
|
||||
text: gifId != null || poi != null ? null : displayText,
|
||||
originalText: originalText,
|
||||
textColor: textColor,
|
||||
metaColor: metaColor,
|
||||
textScale: textScale,
|
||||
trailing: trailing,
|
||||
onSecondaryTap: PlatformInfo.isDesktop
|
||||
? () => _showMessageActions(message)
|
||||
: null,
|
||||
),
|
||||
if (poi != null)
|
||||
_buildPoiMessage(
|
||||
context,
|
||||
poi,
|
||||
isOutgoing,
|
||||
textScale,
|
||||
message.senderName,
|
||||
)
|
||||
else if (gifId != null)
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: GifMessage(
|
||||
url: 'https://media.giphy.com/media/$gifId/giphy.gif',
|
||||
autoLoad: urlImagesEnabled,
|
||||
backgroundColor: Colors.transparent,
|
||||
fallbackTextColor: metaColor,
|
||||
),
|
||||
)
|
||||
else if (urlImagesEnabled)
|
||||
MessageUrlImageFutureBuilder(
|
||||
messageId: message.messageId,
|
||||
text: message.text,
|
||||
builder: (context, snapshot) => snapshot.data == null
|
||||
? const SizedBox.shrink()
|
||||
: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: MessageUrlImagePreview(imageUrl: snapshot.data!),
|
||||
),
|
||||
),
|
||||
if (enableTracing && displayPath.isNotEmpty)
|
||||
Text(
|
||||
context.l10n.channels_via(
|
||||
_formatPathPrefixes(displayPath, displayPathHashWidth),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: metaStyle,
|
||||
),
|
||||
if (message.reactions.isNotEmpty)
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: ReactionChips(
|
||||
reactions: message.reactions,
|
||||
onTap: (_) => _showReactionsReport(message),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (PlatformInfo.isDesktop || isOutgoing) return body;
|
||||
return _SwipeReplyBubble(
|
||||
maxSwipeOffset: 64,
|
||||
replySwipeThreshold: 64,
|
||||
onReplyTriggered: () => _setReplyingTo(message),
|
||||
hintBuilder: ({required isStart}) =>
|
||||
_buildReplySwipeHint(isStart: isStart),
|
||||
child: body,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> openRegionSelectDialog(Channel channel) async {
|
||||
// The AppBar subtitle reads the region from the connector inside a
|
||||
// Consumer, so setChannelRegion's notifyListeners refreshes it directly —
|
||||
|
||||
@@ -47,6 +47,8 @@ import '../l10n/l10n.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../widgets/unread_divider.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import '../widgets/terminal_message_line.dart';
|
||||
import '../widgets/future_timestamp_indicator.dart';
|
||||
import '../widgets/mesh_ui.dart';
|
||||
import 'telemetry_screen.dart';
|
||||
@@ -399,7 +401,9 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
child: ListView.builder(
|
||||
reverse: true, // List grows from bottom up
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
padding: MeshStyle.of(context).terminal
|
||||
? const EdgeInsets.symmetric(horizontal: 4, vertical: 4)
|
||||
: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
itemCount: itemCount,
|
||||
itemBuilder: (context, index) {
|
||||
// Loading indicator now appears at end (bottom) of reversed list
|
||||
@@ -1214,6 +1218,7 @@ class _MessageBubble extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (MeshStyle.of(context).terminal) return _buildTerminal(context);
|
||||
final settingsService = context.watch<AppSettingsService>();
|
||||
final enableTracing = settingsService.settings.enableMessageTracing;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
@@ -1533,6 +1538,133 @@ class _MessageBubble extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// tth fork, terminal theme: the message as an IRC line across the whole
|
||||
/// width — no avatar, no bubble, own messages on the left as well.
|
||||
Widget _buildTerminal(BuildContext context) {
|
||||
final settings = context.watch<AppSettingsService>().settings;
|
||||
final enableTracing = settings.enableMessageTracing;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final isOutgoing = message.isOutgoing;
|
||||
final gifId = GifHelper.parseGif(message.text);
|
||||
final poi = parseMarkerText(message.text);
|
||||
final isFailed = message.status == MessageStatus.failed;
|
||||
final urlImagesEnabled = context.select<MeshCoreConnector, bool>(
|
||||
(connector) => connector.isContactUrlImagesEnabled(sourceId),
|
||||
);
|
||||
final textColor = isFailed ? scheme.error : scheme.onSurface;
|
||||
final metaColor = scheme.onSurfaceVariant;
|
||||
final nick = isOutgoing
|
||||
? (context.read<MeshCoreConnector>().selfName ?? context.l10n.chat_me)
|
||||
: senderName;
|
||||
final displayText =
|
||||
message.translatedText != null &&
|
||||
message.translatedText!.trim().isNotEmpty
|
||||
? message.translatedText!.trim()
|
||||
: message.text;
|
||||
final originalText = isOutgoing
|
||||
? message.originalText
|
||||
: (displayText != message.text ? message.text : null);
|
||||
final metaStyle = MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
color: metaColor,
|
||||
letterSpacing: 0,
|
||||
);
|
||||
|
||||
final trailing = <Widget>[
|
||||
if (message.hasFutureTimestamp)
|
||||
FutureTimestampIndicator(size: 14 * textScale),
|
||||
if (enableTracing && isOutgoing && message.retryCount > 0)
|
||||
Text(
|
||||
'↻${message.retryCount}/${settings.maxMessageRetries}',
|
||||
style: metaStyle,
|
||||
),
|
||||
if (isOutgoing)
|
||||
MessageStatusIcon(
|
||||
size: 14 * textScale,
|
||||
onColor: metaColor,
|
||||
isAcked: message.status == MessageStatus.delivered,
|
||||
isPending: message.status == MessageStatus.pending,
|
||||
isFailed: isFailed,
|
||||
),
|
||||
if (enableTracing &&
|
||||
message.tripTimeMs != null &&
|
||||
message.status == MessageStatus.delivered)
|
||||
Text(
|
||||
'${(message.tripTimeMs! / 1000).toStringAsFixed(1)}s',
|
||||
style: metaStyle,
|
||||
),
|
||||
];
|
||||
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onLongPress: onLongPress,
|
||||
onSecondaryTapUp: PlatformInfo.isDesktop
|
||||
? (_) => onLongPress?.call()
|
||||
: null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TerminalMessageLine(
|
||||
time: formatChatTime(context, message.timestamp),
|
||||
nick: nick,
|
||||
nickColor: senderNameColor(nick),
|
||||
text: gifId != null || poi != null ? null : displayText,
|
||||
originalText: originalText,
|
||||
textColor: textColor,
|
||||
metaColor: metaColor,
|
||||
textScale: textScale,
|
||||
trailing: trailing,
|
||||
onSecondaryTap: PlatformInfo.isDesktop ? onLongPress : null,
|
||||
),
|
||||
if (poi != null)
|
||||
_buildPoiMessage(
|
||||
context,
|
||||
poi,
|
||||
textColor,
|
||||
metaColor,
|
||||
textScale,
|
||||
senderName,
|
||||
)
|
||||
else if (gifId != null)
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: GifMessage(
|
||||
url: 'https://media.giphy.com/media/$gifId/giphy.gif',
|
||||
autoLoad: urlImagesEnabled,
|
||||
backgroundColor: Colors.transparent,
|
||||
fallbackTextColor: metaColor,
|
||||
),
|
||||
)
|
||||
else if (urlImagesEnabled)
|
||||
MessageUrlImageFutureBuilder(
|
||||
messageId: message.messageId,
|
||||
text: message.text,
|
||||
builder: (context, snapshot) => snapshot.data == null
|
||||
? const SizedBox.shrink()
|
||||
: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: MessageUrlImagePreview(imageUrl: snapshot.data!),
|
||||
),
|
||||
),
|
||||
if (message.reactions.isNotEmpty)
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: ReactionChips(
|
||||
reactions: message.reactions,
|
||||
statuses: message.reactionStatuses,
|
||||
onRetry: onRetryReaction == null
|
||||
? null
|
||||
: (emoji) => onRetryReaction!(message, emoji),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPoiMessage(
|
||||
BuildContext context,
|
||||
MarkerPayload poi,
|
||||
|
||||
@@ -230,6 +230,10 @@ class MeshTheme {
|
||||
return _build(scheme, Brightness.light);
|
||||
}
|
||||
|
||||
/// Base for the tth fork's terminal theme (terminal_theme.dart).
|
||||
static ThemeData buildFrom(ColorScheme scheme, Brightness brightness) =>
|
||||
_build(scheme, brightness);
|
||||
|
||||
static ThemeData _build(ColorScheme scheme, Brightness brightness) {
|
||||
final baseText =
|
||||
Typography.material2021(
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'mesh_theme.dart';
|
||||
|
||||
/// Terminal theme of the tth fork: pure black, square corners, monospace,
|
||||
/// minimal padding, and IRC-style chat lines (see [TerminalMessageLine]).
|
||||
///
|
||||
/// Kept out of mesh_theme.dart so the nightly upstream merge does not collide
|
||||
/// with it: it is the dark theme with the shapes and colours overridden.
|
||||
class TerminalPalette {
|
||||
TerminalPalette._();
|
||||
|
||||
static const bg = Color(0xFF000000);
|
||||
static const bg1 = Color(0xFF0A0A0A);
|
||||
static const bg2 = Color(0xFF141414);
|
||||
static const bg3 = Color(0xFF1F1F1F);
|
||||
static const line = Color(0xFF262626);
|
||||
static const line2 = Color(0xFF3A3A3A);
|
||||
static const ink = Color(0xFFD4D4D4);
|
||||
static const ink2 = Color(0xFF9E9E9E);
|
||||
static const green = Color(0xFF4ADE80);
|
||||
static const greenDim = Color(0xFF16A34A);
|
||||
}
|
||||
|
||||
/// Lets widgets ask whether the terminal look is active.
|
||||
@immutable
|
||||
class MeshStyle extends ThemeExtension<MeshStyle> {
|
||||
final bool terminal;
|
||||
|
||||
const MeshStyle({required this.terminal});
|
||||
|
||||
static const _default = MeshStyle(terminal: false);
|
||||
|
||||
static MeshStyle of(BuildContext context) =>
|
||||
Theme.of(context).extension<MeshStyle>() ?? _default;
|
||||
|
||||
@override
|
||||
MeshStyle copyWith({bool? terminal}) =>
|
||||
MeshStyle(terminal: terminal ?? this.terminal);
|
||||
|
||||
@override
|
||||
MeshStyle lerp(MeshStyle? other, double t) =>
|
||||
t < 0.5 ? this : (other ?? this);
|
||||
}
|
||||
|
||||
ThemeData terminalTheme() {
|
||||
const scheme = ColorScheme.dark(
|
||||
primary: TerminalPalette.green,
|
||||
onPrimary: Colors.black,
|
||||
primaryContainer: Color(0xFF052E16),
|
||||
onPrimaryContainer: TerminalPalette.green,
|
||||
secondary: MeshPalette.magenta,
|
||||
onSecondary: Colors.black,
|
||||
secondaryContainer: Color(0xFF2A0F2A),
|
||||
onSecondaryContainer: Colors.white,
|
||||
tertiary: MeshPalette.warn,
|
||||
onTertiary: Colors.black,
|
||||
tertiaryContainer: Color(0xFF3B2405),
|
||||
onTertiaryContainer: Colors.white,
|
||||
error: MeshPalette.alert,
|
||||
onError: Colors.black,
|
||||
errorContainer: Color(0xFF3B0A0A),
|
||||
onErrorContainer: Colors.white,
|
||||
surface: TerminalPalette.bg,
|
||||
onSurface: TerminalPalette.ink,
|
||||
surfaceContainerLowest: TerminalPalette.bg,
|
||||
surfaceContainerLow: TerminalPalette.bg,
|
||||
surfaceContainer: TerminalPalette.bg1,
|
||||
surfaceContainerHigh: TerminalPalette.bg2,
|
||||
surfaceContainerHighest: TerminalPalette.bg3,
|
||||
onSurfaceVariant: TerminalPalette.ink2,
|
||||
outline: TerminalPalette.line2,
|
||||
outlineVariant: TerminalPalette.line,
|
||||
shadow: Colors.black,
|
||||
scrim: Colors.black87,
|
||||
inverseSurface: TerminalPalette.ink,
|
||||
onInverseSurface: TerminalPalette.bg,
|
||||
inversePrimary: TerminalPalette.greenDim,
|
||||
);
|
||||
|
||||
final base = MeshTheme.buildFrom(scheme, Brightness.dark);
|
||||
const square = RoundedRectangleBorder();
|
||||
const mono = TextStyle(
|
||||
fontFamily: MeshFonts.mono,
|
||||
fontFamilyFallback: MeshFonts.monoFallback,
|
||||
);
|
||||
TextStyle? toMono(TextStyle? s) => s?.merge(mono);
|
||||
ButtonStyle squareButton(ButtonStyle? s, EdgeInsets padding) =>
|
||||
(s ?? const ButtonStyle()).copyWith(
|
||||
shape: const WidgetStatePropertyAll(square),
|
||||
padding: WidgetStatePropertyAll(padding),
|
||||
textStyle: s?.textStyle == null
|
||||
? null
|
||||
: WidgetStateProperty.resolveWith(
|
||||
(states) => toMono(s!.textStyle!.resolve(states)),
|
||||
),
|
||||
);
|
||||
OutlineInputBorder inputBorder(Color color, [double width = 1]) =>
|
||||
OutlineInputBorder(
|
||||
borderRadius: BorderRadius.zero,
|
||||
borderSide: BorderSide(color: color, width: width),
|
||||
);
|
||||
|
||||
return base.copyWith(
|
||||
visualDensity: VisualDensity.compact,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
textTheme: base.textTheme.apply(
|
||||
fontFamily: MeshFonts.mono,
|
||||
fontFamilyFallback: MeshFonts.monoFallback,
|
||||
),
|
||||
appBarTheme: base.appBarTheme.copyWith(
|
||||
toolbarHeight: 48,
|
||||
titleSpacing: 8,
|
||||
titleTextStyle: toMono(
|
||||
base.appBarTheme.titleTextStyle,
|
||||
)?.copyWith(fontSize: 16, letterSpacing: 0),
|
||||
),
|
||||
cardTheme: base.cardTheme.copyWith(
|
||||
shape: const RoundedRectangleBorder(
|
||||
side: BorderSide(color: TerminalPalette.line),
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(vertical: 2),
|
||||
),
|
||||
listTileTheme: base.listTileTheme.copyWith(
|
||||
shape: square,
|
||||
dense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
horizontalTitleGap: 8,
|
||||
minVerticalPadding: 2,
|
||||
),
|
||||
floatingActionButtonTheme: base.floatingActionButtonTheme.copyWith(
|
||||
shape: square,
|
||||
extendedTextStyle: toMono(
|
||||
base.floatingActionButtonTheme.extendedTextStyle,
|
||||
),
|
||||
),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: squareButton(
|
||||
base.elevatedButtonTheme.style,
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
),
|
||||
filledButtonTheme: FilledButtonThemeData(
|
||||
style: squareButton(
|
||||
base.filledButtonTheme.style,
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
),
|
||||
outlinedButtonTheme: OutlinedButtonThemeData(
|
||||
style: squareButton(
|
||||
base.outlinedButtonTheme.style,
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
),
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: squareButton(
|
||||
base.textButtonTheme.style,
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
),
|
||||
),
|
||||
iconButtonTheme: const IconButtonThemeData(
|
||||
style: ButtonStyle(shape: WidgetStatePropertyAll(square)),
|
||||
),
|
||||
segmentedButtonTheme: SegmentedButtonThemeData(
|
||||
style: squareButton(
|
||||
base.segmentedButtonTheme.style,
|
||||
const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
),
|
||||
inputDecorationTheme: base.inputDecorationTheme.copyWith(
|
||||
fillColor: TerminalPalette.bg,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
isDense: true,
|
||||
border: inputBorder(scheme.outline),
|
||||
enabledBorder: inputBorder(scheme.outlineVariant),
|
||||
focusedBorder: inputBorder(scheme.primary),
|
||||
disabledBorder: inputBorder(scheme.outlineVariant),
|
||||
errorBorder: inputBorder(scheme.error),
|
||||
focusedErrorBorder: inputBorder(scheme.error),
|
||||
),
|
||||
chipTheme: base.chipTheme.copyWith(
|
||||
shape: square,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 0),
|
||||
labelStyle: toMono(base.chipTheme.labelStyle),
|
||||
),
|
||||
navigationBarTheme: base.navigationBarTheme.copyWith(
|
||||
height: 56,
|
||||
indicatorShape: square,
|
||||
labelTextStyle: WidgetStateProperty.resolveWith(
|
||||
(states) =>
|
||||
toMono(base.navigationBarTheme.labelTextStyle?.resolve(states)),
|
||||
),
|
||||
),
|
||||
bottomSheetTheme: base.bottomSheetTheme.copyWith(
|
||||
shape: const RoundedRectangleBorder(
|
||||
side: BorderSide(color: TerminalPalette.line2),
|
||||
),
|
||||
),
|
||||
dialogTheme: base.dialogTheme.copyWith(
|
||||
shape: const RoundedRectangleBorder(
|
||||
side: BorderSide(color: TerminalPalette.line2),
|
||||
),
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
|
||||
),
|
||||
snackBarTheme: base.snackBarTheme.copyWith(
|
||||
shape: const RoundedRectangleBorder(
|
||||
side: BorderSide(color: TerminalPalette.line2),
|
||||
),
|
||||
),
|
||||
popupMenuTheme: base.popupMenuTheme.copyWith(
|
||||
shape: const RoundedRectangleBorder(
|
||||
side: BorderSide(color: TerminalPalette.line2),
|
||||
),
|
||||
),
|
||||
tooltipTheme: base.tooltipTheme.copyWith(
|
||||
decoration: BoxDecoration(
|
||||
color: TerminalPalette.bg2,
|
||||
border: Border.all(color: TerminalPalette.line2),
|
||||
),
|
||||
),
|
||||
tabBarTheme: base.tabBarTheme.copyWith(
|
||||
labelStyle: toMono(base.tabBarTheme.labelStyle),
|
||||
unselectedLabelStyle: toMono(base.tabBarTheme.unselectedLabelStyle),
|
||||
labelPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
extensions: const [MeshStyle(terminal: true)],
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import '../helpers/gif_helper.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/app_settings_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../theme/terminal_theme.dart';
|
||||
import 'byte_count_input.dart';
|
||||
import 'gif_message.dart';
|
||||
import 'gif_picker.dart';
|
||||
@@ -151,7 +152,9 @@ class ChatComposer extends StatelessWidget {
|
||||
children: [
|
||||
...header,
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
padding: MeshStyle.of(context).terminal
|
||||
? const EdgeInsets.symmetric(horizontal: 2, vertical: 2)
|
||||
: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
@@ -196,7 +199,9 @@ class ChatComposer extends StatelessWidget {
|
||||
? scheme.onPrimary
|
||||
: scheme.onSurfaceVariant,
|
||||
minimumSize: const Size(40, 40),
|
||||
shape: const CircleBorder(),
|
||||
shape: MeshStyle.of(context).terminal
|
||||
? const RoundedRectangleBorder()
|
||||
: const CircleBorder(),
|
||||
),
|
||||
onPressed: hasText
|
||||
? () {
|
||||
@@ -262,7 +267,9 @@ class ChatComposer extends StatelessWidget {
|
||||
Widget _buildTextField(BuildContext context, ColorScheme scheme) {
|
||||
OutlineInputBorder border(Color color, [double width = 1]) =>
|
||||
OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
borderRadius: MeshStyle.of(context).terminal
|
||||
? BorderRadius.zero
|
||||
: BorderRadius.circular(MeshRadii.md),
|
||||
borderSide: BorderSide(color: color, width: width),
|
||||
);
|
||||
return ByteCountedTextField(
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||
|
||||
import '../helpers/link_handler.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
|
||||
/// One chat message as an IRC line for the terminal theme:
|
||||
///
|
||||
/// 14:02 <tth-x1> text that wraps under the whole width [2 hops] ✓
|
||||
///
|
||||
/// [trailing] widgets (route, delivery status) follow the text inline, so a
|
||||
/// plain message stays a single line. [text] may be null for messages whose
|
||||
/// body is not text (GIF, POI) — the line is then just the time and the nick.
|
||||
class TerminalMessageLine extends StatelessWidget {
|
||||
final String time;
|
||||
final String nick;
|
||||
final Color nickColor;
|
||||
final String? text;
|
||||
|
||||
/// Text before translation, shown dimmed on its own line.
|
||||
final String? originalText;
|
||||
final Color textColor;
|
||||
final Color metaColor;
|
||||
final double textScale;
|
||||
final List<Widget> trailing;
|
||||
final VoidCallback? onSecondaryTap;
|
||||
|
||||
const TerminalMessageLine({
|
||||
super.key,
|
||||
required this.time,
|
||||
required this.nick,
|
||||
required this.nickColor,
|
||||
required this.textColor,
|
||||
required this.metaColor,
|
||||
required this.textScale,
|
||||
this.text,
|
||||
this.originalText,
|
||||
this.trailing = const [],
|
||||
this.onSecondaryTap,
|
||||
});
|
||||
|
||||
static const _linkifyOptions = LinkifyOptions(
|
||||
humanize: false,
|
||||
defaultToHttps: false,
|
||||
);
|
||||
static const _linkifiers = [UrlLinkifier(), EmailLinkifier()];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = MeshTheme.mono(
|
||||
fontSize: 14 * textScale,
|
||||
color: textColor,
|
||||
letterSpacing: 0,
|
||||
);
|
||||
final metaStyle = style.copyWith(color: metaColor);
|
||||
final body = text?.trim();
|
||||
final original = originalText?.trim();
|
||||
|
||||
TextSpan linkified(String value, TextStyle base) {
|
||||
// What linkify() from package:linkify does; flutter_linkify does not
|
||||
// re-export the function, only the linkifiers.
|
||||
var elements = <LinkifyElement>[TextElement(value)];
|
||||
for (final linkifier in _linkifiers) {
|
||||
elements = linkifier.parse(elements, _linkifyOptions);
|
||||
}
|
||||
return buildTextSpan(
|
||||
elements,
|
||||
style: base,
|
||||
linkStyle: LinkHandler.defaultLinkStyle(context, base),
|
||||
onOpen: (link) => LinkHandler.handleLinkTap(context, link.url),
|
||||
);
|
||||
}
|
||||
|
||||
final line = TextSpan(
|
||||
children: [
|
||||
TextSpan(text: '$time ', style: metaStyle),
|
||||
TextSpan(
|
||||
text: '<$nick>',
|
||||
style: style.copyWith(color: nickColor, fontWeight: FontWeight.w700),
|
||||
),
|
||||
if (body != null && body.isNotEmpty) ...[
|
||||
TextSpan(text: ' ', style: style),
|
||||
linkified(body, style),
|
||||
],
|
||||
for (final widget in trailing) ...[
|
||||
TextSpan(text: ' ', style: style),
|
||||
WidgetSpan(alignment: PlaceholderAlignment.middle, child: widget),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
final showOriginal =
|
||||
original != null && original.isNotEmpty && original != body;
|
||||
final rich = TextSpan(
|
||||
children: [
|
||||
line,
|
||||
if (showOriginal) ...[
|
||||
TextSpan(text: '\n', style: style),
|
||||
linkified(original, metaStyle.copyWith(fontStyle: FontStyle.italic)),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
if (!PlatformInfo.isDesktop) return Text.rich(rich);
|
||||
final selectable = SelectableText.rich(rich);
|
||||
if (onSecondaryTap == null) return selectable;
|
||||
return Listener(
|
||||
onPointerDown: (event) {
|
||||
if (event.buttons & kSecondaryMouseButton != 0) onSecondaryTap!();
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: selectable,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// [RouteChip] as plain text for a terminal line, e.g. `[2 hops]`, `[flood]`.
|
||||
class TerminalRouteTag extends StatelessWidget {
|
||||
final bool isDirect;
|
||||
final int? hops;
|
||||
final Color color;
|
||||
final double textScale;
|
||||
|
||||
const TerminalRouteTag({
|
||||
super.key,
|
||||
required this.isDirect,
|
||||
required this.hops,
|
||||
required this.color,
|
||||
required this.textScale,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final label = isDirect
|
||||
? (hops == null || hops == 0
|
||||
? l10n.chat_direct
|
||||
: l10n.chat_hopsCount(hops!))
|
||||
: l10n.routing_modeFlood;
|
||||
return Text(
|
||||
'[${label.toLowerCase()}]',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 12 * textScale,
|
||||
color: color,
|
||||
letterSpacing: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||
import 'package:meshcore_open/theme/terminal_theme.dart';
|
||||
import 'package:meshcore_open/widgets/terminal_message_line.dart';
|
||||
|
||||
Future<void> _pumpLine(WidgetTester tester, {required ThemeData theme}) {
|
||||
return tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const Scaffold(
|
||||
body: TerminalMessageLine(
|
||||
time: '14:02',
|
||||
nick: 'tth-x1',
|
||||
nickColor: Colors.green,
|
||||
text: 'hello https://example.com',
|
||||
textColor: Colors.white,
|
||||
metaColor: Colors.grey,
|
||||
textScale: 1,
|
||||
trailing: [
|
||||
TerminalRouteTag(
|
||||
isDirect: true,
|
||||
hops: 2,
|
||||
color: Colors.grey,
|
||||
textScale: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('only the terminal theme reports the terminal style', () {
|
||||
expect(MeshTheme.dark().extension<MeshStyle>(), isNull);
|
||||
expect(terminalTheme().extension<MeshStyle>()?.terminal, isTrue);
|
||||
expect(terminalTheme().scaffoldBackgroundColor, const Color(0xFF000000));
|
||||
});
|
||||
|
||||
testWidgets('time, nick, text and route share one paragraph', (tester) async {
|
||||
await _pumpLine(tester, theme: terminalTheme());
|
||||
|
||||
// Text.rich on mobile, SelectableText.rich on desktop (the test host).
|
||||
expect(
|
||||
find.textContaining(
|
||||
'14:02 <tth-x1> hello https://example.com',
|
||||
findRichText: true,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('[2 hops]'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user