Skip to content

Commit 6675c2d

Browse files
claudebertyhell
authored andcommitted
enhance: show real progress of git operations in running popups
Git already streams progress lines like `Receiving objects: 45% (450/1000)` (fetch/pull/push/clone/checkout/submodule/LFS are run with `--progress`) and the latest line is shown as the popup's description, but the progress bar was always indeterminate. Parse the `NN%` after the phase name from the current description and use it for a determinate progress bar with a percentage label. Falls back to the indeterminate bar for lines without a percentage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KCxH1zwDXLd9kfAAkcf6PZ
1 parent 3e65576 commit 6675c2d

2 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎src/Views/PopupRunningStatus.axaml‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@
2121
FontStyle="Italic"
2222
Text="{Binding #ThisControl.Description}"/>
2323

24-
<ProgressBar x:Name="ProgressBar"
25-
Margin="0,8,0,0"
26-
HorizontalAlignment="Stretch"
27-
Background="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.Accent}"
28-
Minimum="0" Maximum="100"/>
24+
<Grid Margin="0,8,0,0" ColumnDefinitions="*,Auto">
25+
<ProgressBar Grid.Column="0"
26+
x:Name="ProgressBar"
27+
HorizontalAlignment="Stretch"
28+
Background="{DynamicResource Brush.FG2}" Foreground="{DynamicResource Brush.Accent}"
29+
Minimum="0" Maximum="100"/>
30+
31+
<TextBlock Grid.Column="1"
32+
x:Name="Percentage"
33+
Margin="8,0,0,0"
34+
MinWidth="32"
35+
TextAlignment="Right"
36+
VerticalAlignment="Center"
37+
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=DefaultFontSize, Converter={x:Static c:DoubleConverters.Decrease}}"
38+
IsVisible="False"/>
39+
</Grid>
2940
</StackPanel>
3041
</UserControl>

‎src/Views/PopupRunningStatus.axaml.cs‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.RegularExpressions;
12
using Avalonia;
23
using Avalonia.Controls;
34
using Avalonia.Controls.Shapes;
@@ -50,12 +51,17 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
5051
else
5152
StopAnim();
5253
}
54+
else if (change.Property == DescriptionProperty)
55+
{
56+
if (IsVisible && !_isUnloading)
57+
UpdateProgress();
58+
}
5359
}
5460

5561
private void StartAnim()
5662
{
5763
Icon.Content = new Path() { Classes = { "waiting" } };
58-
ProgressBar.IsIndeterminate = true;
64+
UpdateProgress();
5965
}
6066

6167
private void StopAnim()
@@ -64,9 +70,33 @@ private void StopAnim()
6470
path.Classes.Clear();
6571
Icon.Content = null;
6672
ProgressBar.IsIndeterminate = false;
73+
ProgressBar.Value = 0;
74+
Percentage.IsVisible = false;
75+
}
76+
77+
private void UpdateProgress()
78+
{
79+
// Git reports the progress of long-running operations as `<phase>: NN% (...)`. Only the
80+
// percentage is used here, so it also works with translated phase names.
81+
var match = string.IsNullOrEmpty(_description) ? null : REG_PROGRESS().Match(_description);
82+
if (match is { Success: true } && int.TryParse(match.Groups[1].Value, out var percent) && percent <= 100)
83+
{
84+
ProgressBar.IsIndeterminate = false;
85+
ProgressBar.Value = percent;
86+
Percentage.Text = $"{percent}%";
87+
Percentage.IsVisible = true;
88+
}
89+
else
90+
{
91+
ProgressBar.IsIndeterminate = true;
92+
Percentage.IsVisible = false;
93+
}
6794
}
6895

6996
private string _description = string.Empty;
7097
private bool _isUnloading = false;
98+
99+
[GeneratedRegex(@"^[^%]+?:\s+(\d{1,3})%")]
100+
private static partial Regex REG_PROGRESS();
71101
}
72102
}

0 commit comments

Comments
 (0)