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
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: 2

updates:
# NuGet dependencies. Terminal.Gui is the one that matters: the app pins 2.4.17 and
# works around two defects in it (see ThemeCatalog and tests/Netiflux.Ui.Tests/README.md),
# NuGet dependencies. Terminal.Gui is the one that matters: its config API changes between minor
# releases (see ThemeCatalog) and the tests work around quirks (tests/Netiflux.Ui.Tests/README.md),
# so its updates are grouped alone and deserve a real look rather than an auto-merge.
- package-ecosystem: nuget
directory: /
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Terminal.Gui 2.5.0. Theme loading moved off the removed `ConfigurationManager` API; existing `themes.json` files keep working.

## [0.1.0] - 2026-08-13

First release.
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,5 @@ Update [`CHANGELOG.md`](CHANGELOG.md) before tagging.
### Dependencies

[Dependabot](.github/dependabot.yml) opens weekly PRs for NuGet packages and workflow
actions. Terminal.Gui is grouped on its own deliberately: the app pins 2.4.17 and works
around two defects in it, so its updates want a real look rather than a rubber stamp.

## Known limitation

Terminal.Gui 2.4.17 marks its `ConfigurationManager` / `ThemeManager` statics obsolete in
favour of `TuiConfigurationBuilder`, but that replacement is not functional in this
release — it reports only the `Default` theme and its `SwitchTheme` fails, even for the
library's own built-in themes. Netiflux therefore uses the legacy API, isolated in
[`ThemeCatalog`](src/Netiflux/Theming/ThemeCatalog.cs), and should move over once the new
one works.
actions. Terminal.Gui is grouped on its own deliberately: its config API changes between
minor releases and the app works around some of its quirks, so updates want a real look.
2 changes: 1 addition & 1 deletion src/Netiflux/Netiflux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Terminal.Gui" Version="2.4.17" />
<PackageReference Include="Terminal.Gui" Version="2.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Netiflux/Resources/themes.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$comment": [
"Netiflux bundled themes. Loaded into Terminal.Gui's ConfigurationManager at startup.",
"Netiflux bundled themes. Loaded into Terminal.Gui at startup.",
"To add your own theme, copy one of these blocks into ~/.tui/config.json (or",
"%USERPROFILE%\\.tui\\config.json) under a top-level \"Themes\" array. Anything you put",
"there overrides what ships here, so you can also retune a single scheme of a built-in",
Expand Down
90 changes: 66 additions & 24 deletions src/Netiflux/Theming/ThemeCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ namespace Netiflux.Theming;

/// <summary>
/// Owns Netiflux's theme story: merges the bundled palettes with any the user wrote,
/// hands them to Terminal.Gui's <see cref="ConfigurationManager"/>, and resolves the
/// hands them to Terminal.Gui's <see cref="TuiConfigurationBuilder"/>, and resolves the
/// app-specific scheme names the UI draws with.
/// </summary>
/// <remarks>
/// This uses the <c>ConfigurationManager</c> / <c>ThemeManager</c> statics, which
/// Terminal.Gui 2.4.17 marks obsolete in favour of <c>TuiConfigurationBuilder</c>. The
/// replacement is not working yet in that release: its <c>ThemeManager.ThemeNames</c>
/// returns only "Default" and <c>SwitchTheme</c> fails, even for the library's own
/// built-in themes, while the legacy path loads and switches everything correctly.
/// Revisit when the new API becomes functional.
/// Terminal.Gui 2.5.0 expects <c>Themes</c> and <c>Schemes</c> as objects keyed by name
/// and settings nested rather than dotted. <c>themes.json</c> is written in the older
/// array / dotted form, so <see cref="BuildMergedConfig"/> translates it (and passes the
/// new form through unchanged).
/// </remarks>
#pragma warning disable CS0618 // Obsolete configuration API — see the remarks above.
public static class ThemeCatalog
{
private const string BundledResourceName = "Netiflux.Resources.themes.json";
Expand All @@ -45,8 +42,8 @@ public static IReadOnlyList<string> Initialize(string? preferredTheme)

try
{
ConfigurationManager.RuntimeConfig = BuildMergedConfig(warnings);
ConfigurationManager.Enable(ConfigLocations.All);
TuiConfigurationBuilder.Shared.RuntimeConfig = BuildMergedConfig(warnings);
TuiConfigurationBuilder.Shared.ApplyToStaticFacades();
_enabled = true;
}
catch (Exception ex) when (ex is JsonException or IOException or InvalidOperationException)
Expand Down Expand Up @@ -85,7 +82,6 @@ public static void Apply(string? themeName, List<string>? warnings = null)
}

ThemeManager.Theme = target;
ConfigurationManager.Apply();
SchemeCache.Clear();
}

Expand Down Expand Up @@ -182,13 +178,62 @@ private static string BuildMergedConfig(List<string> warnings)
}
}

var array = new JsonArray();
var themes = new JsonObject();
foreach (var name in order)
{
array.Add(new JsonObject { [name] = themesByName[name]?.DeepClone() });
if (themesByName[name] is JsonObject body)
{
themes[name] = NormalizeTheme(body);
}
}

return new JsonObject { ["Themes"] = array }.ToJsonString();
return new JsonObject { ["Themes"] = themes }.ToJsonString();
}

/// <summary>
/// Rewrites one theme body into the nested form: <c>Schemes</c> as an object rather
/// than an array of single-key objects, and <c>Window.DefaultBorderStyle</c>-style keys
/// as <c>Window: { DefaultBorderStyle }</c>.
/// </summary>
private static JsonObject NormalizeTheme(JsonObject body)
{
var result = new JsonObject();

foreach (var (key, value) in body)
{
if (key == "Schemes" && value is JsonArray schemeList)
{
var schemes = new JsonObject();
foreach (var wrapper in schemeList.OfType<JsonObject>())
{
foreach (var (schemeName, scheme) in wrapper)
{
schemes[schemeName] = scheme?.DeepClone();
}
}

result[key] = schemes;
continue;
}

var dot = key.IndexOf('.');
if (dot <= 0)
{
result[key] = value?.DeepClone();
continue;
}

var section = key[..dot];
if (result[section] is not JsonObject nested)
{
nested = new JsonObject();
result[section] = nested;
}

nested[key[(dot + 1)..]] = value?.DeepClone();
}

return result;
}

private static IEnumerable<(string Name, JsonNode? Body)> ReadThemes(
Expand Down Expand Up @@ -216,18 +261,16 @@ private static string BuildMergedConfig(List<string> warnings)
yield break;
}

if (root?["Themes"] is not JsonArray themes)
// Accept both the array form ([{ "Name": { … } }]) and the object form.
var wrappers = root?["Themes"] switch
{
yield break;
}
JsonArray array => array.OfType<JsonObject>(),
JsonObject obj => [obj],
_ => []
};

foreach (var element in themes)
foreach (var wrapper in wrappers)
{
if (element is not JsonObject wrapper)
{
continue;
}

foreach (var (name, body) in wrapper)
{
yield return (name, body);
Expand All @@ -245,4 +288,3 @@ private static string LoadBundledJson()
return reader.ReadToEnd();
}
}
#pragma warning restore CS0618
21 changes: 15 additions & 6 deletions src/Netiflux/Ui/AppShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,23 @@ private void RebuildSidebar()

_sidebar.SetNeedsDraw();

if (selected is { } index && index < _sidebarSource.Count)
// Restoring the cursor is not a request to load: doing so would start a second
// load that clears the session's entries while the first is still being applied.
_suppressSidebarLoad = true;
try
{
_sidebar.SelectedItem = index;
if (selected is { } index && index < _sidebarSource.Count)
{
_sidebar.SelectedItem = index;
}
else
{
_sidebar.SelectedItem = 1;
}
}
else
finally
{
_sidebar.SelectedItem = 1;
_suppressSidebarLoad = false;
}
}

Expand Down Expand Up @@ -552,8 +562,7 @@ private void OnSidebarSelectionChanged(object? sender, ValueChangedEventArgs<int
}

private void LoadSidebarSelection(SidebarItem item)
{
_ = RunOperationAsync($"Loading {item.Label}…", ct =>
{ _ = RunOperationAsync($"Loading {item.Label}…", ct =>
_session.LoadEntriesAsync(item.ToQuery(_config.PageSize), ct),
onSuccess: () => RefreshListFromSession(selectFirst: true));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Netiflux.Core.Tests/Netiflux.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<PackageReference Include="Terminal.Gui" Version="2.4.17" />
<PackageReference Include="Terminal.Gui" Version="2.5.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions tests/Netiflux.Ui.Tests/FakeMinifluxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public sealed class FakeMinifluxClient(List<Entry> entries) : IMinifluxClient

public int RefreshCount { get; private set; }

private int _entryRequests;

/// <summary>How many times the entry list has been loaded from the server.</summary>
public int EntryRequestCount => Volatile.Read(ref _entryRequests);

/// <summary>Armed to make the next mutating call fail, for rollback tests.</summary>
public Exception? NextFailure { get; set; }

Expand All @@ -24,6 +29,11 @@ public Task<MinifluxUser> GetMeAsync(CancellationToken ct = default) =>

public Task<EntryPage> GetEntriesAsync(EntryQuery query, CancellationToken ct = default)
{
// The single-row starred query is how the session reads a count, not a list load.
if (!(query.Starred == true && query.Limit == 1))
{
Interlocked.Increment(ref _entryRequests); }

ThrowIfArmed();

IEnumerable<Entry> match = Entries;
Expand Down
2 changes: 1 addition & 1 deletion tests/Netiflux.Ui.Tests/Netiflux.Ui.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<PackageReference Include="Terminal.Gui" Version="2.4.17" />
<PackageReference Include="Terminal.Gui" Version="2.5.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0" />
</ItemGroup>
Expand Down
51 changes: 51 additions & 0 deletions tests/Netiflux.Ui.Tests/ThemeCatalogTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Netiflux.Theming;

namespace Netiflux.Ui.Tests;

/// <summary>
/// Terminal.Gui silently ignores theme config it can't parse, so a format change shows up
/// as missing themes rather than an error. These pin the bundled themes actually loading.
/// </summary>
[Collection(nameof(UiTestCollection))]
public class ThemeCatalogTests
{
private static readonly string[] BundledThemes =
[
"Netiflux Dark", "Netiflux Light", "Netiflux Gruvbox", "Netiflux Nord", "Netiflux Rose Pine"
];

public ThemeCatalogTests() => ThemeCatalog.Initialize("Netiflux Dark");

[Fact]
public void Initialize_LoadsEveryBundledTheme()
{
var names = ThemeCatalog.GetThemeNames();

Assert.All(BundledThemes, theme => Assert.Contains(theme, names));
Assert.Equal("Netiflux Dark", ThemeCatalog.CurrentTheme);
}

[Theory]
[InlineData("Sidebar")]
[InlineData("EntryUnread")]
public void Resolve_ReturnsTheThemesOwnScheme_NotTheBaseFallback(string schemeName)
{
var resolved = ThemeCatalog.Resolve(schemeName);
var fallback = ThemeCatalog.Resolve("NoSuchScheme");

Assert.NotEqual(fallback.Normal, resolved.Normal);
}

[Fact]
public void Apply_SwitchesTheme_AndResolvesItsSchemes()
{
var dark = ThemeCatalog.Resolve("Sidebar").Normal;

ThemeCatalog.Apply("Netiflux Light");
var light = ThemeCatalog.Resolve("Sidebar").Normal;
ThemeCatalog.Apply("Netiflux Dark");

Assert.Equal("Netiflux Dark", ThemeCatalog.CurrentTheme);
Assert.NotEqual(dark, light);
}
}
10 changes: 10 additions & 0 deletions tests/Netiflux.Ui.Tests/TriageKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public async Task Save_RecordsTheEntryInTheLocalSavedStore()
await ui.WaitForAsync(() => ui.Session.SavedStore.IsSaved(1), "entry 1 to be recorded locally");
}

[Fact]
public async Task InitialLoad_FetchesEntriesOnce()
{
// Restoring the sidebar cursor after the first load must not start a second one;
// the two would race over the session's entry list.
await using var ui = await ShellHarness.StartAsync();

Assert.Equal(1, ui.Client.EntryRequestCount);
}

[Fact]
public async Task Star_AppliesToTheHighlightedRow()
{
Expand Down
Loading