Add hex color parsing helper and implement custom list sources for channels and users

- Introduced HexColorHelper for parsing hex color strings to Terminal.Gui Attributes and Colors.
- Created ChannelListSource for managing and rendering a list of channels with unread counts and active indicators.
- Developed UserListSource for displaying online users with per-user nickname colors.
- Refactored MainWindow to utilize ChatMessageManager for handling messages and channel state.
- Updated project references and removed unused content from the server project.
- Adjusted tests to reflect changes in namespaces and structure.
This commit is contained in:
HueByte
2026-02-22 08:08:21 +01:00
parent c5d8e25a86
commit c8ea124198
32 changed files with 1869 additions and 1586 deletions
@@ -5,7 +5,7 @@ using Terminal.Gui.ViewBase;
using Terminal.Gui.Views;
using Attribute = Terminal.Gui.Drawing.Attribute;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
public sealed class AudioPlayerDialog
{
@@ -4,7 +4,7 @@ using Terminal.Gui.App;
using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
/// <summary>
/// Result returned from the connect dialog.
@@ -2,7 +2,7 @@ using Terminal.Gui.App;
using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
public record CreateChannelResult(string Name, string? Topic, bool IsPublic);
@@ -1,10 +1,11 @@
using EchoHub.Client.UI.Helpers;
using Terminal.Gui.App;
using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
using Terminal.Gui.Drawing;
using Terminal.Gui.ViewBase;
using Terminal.Gui.Views;
using Attribute = Terminal.Gui.Drawing.Attribute;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
/// <summary>
/// Result returned from the profile edit dialog.
@@ -243,32 +244,13 @@ public sealed class ProfileEditDialog
return;
}
var color = ParseHexToTrueColor(hexColor.Trim());
var color = HexColorHelper.ParseHexToColor(hexColor.Trim(), Color.White);
preview.SetScheme(new Scheme
{
Normal = new Attribute(color, Color.Blue)
});
}
/// <summary>
/// Parses a hex color string to a Terminal.Gui TrueColor Color.
/// V2 supports TrueColor via new Color(r, g, b).
/// </summary>
private static Color ParseHexToTrueColor(string hex)
{
if (hex.StartsWith('#'))
hex = hex[1..];
if (hex.Length != 6 || !int.TryParse(hex, System.Globalization.NumberStyles.HexNumber, null, out var rgb))
return Color.White;
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = rgb & 0xFF;
return new Color(r, g, b);
}
private static string? NullIfEmpty(string? value) =>
string.IsNullOrWhiteSpace(value) ? null : value;
}
@@ -1,12 +1,14 @@
using Terminal.Gui.App;
using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
using Terminal.Gui.Drawing;
using EchoHub.Client.UI.Chat;
using EchoHub.Client.UI.Helpers;
using EchoHub.Core.DTOs;
using EchoHub.Core.Models;
using Terminal.Gui.App;
using Terminal.Gui.Drawing;
using Terminal.Gui.ViewBase;
using Terminal.Gui.Views;
using Attribute = Terminal.Gui.Drawing.Attribute;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
/// <summary>
/// Action selected by the user in their own profile dialog.
@@ -111,7 +113,7 @@ public sealed class ProfileViewDialog
// Color
var colorLabel = new Label { Text = "Color:", X = 1, Y = row };
var colorValue = new Label { Text = profile.NicknameColor ?? "-", X = 14, Y = row };
if (ColorHelper.ParseHexColor(profile.NicknameColor) is { } colorAttr)
if (HexColorHelper.ParseHexColor(profile.NicknameColor) is { } colorAttr)
colorValue.SetScheme(new Scheme { Normal = colorAttr });
dialog.Add(colorLabel, colorValue);
row++;
@@ -3,7 +3,7 @@ using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
using EchoHub.Core.Models;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
/// <summary>
/// Result returned from the status dialog.
@@ -2,7 +2,7 @@ using Terminal.Gui.App;
using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
public sealed class UpdateConfirmDialog
{
@@ -2,7 +2,7 @@ using Terminal.Gui.App;
using Terminal.Gui.Views;
using Terminal.Gui.ViewBase;
namespace EchoHub.Client.UI;
namespace EchoHub.Client.UI.Dialogs;
public sealed class UpdateProgressDialog
{