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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`]
become `_`, and a name like `CON` is changed so Windows will take it. A name that needed none of this names the same
file as before.

- A world connected with no character (`/connect host`, a `telnet://` link, Browse worlds) can be closed again. Its tab
was the client's main window, which only closed once a character was deleted, so ⌃W, ⌃B x and the tab's × did
nothing. Closing it now ends that connection. Its world's row in the sidebar reads *no character* and opens it again,
and ⌃P lists it under *Switch to*; it used to say the world had no characters and offer no way back. Closing a
character's own window still refuses, and now says so instead of doing nothing.

## [0.3.6] - 2026-11-16

### Added
Expand Down
5 changes: 3 additions & 2 deletions src/SharpMUTerm.Avalonia/NativeChrome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,9 @@ protected override void Layout(ChromeOverlay overlay, List<(Rect Area, string Ta
foreach (var character in world.Characters)
{
var area = folded ? new Rect((width - 36) / 2, y, 36, row) : new Rect(RowInset, y, width - (2 * RowInset), row);
var who = character.Alone ? $"{world.Name}, no character" : $"{character.Name} on {world.Name}";
var tip = folded
? $"{character.Name} on {world.Name}{(character.Connected ? string.Empty : " (offline)")}{(character.Unread > 0 ? $", {UnreadText(character.Unread)} unread" : string.Empty)}"
? $"{who}{(character.Connected ? string.Empty : " (offline)")}{(character.Unread > 0 ? $", {UnreadText(character.Unread)} unread" : string.Empty)}"
: $"Switch to {character.Name}";
Add(new Row(RailRowKind.Character, area, world, character), SidebarModel.TargetOf(character), tip);
y += row;
Expand Down Expand Up @@ -1286,7 +1287,7 @@ private void DrawCharacter(DrawingContext context, Row r, RailCharacter characte
}

var x = r.Area.X + CharacterIndent;
Text(context, character.Name, x, middle, size, character.Connected ? Ink : Dim, bold: character.Active, maxWidth: Math.Max(1, right - x));
Text(context, character.Label, x, middle, size, character.Connected ? Ink : Dim, bold: character.Active, maxWidth: Math.Max(1, right - x));
}

private void DrawWindow(DrawingContext context, Row r, RailWindow window, Color accent, bool selected, double middle, double right, double size)
Expand Down
2 changes: 1 addition & 1 deletion src/SharpMUTerm.Client/Chrome/SidebarModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ private static bool SameWorld(RailWorld a, RailWorld b) =>

private static bool SameCharacter(RailCharacter a, RailCharacter b) =>
a.Name == b.Name && a.SessionKey == b.SessionKey && a.Connected == b.Connected && a.Active == b.Active
&& a.Unread == b.Unread && a.Chord == b.Chord && a.InGroup == b.InGroup && Equals(a.Avatar, b.Avatar)
&& a.Unread == b.Unread && a.Chord == b.Chord && a.InGroup == b.InGroup && a.Alone == b.Alone && Equals(a.Avatar, b.Avatar)
&& a.Windows.SequenceEqual(b.Windows); // RailWindow has no list member, so its record equality is by value
}
2 changes: 1 addition & 1 deletion src/SharpMUTerm.Client/Commands/BuiltInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ private static IEnumerable<CommandItem> Characters(ICommandContext context)
: string.Empty;
yield return new CommandItem(
CommandGroup.GoTo,
$"Switch to {character.CharacterName}",
$"Switch to {(character.CharacterName.Length > 0 ? character.CharacterName : character.WorldName)}",
CommandIds.Character(character.SessionKey),
$"{chord}{character.WorldName} · {state}")
{
Expand Down
20 changes: 18 additions & 2 deletions src/SharpMUTerm.Core/Workspaces/RailModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public sealed record RailWorld(
/// <paramref name="Avatar"/> is the picture to draw for the character: its own once loaded, else its world's, else
/// null and the views draw the dot or the initial they always drew.
/// </para>
/// <para>
/// <paramref name="Alone"/> marks a world's own session, for a world with no character configured (one added by
/// <c>/connect host</c>, a link or Browse): <paramref name="Name"/> and <paramref name="SessionKey"/> are the world's
/// name, as every other surface names that session, and the row reads <see cref="RailModel.AloneLabel"/> under its world.
/// </para>
/// </summary>
public sealed record RailCharacter(
string Name,
Expand All @@ -86,7 +91,12 @@ public sealed record RailCharacter(
IReadOnlyList<RailWindow> Windows,
string? Chord = null,
bool InGroup = false,
AvatarPicture? Avatar = null);
AvatarPicture? Avatar = null,
bool Alone = false)
{
/// <summary>What the row says: the character's name, or <see cref="RailModel.AloneLabel"/> for a world's own session.</summary>
public string Label => Alone ? RailModel.AloneLabel : Name;
}

/// <summary>
/// A window in the rail: its title, the workspace id a click activates, the <c>⌥N</c> chord that goes
Expand Down Expand Up @@ -138,6 +148,12 @@ public static class RailModel
/// </summary>
public const string NoCharactersPrefix = "rail:no-characters:";

/// <summary>
/// The row a world's own session is drawn as when the world has no character (<see cref="RailCharacter.Alone"/>):
/// under the world's name, so the row says what is missing rather than the name a second time.
/// </summary>
public const string AloneLabel = "no character";

/// <summary>The target a click on a character-less <paramref name="worldName"/> reports through.</summary>
public static string NoCharactersTarget(string worldName) => NoCharactersPrefix + worldName;

Expand All @@ -163,7 +179,7 @@ public static IReadOnlyList<RailRow> Build(IReadOnlyList<RailWorld> worlds)
rows.Add(new RailRow(
RailRowKind.Character,
1,
character.Name,
character.Label,
Accent: world.Accent,
Active: character.Active,
Connected: character.Connected,
Expand Down
22 changes: 20 additions & 2 deletions src/SharpMUTerm.Tui/RailRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SharpConsoleUI.Parsing;
using SharpMUTerm.Client.Chrome;
using SharpMUTerm.Core.Avatars;
using SharpMUTerm.Core.Commands;
using SharpMUTerm.Core.Text;
using SharpMUTerm.Core.Workspaces;
using static SharpMUTerm.Tui.MarkupText;
Expand Down Expand Up @@ -169,12 +170,29 @@ public static List<string> RenderCollapsed(IReadOnlyList<RailRow> rows, ChromeIn
{
var voice = ink ?? ChromeInk.Default;
var lines = new List<string>();
var letters = InitialLength(rows.Where(r => r.Kind == RailRowKind.Character).Select(r => r.Label));
// A world's own session (no character) reads "no character" open, but its letter is the world's, as the
// window's folded sidebar draws it: its target is the world's name.
var world = string.Empty;
string NameOf(RailRow row, string worldName) =>
row.Kind == RailRowKind.Character && row.Target == CommandIds.Character(worldName) ? worldName : row.Label;
var named = new List<string>();
foreach (var row in rows)
{
world = row.Kind == RailRowKind.World ? row.Label : world;
if (row.Kind == RailRowKind.Character)
{
named.Add(NameOf(row, world));
}
}

var letters = InitialLength(named);
world = string.Empty;
foreach (var row in rows)
{
switch (row.Kind)
{
case RailRowKind.World:
world = row.Label;
lines.Add(Link(row, $"[{Accent(row, voice)}]{CollapsedWorldMark}[/]"));
break;
case RailRowKind.Character:
Expand All @@ -188,7 +206,7 @@ public static List<string> RenderCollapsed(IReadOnlyList<RailRow> rows, ChromeIn
break;
}

var initial = Escape(Initials(row.Label, letters));
var initial = Escape(Initials(NameOf(row, world), letters));
var dot = row.Connected ? "●" : "○";
var name = row.Active ? $"[bold]{initial}[/]" : initial;
lines.Add(Link(row, $"[{Accent(row, voice)}]{dot}[/]{name}{UnreadField(row.Unread, voice)}"));
Expand Down
2 changes: 1 addition & 1 deletion src/SharpMUTerm.Tui/SharpMUTermApp.CharacterMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal MenuModel HeaderCharacterMenu()
frontConnected = character.Connected;
}

var name = CharacterNames.Display(world.Name, character.Name);
var name = CharacterNames.Display(world.Name, character.Alone ? null : character.Name);
var label = character.Connected ? name : $"{name} (offline)";
var command = CommandIds.Character(character.SessionKey);
if (_contributions.Commands.Resolve(command) is not null)
Expand Down
13 changes: 11 additions & 2 deletions src/SharpMUTerm.Tui/SharpMUTermApp.RailKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ internal MenuModel SidebarRowMenu(string rowKey)
var world = model.Worlds.FirstOrDefault(w => RowsOf(w).Contains(rowKey));
var character = world?.Characters.FirstOrDefault(c => c.Windows.Any(w => CommandIds.Window(w.Id) == target)
|| CommandIds.Character(c.SessionKey) == target);
var title = Snippet(row.Label);
// A world's own session (no character) is named by its world, as everywhere else; its row only says what is missing.
var title = Snippet(character is { Alone: true } ? character.Name : row.Label);
switch (row.Kind)
{
case RailRowKind.World:
Expand All @@ -231,7 +232,15 @@ internal MenuModel SidebarRowMenu(string rowKey)
row.Connected ? "world:disconnect" : "world:reconnect");
entries.Add(MenuEntry.Separator);
Offer(entries, $"Edit {Snippet(world?.Name ?? string.Empty)} in F5", "F5", ScreenCommandPrefix + "worlds");
Offer(entries, $"Edit {title} in F9", "F9", ScreenCommandPrefix + "logging");
if (character is { Alone: true })
{
Offer(entries, $"Add a character to {title} in F5", "F5", ScreenCommandPrefix + "worlds");
}
else
{
Offer(entries, $"Edit {title} in F9", "F9", ScreenCommandPrefix + "logging");
}

break;

case RailRowKind.Window:
Expand Down
97 changes: 89 additions & 8 deletions src/SharpMUTerm.Tui/SharpMUTermApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3780,13 +3780,22 @@ private void SwitchToCharacter(string sessionKey)
var session = _sessions.Find(sessionKey);
if (session is null)
{
if (FindCharacter(sessionKey) is not { } found)
if (FindCharacter(sessionKey) is { } found)
{
session = OpenSession(found.World, found.Character);
}

// A world with no character is opened as itself (its session key is its name), the way /connect opened it.
else if (_config.Worlds.FirstOrDefault(w => string.Equals(w.Name, sessionKey, StringComparison.Ordinal)) is { } world)
{
session = OpenSession(world, null);
}
else
{
Notice($"no character called {Snippet(DisplayName(sessionKey))} is configured — F5 adds one");
return;
}

session = OpenSession(found.World, found.Character);
BindSession(session, OpenSessionWindow(session));
}
else
Expand Down Expand Up @@ -8789,6 +8798,26 @@ internal SidebarModel BuildSidebar()
Avatar: _avatars.Get(character.Avatar) ?? worldAvatar));
}

// A world with no character still has a session of its own — /connect host, a link and Browse all make
// one — so it gets a row to open it by, under the world's own name, as every other surface names it.
if (world.Characters.Count == 0)
{
var key = world.Name;
var active = key == activeKey;
var windows = active ? BuildRailWindows(key, chords) : Array.Empty<RailWindow>();
characters.Add(new RailCharacter(
world.Name,
key,
Connected: connected.Contains(key),
Active: active,
Unread: windows.Sum(w => w.Unread),
windows,
Chord: characterChords.GetValueOrDefault(key),
InGroup: _sendGroup.Contains(key),
Avatar: worldAvatar,
Alone: true));
}

worlds.Add(new RailWorld(world.Name, world.Host, world.Port, accent, characters, worldAvatar));
index++;
}
Expand Down Expand Up @@ -9069,6 +9098,18 @@ private IReadOnlyList<CharacterRef> BuildCharacterRefs()
Open: _sessions.Find(key) is not null,
InGroup: _sendGroup.Contains(key)));
}

// A world with no character is reached as itself: its session key is its name.
if (world.Characters.Count == 0)
{
refs.Add(new CharacterRef(
world.Name,
string.Empty,
world.Name,
Connected: connected.Contains(world.Name),
Open: _sessions.Find(world.Name) is not null,
InGroup: _sendGroup.Contains(world.Name)));
}
}

return refs;
Expand Down Expand Up @@ -12535,7 +12576,7 @@ private void ConsumePrefixKey(ConsoleKeyInfo key)
private PrefixFacts PrefixFactsNow() => new(
_workspace.Layout.Panes.Count,
_workspace.Layout.FocusedPane.Tabs.Count,
ActiveWindowId() == MainWindowId,
!CanClose(ActiveWindowId()),
_workspace.Layout.ZoomedPaneId is not null,
_railCollapsed,
_second.Visible);
Expand Down Expand Up @@ -14016,9 +14057,32 @@ private bool CanCloseTab(string windowId, string? activeTab) =>
/// Whether a window may be closed: any but the main window, and the main window too once the character
/// it belongs to has been deleted. The main window is the session, so it stays while the session has a
/// character; with the character gone nothing else reaches it (the rail and ⌃P list configured
/// characters only), and refusing left a pane the player could not get rid of.
/// characters only), and refusing left a pane the player could not get rid of. A world connected with no
/// character (<c>/connect host</c>, a link, Browse) is not a character's either: its window closes, and the
/// session with it (<see cref="WorldAloneOwns"/>).
/// </summary>
private bool CanClose(string windowId) =>
windowId != MainWindowId || OwnerWasDeleted(windowId) || WorldAloneOwns(windowId);

/// <summary>
/// Whether <paramref name="windowId"/> is the own window of a world's session with no character, or a window a
/// resumed workspace recorded for one. Such a session is reached again from the world's <c>no character</c> row
/// in the sidebar or ⌃P, so closing its window ends it rather than leaving it connected out of sight.
/// </summary>
private bool CanClose(string windowId) => windowId != MainWindowId || OwnerWasDeleted(windowId);
private bool WorldAloneOwns(string windowId)
{
if (SessionFor(windowId) is { } session)
{
return session.Character is null
&& _sessionWindows.TryGetValue(session, out var own)
&& string.Equals(own, windowId, StringComparison.Ordinal);
}

return _workspace.FindWindow(windowId) is { Kind: WindowKind.Main, SessionKey: { Length: > 0 } owner }
&& _sessions.Find(owner) is null
&& FindCharacter(owner) is null
&& _config.Worlds.Any(w => string.Equals(w.Name, owner, StringComparison.Ordinal));
}

/// <summary>
/// Whether the character a window belongs to has been deleted from the configuration. With a session,
Expand Down Expand Up @@ -14105,14 +14169,25 @@ internal bool SimulateTabStripClick(string paneId, int x, int y)
/// </summary>
private void CloseWindow(string id)
{
if (!CanClose(id) || _workspace.FindWindow(id) is not { } closing)
if (_workspace.FindWindow(id) is not { } closing)
{
return;
}

if (!CanClose(id))
{
// Said, not swallowed: ⌃W, ⌃B x and the menu all end here, and a key that does nothing reads as broken.
Notice(FirstFitting(
NoticeRoom(),
$"{Snippet(closing.Title)} is its character's own window and stays open",
"the main window stays open"));
return;
}

// A deleted character's own window: once it is closed nothing can reach the session (no rail row,
// no ⌃P entry), so the session is ended with it rather than left connected out of sight.
var orphan = SessionFor(id) is { } owner && OwnerWasDeleted(id) ? owner : null;
// no ⌃P entry), so the session is ended with it rather than left connected out of sight. A world's
// session with no character is its window, so closing that ends it too.
var orphan = SessionFor(id) is { } owner && (OwnerWasDeleted(id) || WorldAloneOwns(id)) ? owner : null;

// A layout panel the player closes stays closed: recorded on its character, so no connect, re-fold or later
// launch puts it back until they ask for it (ClosedPanelsOf).
Expand Down Expand Up @@ -14141,6 +14216,12 @@ private void CloseWindow(string id)

if (orphan is not null)
{
if (orphan.Character is null && orphan.IsConnected)
{
Notice(FirstFitting(NoticeRoom(), $"closed {Snippet(orphan.World.Name)} and disconnected", "closed and disconnected"),
MessageSeverity.Info);
}

EndDeletedSession(orphan);
}

Expand Down
17 changes: 8 additions & 9 deletions tests/SharpMUTerm.Tui.Tests/RailClickTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,22 +246,21 @@ await Assert.That(app.DispatchRailTarget(target))
}

/// <summary>
/// A world with no characters already prints "no characters"; clicking it has to say so rather than
/// look broken. It reports through the transient status mechanism, so it is visible with nothing
/// connected, clears itself, and stays findable in the ⌃P message log.
/// A world with no character still has a session of its own (<c>/connect host</c> makes one), so its row opens
/// it, keyed by the world's name. It used to say "no characters yet", which left a world connected that way
/// with no way back to it.
/// </summary>
[Test]
public async Task ClickingAWorldWithNoCharacters_SaysSo()
public async Task ClickingAWorldWithNoCharacters_OpensTheWorldItself()
{
var app = App(WithAnEmptyWorld());
app.RenderSnapshot();
var before = app.ActiveSessionKey;

ClickRailRow(app, "no characters");
ClickRailRow(app, "no character");

await Assert.That(app.ActiveSessionKey).IsEqualTo(before); // nothing to switch to, nothing switched
await Assert.That(app.StatusMarkup).Contains("Hollow has no characters yet");
await Assert.That(app.Messages.Entries.Any(m => m.Text.Contains("Hollow has no characters"))).IsTrue();
await Assert.That(app.ActiveSessionKey).IsEqualTo("Hollow");
await Assert.That(app.FindSession("Hollow")).IsNotNull();
await Assert.That(app.StatusMarkup).Contains("switched to Hollow");
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions tests/SharpMUTerm.Tui.Tests/WorldBrowseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ await Assert.That(string.Join(' ', list.Select(r => r.Replace('│', ' ').Trim()
await Frame("form", "⏎ connect", "Esc back");
run.App.SimulateWelcomeKey(Key(ConsoleKey.Enter, '\r'));
await run.App.LastCommand;

// The world was added with no character, so connecting gives the sidebar its "no character" row and the pane
// narrows by that much. The tour row is re-laddered to the new width as that frame paints and shows on the next,
// which a terminal draws 16 ms later; a test reading one frame drives that one on.
run.App.RenderNextFrame();
await Frame("connected", SharpMUTermApp.KeyTourLead, "⌃P", "Key tour");
}
}
Loading
Loading