diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c2439b..fc223c4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`] ## [Unreleased] +### Added + +- In the window, Ctrl+1 to Ctrl+9 and Ctrl+0 go straight to the main window of the first ten characters you have open, + in the order the sidebar lists them; the sidebar, the character menu and Ctrl+P show each character's key. A key with + no character behind it says so and opens nothing. Terminals cannot send Ctrl with a digit (Ctrl+3 arrives as Escape, + Ctrl+8 as Backspace), so there Alt+J and Alt+K still move between characters, and Alt+1 to Alt+9 still go to the + character's own windows. + +### Changed + +- In the window, the zoom reset is Ctrl+Numpad 0 (and the output's right-click menu and Ctrl+P), since Ctrl+0 now goes + to the tenth character. + ## [0.3.9] - 2026-11-24 ### Changed diff --git a/CLAUDE.md b/CLAUDE.md index 09a0f976..fffbf8e4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -3073,7 +3073,16 @@ markup (`[bold #rrggbb on #rrggbb]…[/]`, `[[`/`]]` escaping, `[link=url]…[/] took a four-window fixture to expose: with fewer, both orders agree). Only **placed** windows are numbered — one no pane holds is drawn `closed` and a digit for it would name nowhere to go — and never a layout panel (`WindowKind.Panel`), which is furniture and has no rail row. - - **⌃B 1–⌃B 9 go to a pane.** It was ⌥N until windows took that; it is on the prefix because that is + - **⌃1–⌃9 and ⌃0 go to the first ten open characters' main windows, and only in a host that reports Ctrl+digit whole** + (`SharpMUTermApp.CharacterJumps.cs`, `MacroKeys.CharacterJumpNumber`, `CommandIds.CharacterJumpDigits`; + `HostKeys.ReportsChordsWhole`, so the window). Asked for by players. Same order as the cycle + (`CommandCatalog.CharacterCycle`, open characters only, so a digit never dials). **Not in `MacroKeys.AppShortcuts`**: + that list is every host's, and a terminal writes these as a bare digit or another key's byte (`DigitBytes`), so + `Verdict` reports them taken only where they arrive; registered by `RegisterCharacterJumps`. Where they exist the + sidebar's character rows, the character menu and ⌃P's *Switch to* entries carry `⌃N` instead of ⌥J/⌥K + (`CommandContext.CharacterJumps`). **⌃0 is the tenth character, so the window's zoom reset is ⌃Numpad 0**, the + right-click menu and ⌃P (`WindowHost.Zoom`). The terminal has no digit chord for characters: ⌥J/⌥K and ⌃P. +- **⌃B 1–⌃B 9 go to a pane.** It was ⌥N until windows took that; it is on the prefix because that is where the rest of the pane keymap lives, and it is kept rather than dropped because the pane numbering does not go away with the chord — move mode badges each pane with it, the move and drag prompts say `pane 2`, the ⌃P entry says `Go to pane 2`, and ⌃O counts in it. It also refuses on a diff --git a/src/SharpMUTerm.Avalonia/TerminalView.cs b/src/SharpMUTerm.Avalonia/TerminalView.cs index a7307cdc..78f0d3fb 100644 --- a/src/SharpMUTerm.Avalonia/TerminalView.cs +++ b/src/SharpMUTerm.Avalonia/TerminalView.cs @@ -115,7 +115,7 @@ internal IReadOnlyList ZoomItems [ new($"Zoom in ({SharpMUTerm.Core.Configuration.ZoomLevels.Label(SharpMUTerm.Core.Configuration.ZoomLevels.Next(zoom))})", "Ctrl+=", () => RequestZoom(1), zoom < SharpMUTerm.Core.Configuration.ZoomLevels.Maximum), new($"Zoom out ({SharpMUTerm.Core.Configuration.ZoomLevels.Label(SharpMUTerm.Core.Configuration.ZoomLevels.Previous(zoom))})", "Ctrl+-", () => RequestZoom(-1), zoom > SharpMUTerm.Core.Configuration.ZoomLevels.Minimum), - new($"Reset zoom ({SharpMUTerm.Core.Configuration.ZoomLevels.Label(zoom)})", "Ctrl+0", () => RequestZoom(0), zoom != 100), + new($"Reset zoom ({SharpMUTerm.Core.Configuration.ZoomLevels.Label(zoom)})", "Ctrl+Num 0", () => RequestZoom(0), zoom != 100), ]; } } @@ -511,7 +511,7 @@ internal void AttachZoomKeys(InputElement root) (Key.OemPlus, KeyModifiers.Control or (KeyModifiers.Control | KeyModifiers.Shift)) => 1, (Key.Add, KeyModifiers.Control) => 1, (Key.OemMinus or Key.Subtract, KeyModifiers.Control) => -1, - (Key.D0 or Key.NumPad0, KeyModifiers.Control) => 0, + (Key.NumPad0, KeyModifiers.Control) => 0, // Ctrl+0 is the tenth character (WindowHost.Zoom) _ => null, }; @@ -550,7 +550,7 @@ internal void HandleKeyDown(KeyEventArgs e) RequestZoom(zoom); _swallowText = e.Key switch { - Key.D0 or Key.NumPad0 => '0', + Key.NumPad0 => '0', Key.OemMinus or Key.Subtract => '-', Key.Add => '+', _ => e.KeyModifiers.HasFlag(KeyModifiers.Shift) ? '+' : '=', @@ -588,7 +588,9 @@ internal void HandleKeyDown(KeyEventArgs e) { // An Alt chord can be followed by a TextInput for the same letter on some platforms. // So is a numpad digit, which KeyMapper has already sent with its digit. + // A Ctrl+digit (⌃1–⌃0, the character chords) can be followed by a TextInput for the digit as well. _swallowText = (key.Modifiers.HasFlag(ConsoleModifiers.Alt) && !key.Modifiers.HasFlag(ConsoleModifiers.Control)) + || (key.Modifiers == ConsoleModifiers.Control && key.Key is >= ConsoleKey.D0 and <= ConsoleKey.D9) || key.Key is >= ConsoleKey.NumPad0 and <= ConsoleKey.NumPad9 ? key.KeyChar : null; diff --git a/src/SharpMUTerm.Avalonia/WindowHost.cs b/src/SharpMUTerm.Avalonia/WindowHost.cs index cf38ecad..01863282 100644 --- a/src/SharpMUTerm.Avalonia/WindowHost.cs +++ b/src/SharpMUTerm.Avalonia/WindowHost.cs @@ -22,6 +22,10 @@ internal static class WindowHost public static ReservedChord WindowedFullScreen { get; } = new( new HostChord(ConsoleKey.F11, ConsoleModifiers.Shift, "Shift+F11", "Shift+F11"), "goes in and out of windowed full screen"); + /// + /// The window's zoom chords. Ctrl+0 is not one of them: ⌃1–⌃9 and ⌃0 go to the open characters + /// (SharpMUTermApp.JumpToCharacter), so the reset is Ctrl+Numpad 0, the output's right-click menu and ⌃P. + /// public static IReadOnlyList Zoom { get; } = [ new(new HostChord(ConsoleKey.OemPlus, ConsoleModifiers.Control, "Ctrl+=", "Ctrl+="), "zooms in"), @@ -29,7 +33,6 @@ internal static class WindowHost new(new HostChord(ConsoleKey.Add, ConsoleModifiers.Control, "Ctrl+Add", "Ctrl+Add"), "zooms in"), new(new HostChord(ConsoleKey.OemMinus, ConsoleModifiers.Control, "Ctrl+-", "Ctrl+-"), "zooms out"), new(new HostChord(ConsoleKey.Subtract, ConsoleModifiers.Control, "Ctrl+Subtract", "Ctrl+Subtract"), "zooms out"), - new(new HostChord(ConsoleKey.D0, ConsoleModifiers.Control, "Ctrl+0", "Ctrl+0"), "resets terminal zoom"), new(new HostChord(ConsoleKey.NumPad0, ConsoleModifiers.Control, "Ctrl+NumPad0", "Ctrl+NumPad0"), "resets terminal zoom"), ]; diff --git a/src/SharpMUTerm.Client/Commands/BuiltInCommands.cs b/src/SharpMUTerm.Client/Commands/BuiltInCommands.cs index a1e4a86e..19704ff8 100644 --- a/src/SharpMUTerm.Client/Commands/BuiltInCommands.cs +++ b/src/SharpMUTerm.Client/Commands/BuiltInCommands.cs @@ -113,7 +113,7 @@ public static class BuiltInCommands /// Zooms the window out a step (Ctrl+- in the window). public const string ZoomOutCommand = "window:zoom-out"; - /// Puts the window's zoom back to 100% (Ctrl+0 in the window). + /// Puts the window's zoom back to 100% (Ctrl+Numpad 0 in the window; Ctrl+0 is the tenth character). public const string ZoomResetCommand = "window:zoom-reset"; /// Opens the Text size & zoom page (the window only). @@ -297,7 +297,7 @@ void Family(string id, string prefix, Func c.State.TextZoom is { } zoom && zoom > Core.Configuration.ZoomLevels.Minimum, titleFor: c => "Zoom out to " + Core.Configuration.ZoomLevels.Label(Core.Configuration.ZoomLevels.Previous(c.State.TextZoom ?? 100))); - Add(ZoomResetCommand, CommandGroup.Layout, "Reset zoom", "⌃0", "back to 100% · sizes by area are on the Text size page", + Add(ZoomResetCommand, CommandGroup.Layout, "Reset zoom", "⌃Num0", "back to 100% · sizes by area are on the Text size page", when: c => c.State.TextZoom is { } zoom && zoom != 100, titleFor: c => "Reset zoom (" + Core.Configuration.ZoomLevels.Label(c.State.TextZoom ?? 100) + ")"); Add(TextSizeCommand, CommandGroup.Settings, "Text size & zoom…", detail: "font sizes for the output, composer, panels and menus", @@ -470,11 +470,12 @@ public static IReadOnlyList Catalog( new HostKeyGlyphs(context.NewlineChord))); } - // The two neighbours in the character cycle carry its chords. Only those two: ⌥J and ⌥K move one - // step, so they are the honest answer for the rows either side of you and a lie for anybody - // further away. There is deliberately no direct-selection chord to put on the rest — the digit - // row is spent on windows and panes, and every remaining digit-bearing modifier (⌥⇧, ⌃⇧) has no - // legacy encoding at all on this terminal, which was measured rather than assumed. + // In a terminal the two neighbours in the character cycle carry its chords. Only those two: ⌥J and ⌥K + // move one step, so they are the honest answer for the rows either side of you and a lie for anybody + // further away. A terminal has no direct-selection chord to put on the rest — the digit row is spent on + // windows and panes, and every remaining digit-bearing modifier (⌃, ⌥⇧, ⌃⇧) has no legacy encoding there, + // which was measured rather than assumed. A host that reports Ctrl+digit whole (the window) has one: + // ⌃1–⌃9 and ⌃0 name the first ten open characters, in the cycle's order, and every such row carries its own. private static IEnumerable Characters(ICommandContext context) { var characters = context.Characters; @@ -486,6 +487,7 @@ private static IEnumerable Characters(ICommandContext context) ? cycle[(here - 1 + cycle.Count) % cycle.Count].SessionKey : null; + var jumps = context.State.CharacterJumps; foreach (var character in characters) { if (character.SessionKey == focusedSessionKey) @@ -494,7 +496,10 @@ private static IEnumerable Characters(ICommandContext context) } var state = character.Connected ? "connected" : "offline"; - var chord = character.SessionKey == next ? "⌥J · " + var number = cycle.FindIndex(c => c.SessionKey == character.SessionKey) + 1; + var chord = jumps + ? number is > 0 and <= CommandIds.CharacterJumpDigits ? CommandIds.CharacterJumpChord(number) + " · " : string.Empty + : character.SessionKey == next ? "⌥J · " : character.SessionKey == previous ? "⌥K · " : string.Empty; yield return new CommandItem( diff --git a/src/SharpMUTerm.Client/Help/HelpTopics.cs b/src/SharpMUTerm.Client/Help/HelpTopics.cs index 21c75081..79432a5f 100644 --- a/src/SharpMUTerm.Client/Help/HelpTopics.cs +++ b/src/SharpMUTerm.Client/Help/HelpTopics.cs @@ -10,8 +10,11 @@ namespace SharpMUTerm.Client.Help; /// public static class HelpTopics { - /// The pages, with (the host's newline chord) where a page names it. - public static IReadOnlyList For(string newline) => + /// + /// The pages, with (the host's newline chord) where a page names it, and the character + /// chords where the host has them (: ⌃1–⌃9 and ⌃0, the window). + /// + public static IReadOnlyList For(string newline, bool characterJumps = false) => [ new("getting-started", "Getting started", "connect to a game, and what the screen is", [ "Connect: type /connect mud.example.org 4000 (add tls for a secure port), or open the welcome", @@ -45,7 +48,7 @@ public static IReadOnlyList For(string newline) => "Copy: drag across output, then ⌃C.", ]), new("text-size", "Text size", "make the text bigger or smaller", [ - "In the window: ⌃= zooms in, ⌃- zooms out and ⌃0 goes back to 100%, as in a browser; so does ⌃ with", + "In the window: ⌃= zooms in, ⌃- zooms out and ⌃ with numpad 0 goes back to 100%; so does ⌃ with", "the wheel, and the output's right-click menu. The zoom covers the whole window and is kept between runs.", "⌃P ▸ Text size & zoom sets the output's size in points, and the composer, the header and sidebar,", "the panels, and menus and dialogs each on their own.", @@ -94,6 +97,7 @@ public static IReadOnlyList For(string newline) => "Windows: ⌥1 to ⌥9 go to a numbered window of the character you are on — the numbers are the ones", "the sidebar prints beside each window.", "Characters: ⌥J and ⌥K move to the next and previous character you have open.", + .. CharacterJumpLines(characterJumps), "Connection: ⌥R reconnects, ⌥D disconnects. Neither asks.", "", "Panes: ⌃B then a key — | split right, - split down, z zoom, o next, 1-9 go to a pane, x close,", @@ -129,4 +133,12 @@ private static IEnumerable MapKeyRows() yield return " " + string.Concat(keys.Skip(i).Take(3).Select(k => (k.Key.PadRight(10) + k.Word).PadRight(26))).TrimEnd(); } } + + /// The keys page's line for ⌃1–⌃0, only where the host delivers them. + private static string[] CharacterJumpLines(bool characterJumps) => characterJumps + ? [ + " ⌃1 to ⌃9 and ⌃0 go straight to the main window of the first ten characters you have open, in", + " the order the sidebar lists them (it prints each one's key).", + ] + : []; } diff --git a/src/SharpMUTerm.Client/Modals/HelpModel.cs b/src/SharpMUTerm.Client/Modals/HelpModel.cs index 97dcd793..d5fb9ea9 100644 --- a/src/SharpMUTerm.Client/Modals/HelpModel.cs +++ b/src/SharpMUTerm.Client/Modals/HelpModel.cs @@ -129,14 +129,16 @@ private bool Mentions(HelpEntry entry, string word) /// The command registry's entries for this host and state. /// The host's newline chord, in glyphs (⌥⏎, ⌃⏎). /// The chords the host keeps for itself, with what each does there. + /// Whether the host has ⌃1–⌃9 and ⌃0 for the open characters (the window). public static HelpModel Build( IReadOnlyList catalog, string newline, - IReadOnlyList<(string Chord, string Action)> hostKeeps) + IReadOnlyList<(string Chord, string Action)> hostKeeps, + bool characterJumps = false) { ArgumentNullException.ThrowIfNull(catalog); ArgumentNullException.ThrowIfNull(hostKeeps); - var topics = HelpTopics.For(KeyGlyphs.Normalize(newline)); + var topics = HelpTopics.For(KeyGlyphs.Normalize(newline), characterJumps); var entries = new List(); entries.AddRange(topics.Select(t => new HelpEntry(HelpKind.Topic, TopicsSection, t.Title, string.Empty, t.Summary, t.Id))); entries.AddRange(SlashCommands.All.Select(c => new HelpEntry(HelpKind.Command, CommandsSection, c.Usage, string.Empty, c.Summary, c.Placed))); diff --git a/src/SharpMUTerm.Client/Settings/BuiltInSettings.TextSize.cs b/src/SharpMUTerm.Client/Settings/BuiltInSettings.TextSize.cs index 721620c2..25d3e497 100644 --- a/src/SharpMUTerm.Client/Settings/BuiltInSettings.TextSize.cs +++ b/src/SharpMUTerm.Client/Settings/BuiltInSettings.TextSize.cs @@ -21,7 +21,7 @@ public static partial class BuiltInSettings public static IReadOnlyList AreaChoices { get; } = [.. ZoomLevels.AreaSteps.Select(ZoomLevels.Label)]; /// - /// The desktop window's text sizes: a zoom over the whole window (Ctrl+= / Ctrl+- / Ctrl+0, Ctrl+wheel), the + /// The desktop window's text sizes: a zoom over the whole window (Ctrl+= / Ctrl+- / Ctrl+Numpad 0, Ctrl+wheel), the /// output's size in points, and the composer, interface, panels and dialogs each as a percentage. Not in /// and on no F-key, like : a host registers it only when it draws its own text /// (the window), so a terminal, whose font size is its emulator's, never lists a choice that does nothing there. @@ -34,7 +34,7 @@ public static partial class BuiltInSettings Fields = [ new ChoiceField("zoom", "zoom", ZoomChoices, - "everything in the window, as a browser zooms; Ctrl+= and Ctrl+- step it, Ctrl+0 resets, Ctrl+wheel too") + "everything in the window, as a browser zooms; Ctrl+= and Ctrl+- step it, Ctrl+Numpad 0 resets, Ctrl+wheel too") { Group = ZoomGroup, Keywords = "zoom scale magnify bigger smaller font size text size accessibility dpi", diff --git a/src/SharpMUTerm.Core/Commands/CommandCatalog.cs b/src/SharpMUTerm.Core/Commands/CommandCatalog.cs index 11a5d5c8..fc90e550 100644 --- a/src/SharpMUTerm.Core/Commands/CommandCatalog.cs +++ b/src/SharpMUTerm.Core/Commands/CommandCatalog.cs @@ -83,6 +83,10 @@ public sealed record CharacterRef( /// /// Where this copy's update stands; null in a host that cannot update itself. /// Whether the host has the Text size & zoom page (the window, not --emulated). +/// +/// Whether the host delivers Ctrl+digit as itself, so ⌃1–⌃9 and ⌃0 go to the open characters in the cycle's order (the +/// window). False in a terminal, where those chords are bytes other keys own. +/// /// /// The desktop window's zoom, a percentage, so ⌃P offers zooming in, out and back; null in a host that draws no text of /// its own (the terminal, whose font size is its emulator's). @@ -119,7 +123,8 @@ public sealed record CommandContext( Configuration.WindowMode? WindowMode = null, UpdateState? Update = null, int? TextZoom = null, - bool TextSizePage = false); + bool TextSizePage = false, + bool CharacterJumps = false); /// /// Where this copy's update stands, for ⌃P's update entries: null when the host cannot update itself at all (a build diff --git a/src/SharpMUTerm.Core/Commands/CommandIds.cs b/src/SharpMUTerm.Core/Commands/CommandIds.cs index c4378852..5dabb387 100644 --- a/src/SharpMUTerm.Core/Commands/CommandIds.cs +++ b/src/SharpMUTerm.Core/Commands/CommandIds.cs @@ -57,6 +57,16 @@ public static class CommandIds /// public const int WindowJumpDigits = 9; + /// + /// How many open characters have a chord of their own where the host delivers Ctrl+digit as itself (the window): + /// ⌃1–⌃9 and ⌃0 for the tenth, counting . A terminal writes Ctrl+digit + /// as a bare digit or a byte another key already owns, so there the cycle (⌥J/⌥K) and ⌃P are the way. + /// + public const int CharacterJumpDigits = 10; + + /// The chord, in glyphs, that goes to open character (1-based): ⌃1…⌃9, ⌃0. + public static string CharacterJumpChord(int number) => number == 10 ? "⌃0" : "⌃" + number; + /// Prefix of a "go to this numbered pane" id; the remainder is the pane's 1-based number. public const string PanePrefix = "layout:pane-"; diff --git a/src/SharpMUTerm.Core/Configuration/AppConfiguration.cs b/src/SharpMUTerm.Core/Configuration/AppConfiguration.cs index 47beb76b..2954f9d5 100644 --- a/src/SharpMUTerm.Core/Configuration/AppConfiguration.cs +++ b/src/SharpMUTerm.Core/Configuration/AppConfiguration.cs @@ -157,7 +157,7 @@ public sealed class AppConfiguration public WindowPlacement? Window { get; set; } /// - /// The desktop window's text sizes and zoom (the Text size settings page, Ctrl+= / Ctrl+- / Ctrl+0). Read by the + /// The desktop window's text sizes and zoom (the Text size settings page, Ctrl+= / Ctrl+- / Ctrl+Numpad 0). Read by the /// window alone; a terminal's font size is its emulator's. /// public DisplaySettings Display { get; set; } = new(); diff --git a/src/SharpMUTerm.Core/Configuration/DisplaySettings.cs b/src/SharpMUTerm.Core/Configuration/DisplaySettings.cs index 3502033d..02ac8a48 100644 --- a/src/SharpMUTerm.Core/Configuration/DisplaySettings.cs +++ b/src/SharpMUTerm.Core/Configuration/DisplaySettings.cs @@ -8,7 +8,7 @@ namespace SharpMUTerm.Core.Configuration; /// The output is in points, because a monospace console's size is a font size (Mudlet, Windows Terminal and kitty all /// say it that way). Every other area is a percentage of its designed size, because each is a ramp of sizes (a heading, /// a label, a caption) that has to move together. multiplies all of them, the way a browser's does, -/// and is what Ctrl+= / Ctrl+- / Ctrl+0 and Ctrl+wheel change. +/// and is what Ctrl+= / Ctrl+- / Ctrl+Numpad 0 and Ctrl+wheel change. /// /// public sealed class DisplaySettings diff --git a/src/SharpMUTerm.Tui/ClientUsage.cs b/src/SharpMUTerm.Tui/ClientUsage.cs index bcff1361..0b6c102f 100644 --- a/src/SharpMUTerm.Tui/ClientUsage.cs +++ b/src/SharpMUTerm.Tui/ClientUsage.cs @@ -234,6 +234,13 @@ public static void Write(TextWriter usage, UsageLauncher launcher, HostKeys keys usage.WriteLine(" Alt+J and Alt+K move to the next and previous character you have open — the two the"); usage.WriteLine(" sidebar marks '⌥J' and '⌥K'. They never open one that is not; the sidebar and"); usage.WriteLine(" Ctrl+P do that."); + if (keys.ReportsChordsWhole) + { + // Only where Ctrl+digit arrives as itself (the window); a terminal sends those as other keys' bytes. + usage.WriteLine(" Ctrl+1 to Ctrl+9 and Ctrl+0 go to the main window of the first ten characters you"); + usage.WriteLine(" have open, in the order the sidebar lists them."); + } + usage.WriteLine("Panes: Ctrl+B then | - z o 1-9 x b m i < > splits, zooms, goes and moves; Esc or Ctrl+B"); usage.WriteLine(" cancels, and pausing after Ctrl+B pops a panel naming each key. Or drag a tab"); usage.WriteLine(" strip onto another pane — middle drops it as a tab, an edge splits there."); diff --git a/src/SharpMUTerm.Tui/Hosting/ClientHost.cs b/src/SharpMUTerm.Tui/Hosting/ClientHost.cs index 9d3de712..97382418 100644 --- a/src/SharpMUTerm.Tui/Hosting/ClientHost.cs +++ b/src/SharpMUTerm.Tui/Hosting/ClientHost.cs @@ -194,7 +194,7 @@ internal sealed record ClientHost /// /// Draws its own text and so can size it (): the window, which is told the Text size - /// page's sizes and the zoom, and asks the client to step the zoom on Ctrl+= / Ctrl+- / Ctrl+0 and Ctrl+wheel. Null in + /// page's sizes and the zoom, and asks the client to step the zoom on Ctrl+= / Ctrl+- / Ctrl+Numpad 0 and Ctrl+wheel. Null in /// the terminal (its font size is its emulator's), the snapshot, the tests and --plain, where the client lists /// none of it. /// diff --git a/src/SharpMUTerm.Tui/MacroKeys.cs b/src/SharpMUTerm.Tui/MacroKeys.cs index 8a999723..525a08c6 100644 --- a/src/SharpMUTerm.Tui/MacroKeys.cs +++ b/src/SharpMUTerm.Tui/MacroKeys.cs @@ -77,6 +77,20 @@ internal static class MacroKeys ? key - ConsoleKey.D0 : null; + /// + /// The open character a Ctrl+digit stands for where the host reports that chord whole: ⌃1–⌃9 are the first nine, + /// ⌃0 the tenth (); null for any other key. Not in + /// , because that list is the same on every host and a terminal never delivers these + /// (): claiming them there would have F4 call ⌃3 taken where it is really Escape. + /// reports them taken only where . + /// + internal static int? CharacterJumpNumber(ConsoleKey key) => key switch + { + >= ConsoleKey.D1 and <= ConsoleKey.D9 => key - ConsoleKey.D0, + ConsoleKey.D0 => CommandIds.CharacterJumpDigits, + _ => null, + }; + /// /// The fixed claims are a local rather than a field: a static field initialiser runs in declaration /// order, so a field read from this method would still be null when the property above calls it. @@ -347,6 +361,13 @@ internal static MacroKeyVerdict Verdict(HostKeys keys, string? descriptor) return new MacroKeyVerdict(MacroKeyDelivery.Taken, $"{canonical} {does}"); } + // ⌃1–⌃9 and ⌃0 go to a character where the host delivers them (SharpMUTermApp.RegisterCharacterJumps). + if (whole && parts.Ctrl && !parts.Alt && !parts.Shift && IsDigit(parts.Key)) + { + var number = parts.Key == "0" ? CommandIds.CharacterJumpDigits : parts.Key[0] - '0'; + return new MacroKeyVerdict(MacroKeyDelivery.Taken, $"{canonical} goes to character {number}"); + } + if (parts.Key.Length == 4 && parts.Key.StartsWith("Num", StringComparison.Ordinal) && char.IsAsciiDigit(parts.Key[3])) { diff --git a/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterJumps.cs b/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterJumps.cs new file mode 100644 index 00000000..59dd21a2 --- /dev/null +++ b/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterJumps.cs @@ -0,0 +1,90 @@ +using SharpMUTerm.Core.Commands; +using SharpMUTerm.Core.Diagnostics; + +namespace SharpMUTerm.Tui; + +/// +/// ⌃1–⌃9 and ⌃0: go straight to the main window of the first ten open characters, in the order the sidebar lists +/// them (, the order ⌥J and ⌥K walk). +/// +/// Only where the host delivers Ctrl+digit as itself (: the window). +/// A terminal writes ⌃1 as a bare 1, ⌃3 as Escape and ⌃8 as Backspace (MacroKeys.DigitBytes), so there the +/// chord does not exist and nothing claims it; ⌥J/⌥K and ⌃P's Switch to … entries are the way, and ⌥1–⌥9 are +/// still the active character's windows in both hosts. +/// +/// +/// Open characters only, the cycle's rule: opens a session for one that has none, +/// and a digit that dialled a character by accident is the thing the cycle was built not to do. The character you are +/// on counts, so ⌃1 from its Chat window goes back to its main window. +/// +/// +internal sealed partial class SharpMUTermApp +{ + /// Whether this host's keyboard has the character chords (the window, not a terminal). + private bool HasCharacterJumps => Host.Keys.ReportsChordsWhole; + + /// + /// Claims ⌃0–⌃9 where the host reports them whole. Registered apart from + /// for the reason gives; F4 reads , which + /// says taken on exactly this host. + /// + private void RegisterCharacterJumps() + { + if (!HasCharacterJumps) + { + return; + } + + for (var key = ConsoleKey.D0; key <= ConsoleKey.D9; key++) + { + var number = MacroKeys.CharacterJumpNumber(key)!.Value; + Func action = () => + { + DisarmPrefix(); + LeaveRailKeys(); + JumpToCharacter(number); + return true; + }; + _system.RegisterGlobalShortcut(ConsoleModifiers.Control, key, action); + _shortcuts[(ConsoleModifiers.Control, key)] = action; + } + } + + /// Goes to the main window of open character (1-based), or says why it cannot. + private void JumpToCharacter(int number) + { + var cycle = CommandCatalog.CharacterCycle(BuildCharacterRefs()); + if (number < 1 || number > cycle.Count) + { + // Never silent, ⌥N's rule: the count is the whole answer. + Notice( + cycle.Count switch + { + 0 => "no character is open — the sidebar and ⌃P open one", + 1 => $"there is no character {number} — only {DisplayName(cycle[0].SessionKey)} is open", + _ => $"there is no character {number} — {cycle.Count} are open", + }, + MessageSeverity.Warning, + CommandIds.CharacterJumpChord(number)); + return; + } + + SwitchToCharacter(cycle[number - 1].SessionKey); + } + + /// + /// The sidebar chord for each of the first ten open characters where the host has the character chords: every + /// such row carries the chord that reaches it, the rule the window rows' ⌥N already follow. + /// + private Dictionary CharacterJumpChords() + { + var chords = new Dictionary(StringComparer.Ordinal); + var cycle = CommandCatalog.CharacterCycle(BuildCharacterRefs()); + for (var i = 0; i < cycle.Count && i < CommandIds.CharacterJumpDigits; i++) + { + chords[cycle[i].SessionKey] = CommandIds.CharacterJumpChord(i + 1); + } + + return chords; + } +} diff --git a/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterMenu.cs b/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterMenu.cs index 706970c2..b94f6cdf 100644 --- a/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterMenu.cs +++ b/src/SharpMUTerm.Tui/SharpMUTermApp.CharacterMenu.cs @@ -40,7 +40,7 @@ internal MenuModel HeaderCharacterMenu() var command = CommandIds.Character(character.SessionKey); if (_contributions.Commands.Resolve(command) is not null) { - entries.Add(new MenuEntry(Snippet(label), character.Chord is "⌥J" or "⌥K" ? character.Chord : null, command, + entries.Add(new MenuEntry(Snippet(label), character.Chord is { Length: > 0 } chord ? chord : null, command, Checked: character.Active, Enabled: !character.Active)); } } diff --git a/src/SharpMUTerm.Tui/SharpMUTermApp.Help.cs b/src/SharpMUTerm.Tui/SharpMUTermApp.Help.cs index d1f43619..f4e55b6b 100644 --- a/src/SharpMUTerm.Tui/SharpMUTermApp.Help.cs +++ b/src/SharpMUTerm.Tui/SharpMUTermApp.Help.cs @@ -91,7 +91,8 @@ internal void SimulateHelpTyping(string text) internal HelpModel HelpModelNow() => HelpModel.Build( BuildCatalog(), Host.Keys.Newline.Glyph, - Host.Keys.Reserved.Select(r => (r.Chord.Glyph, r.Action)).ToArray()); + Host.Keys.Reserved.Select(r => (r.Chord.Glyph, r.Action)).ToArray(), + HasCharacterJumps); /// /// ⌃P ▸ Help and /help: opens help, typed into its search, or closes it. With no diff --git a/src/SharpMUTerm.Tui/SharpMUTermApp.TextSize.cs b/src/SharpMUTerm.Tui/SharpMUTermApp.TextSize.cs index 820e1cd1..99f5cb29 100644 --- a/src/SharpMUTerm.Tui/SharpMUTermApp.TextSize.cs +++ b/src/SharpMUTerm.Tui/SharpMUTermApp.TextSize.cs @@ -7,7 +7,7 @@ namespace SharpMUTerm.Tui; /// /// Text size and zoom, where the host draws its own text (: the desktop window). The /// sizes are the configuration's : the Text size page edits them through the -/// settings funnel like any setting, the window's Ctrl+= / Ctrl+- / Ctrl+0 and Ctrl+wheel and ⌃P's zoom entries step the +/// settings funnel like any setting, the window's Ctrl+= / Ctrl+- / Ctrl+Numpad 0 and Ctrl+wheel and ⌃P's zoom entries step the /// zoom here, and the host is told the result. A terminal has none of it: its font size is its emulator's, and nothing an /// application writes changes it (xterm's OSC 50 picks a font, not a size, and is off in every terminal this client /// targets), so the client lists nothing that would do nothing and the help topic says to use the terminal's own zoom. @@ -85,7 +85,7 @@ internal bool StepZoom(int step) _config.Display.Zoom = after; PersistConfiguration(); SyncTextSizes(); - Notice($"zoom {ZoomLevels.Label(after)}", MessageSeverity.Info, key: step == 0 ? "⌃0" : step > 0 ? "⌃=" : "⌃-", toast: false); + Notice($"zoom {ZoomLevels.Label(after)}", MessageSeverity.Info, key: step == 0 ? "⌃Num0" : step > 0 ? "⌃=" : "⌃-", toast: false); return true; } diff --git a/src/SharpMUTerm.Tui/SharpMUTermApp.cs b/src/SharpMUTerm.Tui/SharpMUTermApp.cs index e035e2c9..fea78b56 100644 --- a/src/SharpMUTerm.Tui/SharpMUTermApp.cs +++ b/src/SharpMUTerm.Tui/SharpMUTermApp.cs @@ -7724,6 +7724,7 @@ private void RegisterGlobalShortcuts() } } + RegisterCharacterJumps(); RegisterFocusReportTab(); } @@ -9024,6 +9025,11 @@ private Dictionary WindowChords() /// private Dictionary CharacterChords() { + if (HasCharacterJumps) + { + return CharacterJumpChords(); + } + var chords = new Dictionary(StringComparer.Ordinal); var cycle = CommandCatalog.CharacterCycle(BuildCharacterRefs()); var here = cycle.FindIndex(c => c.SessionKey == _active?.SessionKey); @@ -9157,6 +9163,7 @@ private CommandContext CommandState() WindowMode: CanSetWindowMode ? Host.WindowModes!.Mode : null, TextZoom: CanSizeText ? TextSizes.Zoom : null, TextSizePage: HasTextSizePage, + CharacterJumps: HasCharacterJumps, Update: UpdateCommandState(), ScriptFiles: !_scriptsListed || (_scriptsRoot is null && !DemoScriptsShown) ? null : ScriptFileRefs()); } diff --git a/tests/SharpMUTerm.Avalonia.Tests/SurfaceParityTests.cs b/tests/SharpMUTerm.Avalonia.Tests/SurfaceParityTests.cs index 301c0961..a084251e 100644 --- a/tests/SharpMUTerm.Avalonia.Tests/SurfaceParityTests.cs +++ b/tests/SharpMUTerm.Avalonia.Tests/SurfaceParityTests.cs @@ -1694,7 +1694,9 @@ private static void TypeLine(SharpMUTermApp app, string text) [Test] public async Task F4TellsTheWindowsTruth() { - await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Ctrl+3").Fires).IsTrue(); + // ⌃H is Backspace in a terminal; a window reports it as itself. + await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Ctrl+H").Fires).IsTrue(); + await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Ctrl+3").Reason).Contains("goes to character 3"); await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Ctrl+Shift+Left").Fires).IsTrue(); await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Alt+Enter").Delivery).IsEqualTo(MacroKeyDelivery.Taken); await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Alt+Enter").Reason).Contains("maximises"); @@ -1705,15 +1707,15 @@ public async Task F4TellsTheWindowsTruth() await using var app = App(driver, config); app.BindWorldWithoutConnecting(config.Worlds[0]); var macro = config.TriggerSets.SelectMany(s => s.Macros).Single(m => m.Key == "Ctrl+F1"); - macro.Key = "Ctrl+3"; + macro.Key = "Ctrl+H"; - var key = KeyMapper.FromKeyDown(Key.D3, KeyModifiers.Control); + var key = KeyMapper.FromKeyDown(Key.H, KeyModifiers.Control); await Assert.That(key).IsNotNull(); await Assert.That(app.SimulateKey(key!.Value)).IsEqualTo("score"); var hotkeys = string.Join('\n', KeypadScreenRenderer.HotkeysColumn(app.Host.Keys, config.TriggerSets.SelectMany(s => s.Macros).ToList())); - await Assert.That(hotkeys).Contains("⌃3"); - await Assert.That(hotkeys).DoesNotContain("▲ ⌃3"); + await Assert.That(hotkeys).Contains("⌃H"); + await Assert.That(hotkeys).DoesNotContain("▲ ⌃H"); // The numpad is a key the window delivers: F4 marks no numpad binding dead, and Num7 reaches its macro. await Assert.That(MacroKeys.Verdict(WindowHost.Keys, "Num7").Fires).IsTrue(); diff --git a/tests/SharpMUTerm.Avalonia.Tests/TerminalZoomTests.cs b/tests/SharpMUTerm.Avalonia.Tests/TerminalZoomTests.cs index 147f35ee..3b89f315 100644 --- a/tests/SharpMUTerm.Avalonia.Tests/TerminalZoomTests.cs +++ b/tests/SharpMUTerm.Avalonia.Tests/TerminalZoomTests.cs @@ -11,7 +11,7 @@ public class TerminalZoomTests [Test] public async Task ReservedZoomChordsMatchTheirActions() { - await Assert.That(WindowHost.Zoom.Count).IsEqualTo(7); + await Assert.That(WindowHost.Zoom.Count).IsEqualTo(6); foreach (var reserved in WindowHost.Zoom) { var key = Enum.Parse(reserved.Chord.Key.ToString()); @@ -232,4 +232,36 @@ public async Task ZoomKeysAreLocalAndOrdinaryTypingStillReachesTheClient() await Assert.That(TerminalView.ZoomFor(Key.Subtract, KeyModifiers.Control)).IsEqualTo(-1); await Assert.That(TerminalView.ZoomFor(Key.NumPad0, KeyModifiers.Control)).IsEqualTo(0); } + + /// + /// Ctrl+0 is the tenth character's chord, not the zoom reset, and every Ctrl+digit reaches the client as itself + /// once: the digit a platform may also send as text is not typed into the command line. + /// + [Test] + public async Task CtrlAndADigitReachTheClientAsTheChordAndTypeNothing() + { + await Assert.That(TerminalView.ZoomFor(Key.D0, KeyModifiers.Control)).IsNull(); + await Assert.That(WindowHost.Keys.Reserved.Any(r => r.Chord.Key == ConsoleKey.D0)).IsFalse(); + + var sent = await TerminalViewTests.Session.Dispatch(() => + { + using var driver = new AvaloniaConsoleDriver(80, 24); + var view = new TerminalView(driver, SKColors.White, SKColors.Black, 16, null); + var keys = new List(); + driver.KeyPressed += (_, key) => keys.Add(key); + foreach (var (key, text) in new[] { (Key.D1, "1"), (Key.D0, "0") }) + { + view.HandleKeyDown(new KeyEventArgs { Key = key, KeyModifiers = KeyModifiers.Control }); + view.HandleTextInput(new TextInputEventArgs { Text = text }); + } + + return keys; + }, CancellationToken.None); + + await Assert.That(sent.Select(k => (k.Key, k.Modifiers)).ToArray()).IsEquivalentTo(new[] + { + (ConsoleKey.D1, ConsoleModifiers.Control), + (ConsoleKey.D0, ConsoleModifiers.Control), + }); + } } diff --git a/tests/SharpMUTerm.Tui.Tests/CharacterJumpTests.cs b/tests/SharpMUTerm.Tui.Tests/CharacterJumpTests.cs new file mode 100644 index 00000000..cca2c862 --- /dev/null +++ b/tests/SharpMUTerm.Tui.Tests/CharacterJumpTests.cs @@ -0,0 +1,147 @@ +using SharpConsoleUI.Drivers; +using SharpMUTerm.Client.Modals; +using SharpMUTerm.Core.Commands; +using SharpMUTerm.Core.Configuration; +using SharpMUTerm.Graphics; + +namespace SharpMUTerm.Tui.Tests; + +/// +/// ⌃1–⌃9 and ⌃0 go to the main window of the first ten open characters, in the order the sidebar lists them, on a +/// host that reports Ctrl+digit whole (the window). A terminal sends those chords as a bare digit or as another +/// key's byte, so there nothing claims them and F4 says so. +/// +[NotInParallel] +public class CharacterJumpTests +{ + private static readonly TerminalCapabilities Caps = + new(GraphicsProtocol.None, supportsTrueColor: true, supportsKittyGraphics: false, supportsSixel: false); + + private static readonly HostKeys WindowKeys = HostKeys.Terminal with { ReportsChordsWhole = true, DeliversNumpad = true }; + + private static readonly string[] Sessions = ["Alfa.Ann", "Bravo.Bob", "Cara.Cal"]; + + [Test] + public async Task EachDigitGoesToThatCharactersMainWindow() + { + await using var app = Scene(WindowKeys); + + app.SimulateKey(CtrlDigit(2)); + await Assert.That(app.ActiveSessionKey).IsEqualTo("Bravo.Bob"); + await Assert.That(app.ActiveWindowId()).IsEqualTo("char:Bravo.Bob"); + + app.SimulateKey(CtrlDigit(3)); + await Assert.That(app.ActiveSessionKey).IsEqualTo("Cara.Cal"); + + app.SimulateKey(CtrlDigit(1)); + await Assert.That(app.ActiveSessionKey).IsEqualTo("Alfa.Ann"); + } + + [Test] + public async Task ADigitPastTheOpenCharactersSaysSoAndOpensNobody() + { + await using var app = Scene(WindowKeys, unopened: true); + + app.SimulateKey(CtrlDigit(4)); + await Assert.That(app.ActiveSessionKey).IsEqualTo("Alfa.Ann"); + await Assert.That(app.StatusMarkup).Contains("there is no character 4"); + await Assert.That(app.FindSession("Delta.Dee")).IsNull().Because("⌃N walks open characters and never dials one"); + + app.SimulateKey(CtrlDigit(0)); + await Assert.That(app.StatusMarkup).Contains("there is no character 10").Because("⌃0 is the tenth"); + } + + [Test] + public async Task TheSidebarAndThePaletteNameEachCharactersChord() + { + await using var app = Scene(WindowKeys); + app.RenderNextFrame(); + + var rail = app.RailLines.Select(FrameGrid.Visible).ToArray(); + foreach (var (name, chord) in new[] { ("Ann", "⌃1"), ("Bob", "⌃2"), ("Cal", "⌃3") }) + { + await Assert.That(rail.Any(l => l.Contains(name, StringComparison.Ordinal) && l.Contains(chord, StringComparison.Ordinal))) + .IsTrue().Because($"{name}'s row names {chord}"); + } + + var bob = app.BuildCatalog().Single(c => c.Id == CommandIds.Character("Bravo.Bob")); + await Assert.That(bob.Key).IsEqualTo("⌃2"); + + var help = app.HelpModelNow().Topic("keys")!; + await Assert.That(help.Lines.Any(l => l.Contains("⌃1 to ⌃9 and ⌃0", StringComparison.Ordinal))).IsTrue(); + } + + [Test] + public async Task ATerminalClaimsNoCtrlDigit() + { + await using var app = Scene(HostKeys.Terminal); + + app.SimulateKey(CtrlDigit(2)); + await Assert.That(app.ActiveSessionKey).IsEqualTo("Alfa.Ann"); + + var bob = app.BuildCatalog().Single(c => c.Id == CommandIds.Character("Bravo.Bob")); + await Assert.That(bob.Key).IsEqualTo("⌥J").Because("the terminal keeps the cycle's neighbours"); + await Assert.That(app.HelpModelNow().Topic("keys")!.Lines.Any(l => l.Contains("⌃1 to ⌃9", StringComparison.Ordinal))).IsFalse(); + } + + [Test] + public async Task F4SaysTakenInTheWindowAndNeverArrivesInATerminal() + { + for (var n = 0; n <= 9; n++) + { + var window = MacroKeys.Verdict(WindowKeys, $"Ctrl+{n}"); + await Assert.That(window.Delivery).IsEqualTo(MacroKeyDelivery.Taken); + await Assert.That(window.Reason).Contains($"goes to character {(n == 0 ? 10 : n)}"); + await Assert.That(MacroKeys.Verdict(HostKeys.Terminal, $"Ctrl+{n}").Delivery).IsEqualTo(MacroKeyDelivery.NeverArrives); + } + + await Assert.That(MacroKeys.Verdict(WindowKeys, "Ctrl+Shift+1").Fires).IsTrue().Because("only the bare Ctrl chord is taken"); + } + + [Test] + public async Task HelpNamesTheChordOnlyWhereItArrives() + { + var window = new StringWriter(); + ClientUsage.Write(window, ClientUsage.Terminal, WindowKeys); + await Assert.That(window.ToString()).Contains("Ctrl+1 to Ctrl+9 and Ctrl+0"); + + var terminal = new StringWriter(); + ClientUsage.Write(terminal, ClientUsage.Terminal, HostKeys.Terminal); + await Assert.That(terminal.ToString()).DoesNotContain("Ctrl+1 to Ctrl+9"); + } + + private static ConsoleKeyInfo CtrlDigit(int n) => new((char)('0' + n), ConsoleKey.D0 + n, false, false, true); + + private static SharpMUTermApp Scene(HostKeys keys, bool unopened = false) + { + Console.SetIn(TextReader.Null); + var config = new AppConfiguration(); + var names = new List<(string World, string Character)> { ("Alfa", "Ann"), ("Bravo", "Bob"), ("Cara", "Cal") }; + if (unopened) + { + names.Add(("Delta", "Dee")); + } + + foreach (var (world, character) in names) + { + var definition = new WorldDefinition { Name = world, Host = $"{world.ToLowerInvariant()}.example.org", Port = 4000 }; + definition.Characters.Add(new CharacterDefinition { Name = character, Logging = new LoggingSettings() }); + config.Worlds.Add(definition); + } + + var host = ClientHost.Headless(new HeadlessConsoleDriver(160, 40), Caps) with { Keys = keys }; + var app = new SharpMUTermApp(config, host); + app.TelnetFactory = _ => new RecordingTelnetSession(); + foreach (var key in Sessions) + { + if (!app.DispatchCommand(CommandIds.Character(key))) + { + throw new InvalidOperationException($"the app would not switch to {key}"); + } + } + + app.DispatchCommand(CommandIds.Character(Sessions[0])); + app.RenderNextFrame(); + return app; + } +}