Skip to content

Commit 231010a

Browse files
committed
ux: custom style for command line in git command log
Signed-off-by: leo <[email protected]>
1 parent 3358ff9 commit 231010a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Views/ViewLogs.axaml.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,39 @@
44
using Avalonia.Controls;
55
using Avalonia.Controls.Primitives;
66
using Avalonia.Interactivity;
7+
using Avalonia.Media;
78

89
using AvaloniaEdit;
910
using AvaloniaEdit.Document;
1011
using AvaloniaEdit.Editing;
12+
using AvaloniaEdit.Rendering;
1113
using AvaloniaEdit.TextMate;
1214

1315
namespace SourceGit.Views
1416
{
1517
public class LogContentPresenter : TextEditor
1618
{
19+
public class LineStyleTransformer : DocumentColorizingTransformer
20+
{
21+
protected override void ColorizeLine(DocumentLine line)
22+
{
23+
var content = CurrentContext.Document.GetText(line);
24+
if (content.StartsWith("$ git ", StringComparison.Ordinal))
25+
{
26+
ChangeLinePart(line.Offset, line.Offset + 1, v =>
27+
{
28+
v.TextRunProperties.SetForegroundBrush(Brushes.Orange);
29+
});
30+
31+
ChangeLinePart(line.Offset + 2, line.EndOffset, v =>
32+
{
33+
var old = v.TextRunProperties.Typeface;
34+
v.TextRunProperties.SetTypeface(new Typeface(old.FontFamily, old.Style, FontWeight.Bold));
35+
});
36+
}
37+
}
38+
}
39+
1740
public static readonly StyledProperty<ViewModels.CommandLog> LogProperty =
1841
AvaloniaProperty.Register<LogContentPresenter, ViewModels.CommandLog>(nameof(Log));
1942

@@ -46,6 +69,7 @@ protected override void OnLoaded(RoutedEventArgs e)
4669
{
4770
_textMate = Models.TextMateHelper.CreateForEditor(this);
4871
Models.TextMateHelper.SetGrammarByFileName(_textMate, "Log.log");
72+
TextArea.TextView.LineTransformers.Add(new LineStyleTransformer());
4973
}
5074
}
5175

0 commit comments

Comments
 (0)