1+ import 'dart:async' ;
2+
13import 'package:flutter/material.dart' ;
24
5+ import '../l10n/app_calendar.dart' ;
6+
37import '../l10n/app_locale.dart' ;
48import 'action_log.dart' ;
59import 'action_stats_label.dart' ;
10+ import '../theme/app_theme.dart' ;
611
712/// Minimum and maximum drag-resize height for the logs/terminal panels.
813const double kPanelMinHeight = 80 ;
@@ -38,77 +43,113 @@ class PanelResizeHandle extends StatelessWidget {
3843 }
3944}
4045
41- /// The bottom logs panel: a timestamped list of git actions run through
42- /// [GitActions] , newest first.
43- class LogsPanel extends StatelessWidget {
46+ /// The bottom logs panel: git actions run through [GitActions] , newest
47+ /// first, grouped by day ("Today", "Yesterday", "Sep 8, 2026"). Today's
48+ /// recent actions show a relative time ("4 min ago"); hovering a time shows
49+ /// the exact one.
50+ class LogsPanel extends StatefulWidget {
4451 const LogsPanel ({super .key, required this .height, required this .onHeightChanged});
4552
4653 final double height;
4754 final ValueChanged <double > onHeightChanged;
4855
56+ @override
57+ State <LogsPanel > createState () => _LogsPanelState ();
58+ }
59+
60+ class _LogsPanelState extends State <LogsPanel > {
61+ /// Keeps "4 min ago" current.
62+ Timer ? _ticker;
63+
64+ @override
65+ void initState () {
66+ super .initState ();
67+ _ticker = Timer .periodic (
68+ const Duration (seconds: 30 ),
69+ (_) => setState (() {}),
70+ );
71+ }
72+
73+ @override
74+ void dispose () {
75+ _ticker? .cancel ();
76+ super .dispose ();
77+ }
78+
4979 @override
5080 Widget build (BuildContext context) {
51- final colorScheme = Theme . of ( context).colorScheme ;
81+ final b = context.branchi ;
5282 return Column (
5383 mainAxisSize: MainAxisSize .min,
5484 children: [
5585 PanelResizeHandle (
56- onDrag: (delta) => onHeightChanged (
57- (height + delta).clamp (kPanelMinHeight, kPanelMaxHeight),
86+ onDrag: (delta) => widget. onHeightChanged (
87+ (widget. height + delta).clamp (kPanelMinHeight, kPanelMaxHeight),
5888 ),
5989 ),
6090 Container (
61- height: height,
91+ height: widget. height,
6292 decoration: BoxDecoration (
63- color: colorScheme.surface ,
64- border: Border (top: BorderSide (color : colorScheme.outlineVariant) ),
93+ color: b.bg ,
94+ border: Border (top: b.hairline ),
6595 ),
66- child: AnimatedBuilder (
67- animation: ActionLog .instance,
96+ child: ListenableBuilder (
97+ listenable: Listenable .merge (
98+ [ActionLog .instance, AppCalendarSettings .preference],
99+ ),
68100 builder: (context, _) {
69101 final entries = ActionLog .instance.entries;
70102 if (entries.isEmpty) {
71103 return Center (
72104 child: Text (
73105 translate ('no_logged_actions' ),
74- style: TextStyle (color: colorScheme.onSurfaceVariant ),
106+ style: TextStyle (color: b.muted ),
75107 ),
76108 );
77109 }
110+ final now = DateTime .now ();
111+ final cal = AppCalendarSettings .current;
112+ // Day headers between the entries: a String is a header,
113+ // an ActionLogEntry a row.
114+ final items = < Object > [];
115+ DateTime ? day;
116+ for (final entry in entries) {
117+ final t = entry.timestamp;
118+ final entryDay = DateTime (t.year, t.month, t.day);
119+ if (entryDay != day) {
120+ day = entryDay;
121+ items.add (_dayLabel (entryDay, now, cal));
122+ }
123+ items.add (entry);
124+ }
78125 return GestureDetector (
79126 onSecondaryTapUp: (details) =>
80127 _showClearMenu (context, details.globalPosition),
81128 behavior: HitTestBehavior .translucent,
82129 child: ListView .builder (
83- itemCount: entries.length,
130+ padding: const EdgeInsets .only (bottom: 8 ),
131+ itemCount: items.length,
84132 itemBuilder: (context, index) {
85- final entry = entries[index];
86- return ListTile (
87- dense: true ,
88- leading: Icon (
89- entry.success
90- ? Icons .check_circle_outline
91- : Icons .error_outline,
92- size: 16 ,
93- color:
94- entry.success ? colorScheme.primary : colorScheme.error,
95- ),
96- title: Row (
97- children: [
98- Flexible (
99- child: Text (
100- entry.action,
101- overflow: TextOverflow .ellipsis,
102- ),
133+ final item = items[index];
134+ if (item is String ) {
135+ return Padding (
136+ padding: const EdgeInsetsDirectional .fromSTEB (
137+ 16 , 10 , 16 , 4 ),
138+ child: Text (
139+ item.toUpperCase (),
140+ style: TextStyle (
141+ fontSize: 11 ,
142+ color: b.muted,
143+ letterSpacing: 0.44 ,
103144 ),
104- if (entry.stats != null ) ...[
105- const SizedBox (width : 10 ),
106- ActionStatsLabel (stats : entry.stats ! ),
107- ],
108- ] ,
109- ) ,
110- subtitle : entry.success ? null : Text (entry.detail ?? '' ) ,
111- trailing : Text ( _formatTimestamp (entry.timestamp)) ,
145+ ),
146+ );
147+ }
148+ return _row (
149+ context ,
150+ item as ActionLogEntry ,
151+ now ,
152+ cal ,
112153 );
113154 },
114155 ),
@@ -120,6 +161,87 @@ class LogsPanel extends StatelessWidget {
120161 );
121162 }
122163
164+ Widget _row (
165+ BuildContext context,
166+ ActionLogEntry entry,
167+ DateTime now,
168+ AppCalendar cal,
169+ ) {
170+ final b = context.branchi;
171+ final detail = entry.success ? null : entry.detail;
172+ return Padding (
173+ padding: const EdgeInsets .symmetric (horizontal: 16 , vertical: 4 ),
174+ child: Column (
175+ crossAxisAlignment: CrossAxisAlignment .start,
176+ children: [
177+ Row (
178+ children: [
179+ Icon (
180+ entry.success ? Icons .check : Icons .close,
181+ size: 14 ,
182+ color: entry.success ? b.add : b.del,
183+ ),
184+ const SizedBox (width: 10 ),
185+ Flexible (
186+ child: Text (
187+ entry.action,
188+ maxLines: 1 ,
189+ overflow: TextOverflow .ellipsis,
190+ style: TextStyle (fontSize: 13 , color: b.fg),
191+ ),
192+ ),
193+ if (entry.stats != null ) ...[
194+ const SizedBox (width: 10 ),
195+ ActionStatsLabel (stats: entry.stats! ),
196+ ],
197+ const SizedBox (width: 8 ),
198+ Tooltip (
199+ message: cal.digits (_clock (entry.timestamp, seconds: true )),
200+ child: Text (
201+ '· ${_time (entry .timestamp , now , cal )}' ,
202+ style: TextStyle (fontSize: 12 , color: b.muted),
203+ ),
204+ ),
205+ ],
206+ ),
207+ if (detail != null && detail.isNotEmpty)
208+ Padding (
209+ padding: const EdgeInsetsDirectional .only (start: 24 , top: 2 ),
210+ child: Text (
211+ detail,
212+ style: TextStyle (fontSize: 12 , color: b.del),
213+ ),
214+ ),
215+ ],
216+ ),
217+ );
218+ }
219+
220+ static String _dayLabel (DateTime day, DateTime now, AppCalendar cal) {
221+ final today = DateTime (now.year, now.month, now.day);
222+ final daysAgo = today.difference (day).inDays;
223+ if (daysAgo == 0 ) return translate ('activity_today' );
224+ if (daysAgo == 1 ) return translate ('activity_yesterday' );
225+ return cal.formatDate (day);
226+ }
227+
228+ /// "just now" / "4 min ago" within the last hour, else "14:32".
229+ static String _time (DateTime time, DateTime now, AppCalendar cal) {
230+ final diff = now.difference (time);
231+ if (diff.inMinutes < 1 ) return translate ('activity_just_now' );
232+ if (diff.inMinutes < 60 ) {
233+ return translate ('report_ago_minutes' )
234+ .replaceAll ('{n}' , cal.digits (diff.inMinutes));
235+ }
236+ return cal.digits (_clock (time));
237+ }
238+
239+ static String _clock (DateTime t, {bool seconds = false }) {
240+ String two (int v) => v.toString ().padLeft (2 , '0' );
241+ final hm = '${two (t .hour )}:${two (t .minute )}' ;
242+ return seconds ? '$hm :${two (t .second )}' : hm;
243+ }
244+
123245 Future <void > _showClearMenu (BuildContext context, Offset position) async {
124246 final selection = await showMenu <String >(
125247 context: context,
@@ -137,10 +259,4 @@ class LogsPanel extends StatelessWidget {
137259 ActionLog .instance.clear ();
138260 }
139261 }
140-
141- String _formatTimestamp (DateTime timestamp) {
142- String twoDigits (int value) => value.toString ().padLeft (2 , '0' );
143- return '${twoDigits (timestamp .hour )}:${twoDigits (timestamp .minute )}:'
144- '${twoDigits (timestamp .second )}' ;
145- }
146262}
0 commit comments