feat(ui): add copy-last-40-lines button to log visualizer
This commit is contained in:
@@ -310,6 +310,10 @@
|
||||
"refresh": "Aktualisieren",
|
||||
"empty": "Keine Logs in den letzten 30 Minuten.",
|
||||
"count": "{0} Einträge",
|
||||
"copyLast": "Letzte 40 kopieren",
|
||||
"copyLastTooltip": "Kopiert die letzten 40 sichtbaren Zeilen in die Zwischenablage",
|
||||
"copied": "{0} Zeilen kopiert",
|
||||
"copyFailed": "Kopieren fehlgeschlagen",
|
||||
"footerHint": "logs",
|
||||
"openTooltip": "Aktuelle Worker-Logs anzeigen"
|
||||
},
|
||||
|
||||
@@ -311,7 +311,11 @@
|
||||
"empty": "No logs in the last 30 minutes.",
|
||||
"count": "{0} entries",
|
||||
"footerHint": "logs",
|
||||
"openTooltip": "View recent worker logs"
|
||||
"openTooltip": "View recent worker logs",
|
||||
"copyLast": "Copy last 40",
|
||||
"copyLastTooltip": "Copy the last 40 visible lines to the clipboard",
|
||||
"copied": "{0} lines copied",
|
||||
"copyFailed": "Copy failed"
|
||||
},
|
||||
"about": {
|
||||
"title": "ABOUT",
|
||||
|
||||
@@ -3,6 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Input.Platform;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
@@ -18,7 +21,10 @@ namespace ClaudeDo.Ui.ViewModels.Modals;
|
||||
/// </summary>
|
||||
public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
{
|
||||
private const int CopyLastCount = 40;
|
||||
|
||||
private readonly IWorkerClient _worker;
|
||||
private readonly Func<string, Task<bool>> _copyToClipboard;
|
||||
private IReadOnlyList<WorkerLogEntry> _all = Array.Empty<WorkerLogEntry>();
|
||||
|
||||
public ObservableCollection<LogVisualizerRow> Rows { get; } = new();
|
||||
@@ -28,7 +34,14 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
|
||||
public Action? CloseAction { get; set; }
|
||||
|
||||
public LogVisualizerViewModel(IWorkerClient worker) => _worker = worker;
|
||||
public LogVisualizerViewModel(IWorkerClient worker) : this(worker, CopyToClipboardAsync) { }
|
||||
|
||||
internal LogVisualizerViewModel(IWorkerClient worker, Func<string, Task<bool>> copyToClipboard)
|
||||
{
|
||||
_worker = worker;
|
||||
_copyToClipboard = copyToClipboard;
|
||||
Rows.CollectionChanged += (_, _) => CopyLastCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task RefreshAsync()
|
||||
@@ -53,6 +66,33 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
[RelayCommand] private void Close() => CloseAction?.Invoke();
|
||||
|
||||
private bool CanCopyLast() => Rows.Count > 0;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanCopyLast))]
|
||||
private async Task CopyLastAsync()
|
||||
{
|
||||
var count = Math.Min(Rows.Count, CopyLastCount);
|
||||
var ok = await _copyToClipboard(BuildCopyText());
|
||||
StatusText = ok
|
||||
? Loc.T("modals.logVisualizer.copied", count)
|
||||
: Loc.T("modals.logVisualizer.copyFailed");
|
||||
}
|
||||
|
||||
internal string BuildCopyText() =>
|
||||
string.Join('\n', Rows.Take(CopyLastCount).Reverse()
|
||||
.Select(r => $"{r.Time} {r.Level.ToString().ToUpperInvariant()} {r.Message}"));
|
||||
|
||||
private static async Task<bool> CopyToClipboardAsync(string text)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop &&
|
||||
desktop.MainWindow?.Clipboard is { } clipboard)
|
||||
{
|
||||
try { await clipboard.SetTextAsync(text); return true; }
|
||||
catch { return false; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record LogVisualizerRow(string Time, string Message, WorkerLogLevel Level);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<ctl:ModalShell Title="{loc:Tr modals.logVisualizer.title}" CloseCommand="{Binding CloseCommand}">
|
||||
<DockPanel LastChildFill="True">
|
||||
<!-- Toolbar: filter · status · refresh -->
|
||||
<Grid DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto" Margin="14,10">
|
||||
<Grid DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto,Auto" Margin="14,10">
|
||||
<CheckBox Grid.Column="0"
|
||||
Content="{loc:Tr modals.logVisualizer.warnErrorOnly}"
|
||||
IsChecked="{Binding WarnErrorOnly}"
|
||||
@@ -31,7 +31,11 @@
|
||||
Text="{Binding StatusText}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource TextMuteBrush}"/>
|
||||
<Button Grid.Column="2" Classes="btn"
|
||||
<Button Grid.Column="2" Classes="btn" Margin="0,0,8,0"
|
||||
Content="{loc:Tr modals.logVisualizer.copyLast}"
|
||||
ToolTip.Tip="{loc:Tr modals.logVisualizer.copyLastTooltip}"
|
||||
Command="{Binding CopyLastCommand}"/>
|
||||
<Button Grid.Column="3" Classes="btn"
|
||||
Content="{loc:Tr modals.logVisualizer.refresh}"
|
||||
Command="{Binding RefreshCommand}"/>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user