Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Copyright>Copyright (c) gui-cs and contributors</Copyright>

<!-- Pinned Terminal.Gui version. CI / release workflows can override via -p:TerminalGuiVersion=<x>. -->
<TerminalGuiVersion Condition="'$(TerminalGuiVersion)' == ''">2.1.1-develop.*</TerminalGuiVersion>
<TerminalGuiVersion Condition="'$(TerminalGuiVersion)' == ''">2.1.1-develop.98</TerminalGuiVersion>
<!-- Pinned Terminal.Gui.Editor version. CI / release workflows can override via -p:TerminalGuiEditorVersion=<x>. -->
<TerminalGuiEditorVersion Condition="'$(TerminalGuiEditorVersion)' == ''">2.1.1-develop.*</TerminalGuiEditorVersion>
</PropertyGroup>
Expand Down
29 changes: 28 additions & 1 deletion src/Clet/Clets/Viewer/ConfigClet.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Text.Json;
using Terminal.Gui.App;
using Terminal.Gui.Configuration;
Expand Down Expand Up @@ -53,6 +55,7 @@ public async Task<CletRunResult> RunAsync (
Title = options.Title ?? $"clet config — {configPath}",
Width = Dim.Fill (),
Height = Dim.Fill (),
BorderStyle = LineStyle.None,
};

Editor editor = new ()
Expand All @@ -62,6 +65,7 @@ public async Task<CletRunResult> RunAsync (
ConvertTabsToSpaces = true,
IndentationSize = 2,
GutterOptions = GutterOptions.LineNumbers,
ViewportSettings = ViewportSettingsFlags.HasScrollBars,
};

editor.HighlightingDefinition = HighlightingManager.Instance.GetDefinitionByExtension (".json");
Expand All @@ -85,12 +89,35 @@ public async Task<CletRunResult> RunAsync (
UpdateTitle ();
};

// --- Theme selector ---

ImmutableList<string> themeNames = ThemeManager.GetThemeNames ();
ObservableCollection<string> themeCollection = new (themeNames);

DropDownList themeDropDown = new ()
{
Source = new ListWrapper<string> (themeCollection),
ReadOnly = true,
Text = ThemeManager.Theme,
Width = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 10),
};

themeDropDown.ValueChanged += (_, _) =>
{
string selected = themeDropDown.Text;

if (!string.IsNullOrEmpty (selected) && selected != ThemeManager.Theme)
{
ThemeManager.Theme = selected;
}
};

// --- StatusBar ---

Shortcut saveShortcut = new (Key.S.WithCtrl, "Save", () => Save ());
Shortcut quitShortcut = new (Application.GetDefaultKey (Command.Quit), "Quit", () => TryQuit ());

StatusBar statusBar = new ([quitShortcut, saveShortcut, statusMessage, cursorPosition])
StatusBar statusBar = new ([quitShortcut, saveShortcut, statusMessage, cursorPosition, new Shortcut { Title = "Theme", CommandView = themeDropDown }])
{
AlignmentModes = AlignmentModes.IgnoreFirstOrLast,
};
Expand Down
48 changes: 25 additions & 23 deletions src/Clet/Clets/Viewer/EditorClet.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using Terminal.Gui.App;
using Terminal.Gui.Configuration;
Expand Down Expand Up @@ -131,7 +132,6 @@ FileAccessPolicy BuildPolicy (IReadOnlyList<string>? extraAllowed = null)
IndentationSize = EditorSettings.IndentSize,
WordWrap = EditorSettings.WordWrap,
ShowTabs = EditorSettings.ShowTabs,
UseThemeBackground = EditorSettings.UseThemeBackground,
ViewportSettings = ViewportSettingsFlags.HasScrollBars,
};

Expand Down Expand Up @@ -193,8 +193,6 @@ void InstallFolding ()
// View-menu toggle items — declared early so preview toggle can reference them.
MenuItem previewMarkdownItem = new () { Title = " _Preview Markdown", Enabled = isMarkdownFile };

bool optUseThemeBg = EditorSettings.UseThemeBackground;

void OnEditorViewportChanged (object? sender, DrawEventArgs e)
{
if (markdownPreview is null || syncingScroll)
Expand Down Expand Up @@ -285,7 +283,6 @@ void ShowMarkdownPreview ()
Text = editor.Document?.Text ?? string.Empty,
ViewportSettings = ViewportSettingsFlags.HasScrollBars,
SyntaxHighlighter = new TextMateSyntaxHighlighter (ThemeName.DarkPlus),
UseThemeBackground = optUseThemeBg,
};

editor.Width = Dim.Percent (50);
Expand Down Expand Up @@ -790,15 +787,12 @@ .. CreateEditMenuItems (),
MenuItem viewFoldIndicatorsItem = new () { Title = ToggleTitle (optFoldIndicators, "_Fold Indicators") };
MenuItem viewWordWrapItem = new () { Title = ToggleTitle (optWordWrap, "_Word Wrap") };
MenuItem viewShowTabsItem = new () { Title = ToggleTitle (optShowTabs, "Show _Tabs") };
MenuItem viewUseThemeBgItem = new () { Title = ToggleTitle (optUseThemeBg, "Use _Theme Background") };

void SaveViewSettings ()
{
EditorSettings.LineNumbers = optLineNumbers;
EditorSettings.FoldIndicators = optFoldIndicators;
EditorSettings.WordWrap = optWordWrap;
EditorSettings.ShowTabs = optShowTabs;
EditorSettings.UseThemeBackground = optUseThemeBg;
EditorSettings.IndentSize = editor.IndentationSize;
EditorSettings.ConvertTabsToSpaces = editor.ConvertTabsToSpaces;
EditorSettings.AutoIndent = editor.IndentationStrategy is not null;
Expand Down Expand Up @@ -837,20 +831,6 @@ void SaveViewSettings ()
SaveViewSettings ();
};

viewUseThemeBgItem.Action = () =>
{
optUseThemeBg = !optUseThemeBg;
viewUseThemeBgItem.Title = ToggleTitle (optUseThemeBg, "Use _Theme Background");
editor.UseThemeBackground = optUseThemeBg;

if (markdownPreview is not null)
{
markdownPreview.UseThemeBackground = optUseThemeBg;
}

SaveViewSettings ();
};

previewMarkdownItem.Action = () =>
{
if (isMarkdownFile)
Expand All @@ -867,8 +847,6 @@ void SaveViewSettings ()
viewShowTabsItem,
null!,
previewMarkdownItem,
null!,
viewUseThemeBgItem,
]));

// --- Options menu ---
Expand Down Expand Up @@ -915,6 +893,29 @@ void SaveViewSettings ()
UpdateLocShortcut ();
};

// --- Theme selector ---

ImmutableList<string> themeNames = ThemeManager.GetThemeNames ();
ObservableCollection<string> themeCollection = new (themeNames);

DropDownList themeDropDown = new ()
{
Source = new ListWrapper<string> (themeCollection),
ReadOnly = true,
Text = ThemeManager.Theme,
Width = Dim.Auto (DimAutoStyle.Text, minimumContentDim: 10),
};

themeDropDown.ValueChanged += (_, _) =>
{
string selected = themeDropDown.Text;

if (!string.IsNullOrEmpty (selected) && selected != ThemeManager.Theme)
{
ThemeManager.Theme = selected;
}
};

// --- StatusBar ---

List<Shortcut> statusItems =
Expand All @@ -924,6 +925,7 @@ void SaveViewSettings ()
new Shortcut (Key.F3, "Save", () => SaveFile ()),
cursorPositionShortcut,
languageShortcut,
new Shortcut { Title = "Theme", CommandView = themeDropDown },
];

// File selector: dropdown when multiple files, plain label otherwise
Expand Down
5 changes: 0 additions & 5 deletions src/Clet/Clets/Viewer/EditorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ internal static class EditorSettings
[ConfigurationProperty (Scope = typeof (SettingsScope))]
public static bool ShowTabs { get; set; }

[ConfigurationProperty (Scope = typeof (SettingsScope))]
public static bool UseThemeBackground { get; set; }

// --- Tab settings ---

[ConfigurationProperty (Scope = typeof (SettingsScope))]
Expand All @@ -49,7 +46,6 @@ internal static class EditorSettings
"EditorSettings.FoldIndicators",
"EditorSettings.WordWrap",
"EditorSettings.ShowTabs",
"EditorSettings.UseThemeBackground",
"EditorSettings.IndentSize",
"EditorSettings.ConvertTabsToSpaces",
"EditorSettings.AutoIndent",
Expand Down Expand Up @@ -82,7 +78,6 @@ internal static void Save (string path)
["EditorSettings.FoldIndicators"] = ToJson (FoldIndicators),
["EditorSettings.WordWrap"] = ToJson (WordWrap),
["EditorSettings.ShowTabs"] = ToJson (ShowTabs),
["EditorSettings.UseThemeBackground"] = ToJson (UseThemeBackground),
["EditorSettings.IndentSize"] = IndentSize.ToString (),
["EditorSettings.ConvertTabsToSpaces"] = ToJson (ConvertTabsToSpaces),
["EditorSettings.AutoIndent"] = ToJson (AutoIndent),
Expand Down
13 changes: 0 additions & 13 deletions src/Clet/Clets/Viewer/MarkdownClet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,6 @@ public async Task<CletRunResult> RunAsync (

statusItems.Add (new Shortcut { Title = "Theme", CommandView = themeDropDown });

// Auto-select light or dark syntax theme based on terminal background
app.Driver!.DefaultAttributeChanged += (_, e) =>
{
if (e.NewValue is not { } attr)
{
return;
}

ThemeName autoTheme = TextMateSyntaxHighlighter.GetThemeForBackground (attr.Background);
markdownView.SyntaxHighlighter = new TextMateSyntaxHighlighter (autoTheme);
themeDropDown.Value = autoTheme;
};

// Theme background toggle
CheckBox themeBgCheckBox = new ()
{
Expand Down
6 changes: 1 addition & 5 deletions tests/Clet.UnitTests/EditorSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public void ManagedKeys_ContainsAllProperties ()
Assert.Contains ("EditorSettings.FoldIndicators", EditorSettings.ManagedKeys);
Assert.Contains ("EditorSettings.WordWrap", EditorSettings.ManagedKeys);
Assert.Contains ("EditorSettings.ShowTabs", EditorSettings.ManagedKeys);
Assert.Contains ("EditorSettings.UseThemeBackground", EditorSettings.ManagedKeys);
Assert.Contains ("EditorSettings.IndentSize", EditorSettings.ManagedKeys);
Assert.Contains ("EditorSettings.ConvertTabsToSpaces", EditorSettings.ManagedKeys);
Assert.Contains ("EditorSettings.AutoIndent", EditorSettings.ManagedKeys);
Assert.Equal (8, EditorSettings.ManagedKeys.Count);
Assert.Equal (7, EditorSettings.ManagedKeys.Count);
}

[Fact]
Expand All @@ -97,7 +96,6 @@ public void Save_WritesAllKeys_ToConfigFile ()
EditorSettings.FoldIndicators = false;
EditorSettings.WordWrap = true;
EditorSettings.ShowTabs = true;
EditorSettings.UseThemeBackground = true;
EditorSettings.IndentSize = 2;
EditorSettings.ConvertTabsToSpaces = false;
EditorSettings.AutoIndent = true;
Expand Down Expand Up @@ -126,7 +124,6 @@ public void Save_WritesAllKeys_ToConfigFile ()
Assert.False ((bool)obj["EditorSettings.FoldIndicators"]!);
Assert.True ((bool)obj["EditorSettings.WordWrap"]!);
Assert.True ((bool)obj["EditorSettings.ShowTabs"]!);
Assert.True ((bool)obj["EditorSettings.UseThemeBackground"]!);
Assert.Equal (2, (int)obj["EditorSettings.IndentSize"]!);
Assert.False ((bool)obj["EditorSettings.ConvertTabsToSpaces"]!);
Assert.True ((bool)obj["EditorSettings.AutoIndent"]!);
Expand Down Expand Up @@ -392,7 +389,6 @@ public void Defaults_AreCorrect ()
Assert.True (EditorSettings.FoldIndicators);
Assert.False (EditorSettings.WordWrap);
Assert.False (EditorSettings.ShowTabs);
Assert.False (EditorSettings.UseThemeBackground);
Assert.Equal (4, EditorSettings.IndentSize);
Assert.True (EditorSettings.ConvertTabsToSpaces);
Assert.False (EditorSettings.AutoIndent);
Expand Down
Loading