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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`]

## [Unreleased]

### Added

- The docked composer's heading has a close button (`×`), in the terminal and the window. A composer in a pane of its
own, as the Roleplay layout puts it, had no tab to close it by. The draft is kept, and *Dock the composer* brings it
back.

### Fixed

- Esc in the docked composer goes back to the tab you came from. It used to leave the keyboard on the composer's own
pane, so the command line was your character's main window's even when you had been reading Chat.
- Closing the docked composer (Ctrl+W or the new button) puts the keyboard focus straight back on the command line, so
a paste lands there.

- A character whose name has a space, connected as `"first last"` on a MUSH, gets a session log again. The quotes
went into the log's file name, which Windows refuses, so no log was written. World and character names are now made
safe for Windows, Linux and macOS before they name a file: quotes and control characters are dropped, `< > : / \ | ? *`
Expand Down
12 changes: 9 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1653,13 +1653,19 @@ fallbacks) for inline images/maps.
not been released (`_composerReleased`). While armed, `PinFocusToArmedBar` pins the framework's focus to the
*editor* instead of the bar — so typing, paste and the caret all land there by the pin's existing rule — and
both command lines wear the idle band. `HandleWindowKey` hands an armed composer's keys to
`HandleComposerKey` (macros, resize, ⌃C/⌃X, ⌃S, ⌥L, Esc, the ⌃arrows, else the editor). **Esc releases** (the
bar arms and ⏎ sends from it, to the same character); the ⌃↑/⌃↓ ladder releases too; **arriving** at the
`HandleComposerKey` (macros, resize, ⌃C/⌃X, ⌃S, ⌥L, Esc, the ⌃arrows, else the editor). **Esc releases and goes
back** (`LeaveComposer`, both hosts): the window in front before the composer took the keyboard (`_windowBeforeComposer`,
say Chat) is activated, so the bar arms there and ⏎ sends from *that* window's command line; leaving the focus on the
composer's pane gave the main window's bar, which read as "Esc goes to the first tab". The ⌃↑/⌃↓ ladder releases too; **arriving** at the
composer's pane (⌃O, ⌃arrows, a tab, a click in the editor — `ArmClickedComposer` on `FocusChanged`, guarded by
`_pinningFocus` so the pin's own focus moves never count) arms it again. `ArmBar` does **not** release: it is
re-asserted on every layout change, and releasing there disarmed the composer the moment its pane was built.
⌥⏎ arrives as Esc then Enter, so an Enter within 50 ms of the releasing Esc re-arms and inserts a newline
(`TryComposerAltEnter`). `DockedComposerTests` covers each of these.
(`TryComposerAltEnter`, which activates the composer's window again first). `DockedComposerTests` covers each of these.
- **A lone composer pane draws no tab strip, so its heading carries a close** (`DockedComposer.CloseLink`, a `×` link only
its header answers, the last cell but one of the band; the window's `ComposerView` close button →
`ComposerSession.ClosePanel`). Both end in `CloseDockedComposer` → `CloseWindow`, which records the panel closed and keeps
the draft; closing any composer window re-pins the focus to the command line (it was left on the gone editor).
- **The window can pop a native panel out into a window of its own** (map, vitals, who-here, quick bar;
`SharpMUTermApp.Floating.cs`, Avalonia `FloatingPanels.cs`: `FloatingPanelPresenter`, `FloatingPanelWindow`,
`PopOutButton`; Core `FloatingBounds`; Client `PanelFloatCommands`, `FloatingPanelModel`; ⌃P `panel:popout:<window>`
Expand Down
54 changes: 51 additions & 3 deletions src/SharpMUTerm.Avalonia/ComposerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public IEnumerable<EdgeRule> EdgeRules(Size size)
private readonly FittedText _summary = new() { VerticalAlignment = VerticalAlignment.Center };
private readonly Border _previewButton;
private readonly Border _sendButton;

// The docked heading's ×: closes the composer's pane (ComposerSession.ClosePanel), which draws no tab strip of its own.
private readonly Border _closeButton;
private ComposerSession? _session;
private ComposerModel? _model;
private long _applied = -1;
Expand Down Expand Up @@ -164,17 +167,21 @@ public ComposerView(TerminalView view, bool fullScreen)
_target = new TextBlock { VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
_chips = new StackPanel { Orientation = Orientation.Horizontal, Spacing = NativeTokens.Space6, VerticalAlignment = VerticalAlignment.Center };
_count = new TextBlock { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(NativeTokens.Space10, 0, 0, 0) };
_closeButton = CloseButton(() => _session?.ClosePanel());
_closeButton.IsVisible = !fullScreen;
var headerRow = new DockPanel { LastChildFill = true };
DockPanel.SetDock(_title, Dock.Left);
DockPanel.SetDock(_closeButton, Dock.Right);
DockPanel.SetDock(_count, Dock.Right);
DockPanel.SetDock(_chips, Dock.Right);
headerRow.Children.Add(_title);
headerRow.Children.Add(_closeButton);
headerRow.Children.Add(_count);
headerRow.Children.Add(_chips);
headerRow.Children.Add(_target);
// The docked panel's heading is every panel's (PanelText.Heading): 16 px in, a rule under it, the pop-out button
// clear at the right.
_header = new Border { Child = headerRow, Padding = fullScreen ? new Thickness(NativeTokens.Space24, NativeTokens.Space10) : new Thickness(PanelText.Pad, 0, NativeTokens.Space32, 0) };
// The docked panel's heading is every panel's (PanelText.Heading): 16 px in, a rule under it, the close button at
// the right (the composer never pops out, so no pop-out button needs the corner).
_header = new Border { Child = headerRow, Padding = fullScreen ? new Thickness(NativeTokens.Space24, NativeTokens.Space10) : new Thickness(PanelText.Pad, 0, NativeTokens.Space8, 0) };
if (!fullScreen)
{
// Every panel's heading height, so the composer's rule meets the one beside it (who is here, the map).
Expand Down Expand Up @@ -515,6 +522,11 @@ private void Paint()
_title.Foreground = new SolidColorBrush(_text);
_target.Foreground = new SolidColorBrush(Dim);
_count.Foreground = new SolidColorBrush(Dim);
if (_closeButton.Child is TextBlock cross)
{
cross.Foreground = new SolidColorBrush(Dim);
}

_preview.Background = new SolidColorBrush(Band);
_preview.BorderBrush = _header.BorderBrush;
_preview.BorderThickness = new Thickness(0, NativeTokens.Hairline, 0, 0);
Expand Down Expand Up @@ -1193,6 +1205,42 @@ private static Border ActionButton(string words, string tip, Action click)
return button;
}

/// <summary>The docked heading's ×: a quiet square that takes a plate under the pointer, as a tab's × does.</summary>
private Border CloseButton(Action click)
{
var button = new Border
{
Child = new TextBlock { Text = "×", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
Width = NativeTokens.ControlHeightSmall,
Height = NativeTokens.ControlHeightSmall,
Margin = new Thickness(NativeTokens.Space8, 0, 0, 0),
CornerRadius = new CornerRadius(NativeTokens.RadiusControl),
Background = Brushes.Transparent,
Cursor = new Cursor(StandardCursorType.Hand),
VerticalAlignment = VerticalAlignment.Center,
};
button.Name = "Close composer";
ToolTip.SetTip(button, "Close the composer (Ctrl+W). The draft is kept.");
AutomationProperties.SetName(button, "Close composer");
button.PointerEntered += (_, _) => button.Background = new SolidColorBrush(Mix(_plane, _text, 0.1));
button.PointerExited += (_, _) => button.Background = Brushes.Transparent;
button.PointerPressed += (_, e) =>
{
if (e.GetCurrentPoint(button).Properties.IsLeftButtonPressed)
{
e.Handled = true;
click();
}
};
return button;
}

/// <summary>Presses the docked heading's close button, as a click on it does. Internal for tests.</summary>
internal void PressClose() => _session?.ClosePanel();

/// <summary>Whether the docked heading shows its close button. Internal for tests.</summary>
internal bool ShowsClose => _closeButton.IsVisible;

private void PaintButton(Border button, bool accent)
{
button.Background = new SolidColorBrush(accent ? Accent : Mix(_plane, _text, 0.07));
Expand Down
12 changes: 12 additions & 0 deletions src/SharpMUTerm.Client/Composer/ComposerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public sealed record ComposerCallbacks
/// <summary>A click in a docked composer: it takes the keyboard.</summary>
public Action? Arm { get; init; }

/// <summary>The docked composer's close button: its pane closes, the draft kept for the next one.</summary>
public Action? ClosePanel { get; init; }

/// <summary>Esc (or F1) in F1: the window closes, with the buffer to keep.</summary>
public Action<string>? Closed { get; init; }

Expand Down Expand Up @@ -198,6 +201,15 @@ public void Arm()
}
}

/// <summary>The host's: the docked composer's close button.</summary>
public void ClosePanel()
{
if (!IsEnded)
{
_callbacks.ClosePanel?.Invoke();
}
}

/// <summary>Whether this composer's character writes in a proportional face; false (monospace) with nobody to ask.</summary>
public bool Proportional => _callbacks.Proportional?.Invoke() ?? false;

Expand Down
6 changes: 5 additions & 1 deletion src/SharpMUTerm.Client/Surfaces/SurfaceCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,11 @@ [.. PanelViews("MapCanvas"), "SharpMUTerm.Avalonia.MapInspector"]),
typeof(ComposerModel),
[
new(SurfaceActionKind.Compose, "send", "SendDocked"),
new(SurfaceActionKind.Compose, "release", "ReleaseComposer"),
// Esc: the keyboard goes back to the window in front before the composer took it.
new(SurfaceActionKind.Compose, "release", "LeaveComposer"),

// The heading's × (a link in the cells, a button in the window): the composer's window closes.
new(SurfaceActionKind.Compose, "close", "CloseDockedComposer"),

// A click on the cell editor arms it through the framework's focus (ArmClickedComposer); the native
// editor asks for the same thing by name.
Expand Down
28 changes: 26 additions & 2 deletions src/SharpMUTerm.Tui/Panels/DockedComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ internal DockedComposer(string windowId, string sessionKey, ScreenTheme scheme,
};

_header = new MarkupControl(new List<string>()) { HorizontalAlignment = HorizontalAlignment.Stretch };

// The heading's × is the panel's own link, answered here and never by the output panes' handler: a pane holding
// the composer alone draws no tab strip, so without it the pane could be closed only by ⌃W from inside it.
_header.LinkClicked += (_, e) => OnHeaderLink(e.Url);
_footer = new MarkupControl(new List<string>()) { HorizontalAlignment = HorizontalAlignment.Stretch };

var grid = Controls.Grid()
Expand Down Expand Up @@ -255,6 +259,24 @@ internal void SetCommandFromHost(string command)
/// <summary>Raised after the buffer or the mode changed by the writer's hand (never by <see cref="Load"/>).</summary>
internal event EventHandler? Changed;

/// <summary>Raised when the heading's <c>×</c> is clicked: the host closes the composer's window.</summary>
internal event EventHandler? CloseRequested;

/// <summary>The heading's close link, a payload only this composer's header answers.</summary>
internal const string CloseLink = "mux:composer:close";

/// <summary>A link clicked in the heading: only the close link means anything.</summary>
private void OnHeaderLink(string url)
{
if (string.Equals(url, CloseLink, StringComparison.Ordinal))
{
CloseRequested?.Invoke(this, EventArgs.Empty);
}
}

/// <summary>A click on a link in the heading, as the header control raises it. Internal for tests.</summary>
internal void SimulateHeaderLink(string url) => OnHeaderLink(url);

/// <summary>The header row's markup, for the tests.</summary>
internal string HeaderMarkup => _header.Text;

Expand Down Expand Up @@ -336,7 +358,8 @@ internal void Render(ComposerModel model)
var rest = (verb.Length > 0 ? $" {Escape(verb)}" : string.Empty) + $" {bandMode}";
var lead = model.Armed ? $"[{band.Accent}]▌[/]" : null;
var chars = ComposerModel.CharactersLabel(model.Characters);
_header.SetContent(new List<string> { HeadingBand.Row("COMPOSE", rest, chars, _width > 0 ? _width : VisibleLength(rest) + 9, band, lead) });
var close = $"[link={CloseLink}]×[/]";
_header.SetContent(new List<string> { HeadingBand.Row("COMPOSE", rest, chars, _width > 0 ? _width : VisibleLength(rest) + 11, band, lead, close) });
RenderFooter(model);
return;
}
Expand All @@ -347,11 +370,12 @@ internal void Render(ComposerModel model)

// The length cell at the right edge, as F1 has it; the title gives way first, and a pane too narrow for both
// keeps the title.
var length = $"[dim]{ComposerModel.CharactersLabel(model.Characters)}[/] ";
var length = $"[dim]{ComposerModel.CharactersLabel(model.Characters)}[/] [link={CloseLink}]×[/] ";
_header.SetContent(new List<string>
{
_width <= 0 ? $"{title} {length}"
: _width >= VisibleLength(title) + VisibleLength(length) + 2 ? SpreadLR(title, length, _width)
: _width >= 6 ? ElideVisible(title, _width - 3) + $" [link={CloseLink}]×[/] "
: ElideVisible(title, _width),
});

Expand Down
13 changes: 12 additions & 1 deletion src/SharpMUTerm.Tui/Panels/HeadingBand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,21 @@ internal static Ink For(Theme theme, string accent)
/// the right part goes first, then the rest is elided. Never wider than <paramref name="width"/>. The first cell is
/// the band's margin, or <paramref name="lead"/> (one cell of markup: the docked composer's armed <c>▌</c>) in it.
/// </summary>
internal static string Row(string label, string rest, string right, int width, Ink ink, string? lead = null)
/// <param name="close">
/// One cell of markup kept at the far end whatever else gives way, before the last margin cell: the docked composer's
/// <c>×</c>. Null for none.
/// </param>
internal static string Row(string label, string rest, string right, int width, Ink ink, string? lead = null, string? close = null)
{
width = Math.Max(1, width);
var left = $"[bold]{label}[/]{rest}";
if (close is not null && width >= 5)
{
// The rest of the row is laid out two cells narrower, and the button and the margin take those two.
var row = Row(label, rest, right, width - 2, ink, lead);
return row[..^" [/]".Length] + $" {close} [/]";
}

var inner = Math.Max(1, width - 2);
var body = right.Length > 0 && VisibleLength(left) + VisibleLength(right) + 2 <= inner
? SpreadLR(left, right, inner)
Expand Down
3 changes: 2 additions & 1 deletion src/SharpMUTerm.Tui/SharpMUTermApp.NativeComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ private ComposerSession DockedSessionFor(DockedComposer composer)
{
if (ReferenceEquals(ArmedComposer(), composer))
{
ReleaseComposer();
LeaveComposer();
}
}),
Arm = () => OnUiThread(() => ArmComposer(composer)),
ClosePanel = () => OnUiThread(() => CloseDockedComposer(composer)),
Proportional = ComposerFaceOf(composer.SessionKey),
ChooseFace = ChooseComposerFace(composer.SessionKey),
});
Expand Down
Loading
Loading