From 3db0e044023bf965c3e418bf6e6e524ae4d4b503 Mon Sep 17 00:00:00 2001 From: Mikkeli Matlock Date: Tue, 27 Jan 2026 00:03:01 +0900 Subject: [PATCH] generalised console object --- pi/ui/lib/screens/dashboard_screen.dart | 8 ++++++-- pi/ui/lib/widgets/debug_console.dart | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pi/ui/lib/screens/dashboard_screen.dart b/pi/ui/lib/screens/dashboard_screen.dart index fa39cd0..eb3d63f 100644 --- a/pi/ui/lib/screens/dashboard_screen.dart +++ b/pi/ui/lib/screens/dashboard_screen.dart @@ -217,8 +217,12 @@ class _DashboardScreenState extends State { mainAxisAlignment: MainAxisAlignment.end, children: [ const Spacer(), // Top half - empty - const Expanded( - child: DebugConsole(maxLines: 8), + Expanded( + child: DebugConsole( + messageStream: WebSocketService.instance.debugStream, + initialMessages: WebSocketService.instance.debugMessages, + maxLines: 8, + ), ), ], ), diff --git a/pi/ui/lib/widgets/debug_console.dart b/pi/ui/lib/widgets/debug_console.dart index a223352..800739e 100644 --- a/pi/ui/lib/widgets/debug_console.dart +++ b/pi/ui/lib/widgets/debug_console.dart @@ -1,17 +1,26 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import '../services/websocket_service.dart'; import '../theme/app_theme.dart'; -/// Self-contained debug console that displays WebSocket log messages. -/// Subscribes to WebSocketService.debugStream internally. +/// Generic debug console that displays streaming log messages. +/// +/// Can be wired to any message source via [messageStream] and [initialMessages]. +/// Example sources: WebSocketService.debugStream, ArduinoService logs, etc. class DebugConsole extends StatefulWidget { + /// Stream of new messages to display + final Stream messageStream; + + /// Initial messages to populate (e.g., from a buffer) + final List initialMessages; + /// Maximum lines to display final int maxLines; const DebugConsole({ super.key, + required this.messageStream, + this.initialMessages = const [], this.maxLines = 8, }); @@ -21,18 +30,18 @@ class DebugConsole extends StatefulWidget { class _DebugConsoleState extends State { final List _messages = []; - StreamSubscription? _debugSub; + StreamSubscription? _sub; @override void initState() { super.initState(); // Initialize with existing buffer - _messages.addAll(WebSocketService.instance.debugMessages); + _messages.addAll(widget.initialMessages); _trimMessages(); // Subscribe to new messages - _debugSub = WebSocketService.instance.debugStream.listen((msg) { + _sub = widget.messageStream.listen((msg) { setState(() { _messages.add(msg); _trimMessages(); @@ -48,7 +57,7 @@ class _DebugConsoleState extends State { @override void dispose() { - _debugSub?.cancel(); + _sub?.cancel(); super.dispose(); }