From 4a69952f4af8edc673120aa0917e9e0b97658e6e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:11:25 +0000 Subject: [PATCH] Write ClearScreen in MXP as the terminal's erase MXP has no clear of its own and was sent nothing. Its clients already read SGR in the same stream, so it now gets ESC[H ESC[2J. Pueblo keeps alone. docs/formats.md gains a table of which clients clear, from their source. Fixes #109 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Rqqt7W4pTuJocxqXvvDUcf --- CHANGELOG.md | 6 +++++ MarkupString.Ansi/AnsiRegistration.cs | 5 ++-- MarkupString.Ansi/Emitters/ElementEmitters.cs | 14 +++++++--- MarkupString.Mxp/README.md | 4 +++ .../Decoding/MxpDecodingTests.cs | 12 +++++++++ MarkupString.Tests/SharedVocabularyTests.cs | 2 +- MarkupString/Elements/ScreenMarkup.cs | 7 ++++- docs/formats.md | 27 ++++++++++++++++++- 8 files changed, 68 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a92f4a5..e7b73c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed +- `MarkupText.ClearScreen()` is written in MXP as `ESC[H ESC[2J` when `WithAnsi()` is registered, in place of + nothing: MXP has no clear of its own, and its clients already read SGR in the same stream. Pueblo keeps + `` alone. [Formats](docs/formats.md#clearing-the-screen) has a table of which clients + clear: MUSHclient, Mudlet and BeipMU drop both instructions, so a game should not count on a clear having + happened (#109). + - Half-block pictures write a cell whose two halves are the same colour as a space on that background, not as `█`. A background fills the whole cell in every client, but clients that draw `█` from the font (BeipMU among them) fill only the glyph's height, which is shorter than a line, so solid areas came out striped. diff --git a/MarkupString.Ansi/AnsiRegistration.cs b/MarkupString.Ansi/AnsiRegistration.cs index 7573f87..3221ee3 100644 --- a/MarkupString.Ansi/AnsiRegistration.cs +++ b/MarkupString.Ansi/AnsiRegistration.cs @@ -6,7 +6,7 @@ public static class AnsiRegistration /// /// Returns a registry that renders in all seven formats and serialises /// it under kind "ansi". Plain needs nothing: the body passes through. It also writes the - /// bell, a for a terminal, an as + /// bell, a for a terminal and an MXP client, an as /// BBCode's [img] and Markdown's ![](), and a laid-out block as Markdown's own /// structure — a table, a list, a rule. /// @@ -36,7 +36,8 @@ public static MarkupRegistry WithAnsi(this MarkupRegistry registry) .With(new BellEmitter(MarkupFormat.Mxp)) .With(new BellEmitter(MarkupFormat.Html)) // From the shared vocabulary, what a terminal, BBCode and Markdown can express. - .With(new ClearScreenAnsiEmitter()) + .With(new ClearScreenAnsiEmitter(MarkupFormat.Ansi)) + .With(new ClearScreenAnsiEmitter(MarkupFormat.Mxp)) .With(new ImageBBCodeEmitter()) .With(new ImageMarkdownEmitter()) // A layout as Markdown's own structure. Markdown has no styling this package does not already diff --git a/MarkupString.Ansi/Emitters/ElementEmitters.cs b/MarkupString.Ansi/Emitters/ElementEmitters.cs index 5bf1cd3..aae88a9 100644 --- a/MarkupString.Ansi/Emitters/ElementEmitters.cs +++ b/MarkupString.Ansi/Emitters/ElementEmitters.cs @@ -2,17 +2,23 @@ namespace MarkupString.Ansi; /// -/// Clears a terminal's screen. The rest of the shared vocabulary is left to the core rule for a -/// terminal: a point writes nothing, and a markup wrapping text writes the text. +/// Clears the screen with the terminal's erase, in and in +/// , which has no clear of its own but already carries SGR. The rest of +/// the shared vocabulary is left to the core rule for a terminal: a point writes nothing, and a markup +/// wrapping text writes the text. /// -internal sealed class ClearScreenAnsiEmitter : IMarkupEmitter +/// +/// An MXP client that keeps a scrolling window reads the erase and drops it (Mudlet, MUSHclient), so it +/// costs nothing there and clears wherever the client honours it. +/// +internal sealed class ClearScreenAnsiEmitter(MarkupFormat format) : IMarkupEmitter { /// Home the cursor, then erase the display. internal const string Sequence = "\u001b[H\u001b[2J"; public Type MarkupType => typeof(ClearScreenMarkup); - public MarkupFormat Format => MarkupFormat.Ansi; + public MarkupFormat Format { get; } = format; public void Emit(IMarkup markup, ReadOnlySpan body, in EmitContext context, IBufferWriter output) { diff --git a/MarkupString.Mxp/README.md b/MarkupString.Mxp/README.md index 1696141..92be1c4 100644 --- a/MarkupString.Mxp/README.md +++ b/MarkupString.Mxp/README.md @@ -8,6 +8,10 @@ You say a thing once; this package is how an MXP client hears it. The same text client through `MarkupString.Pueblo`, to a browser through `MarkupString.Html`, and to a terminal, which gets a picture's description, a pane's text, and nothing for a sound. +MXP has no clear of its own, so `MarkupText.ClearScreen()` is written as the terminal's `ESC[H ESC[2J` +when `WithAnsi()` is registered. Mudlet and MUSHclient drop it; see +[the client table](https://github.com/SharpMUSH/MarkupString/blob/main/docs/formats.md#clearing-the-screen). + ```sh dotnet add package MarkupString.Mxp ``` diff --git a/MarkupString.Tests/Decoding/MxpDecodingTests.cs b/MarkupString.Tests/Decoding/MxpDecodingTests.cs index b30dd84..e2a830a 100644 --- a/MarkupString.Tests/Decoding/MxpDecodingTests.cs +++ b/MarkupString.Tests/Decoding/MxpDecodingTests.cs @@ -34,6 +34,18 @@ public async Task OpenTags_WorkOnAnOpenLine() await Assert.That(spans[2].Style.Foreground).IsEqualTo(new RgbColor(255, 0, 0)); } + /// MXP has no clear of its own; the terminal's erase a server writes for one reads back as one clear. + [Test] + public async Task ClearScreen_AsAServerWritesIt_IsOneClear() + { + var written = MarkupText.Concat([MarkupText.ClearScreen(), MarkupText.Plain("top")]) + .Render(MarkupFormat.Mxp, MarkupRegistry.Empty.WithAnsi().WithMxp().WithMxpSecureLines()); + + var (lines, _, _) = Decode(written + "\n"); + await Assert.That(Markups(lines[0]).OfType().Count()).IsEqualTo(1); + await Assert.That(lines[0].Content.ToPlainText()).IsEqualTo("top"); + } + [Test] public async Task SecureTags_AreDroppedOnAnOpenLine() { diff --git a/MarkupString.Tests/SharedVocabularyTests.cs b/MarkupString.Tests/SharedVocabularyTests.cs index 7549c8c..7667366 100644 --- a/MarkupString.Tests/SharedVocabularyTests.cs +++ b/MarkupString.Tests/SharedVocabularyTests.cs @@ -145,7 +145,7 @@ public async Task ClearingTheScreenIsEachFormatsOwnInstruction() await Assert.That(Render(clear, MarkupFormat.Ansi)).IsEqualTo("\e[H\e[2J"); await Assert.That(Render(clear, MarkupFormat.Pueblo)).IsEqualTo(""); await Assert.That(Render(clear, MarkupFormat.Html)).IsEqualTo(""); - await Assert.That(Render(clear, MarkupFormat.Mxp)).IsEqualTo(string.Empty).Because("MXP has no such instruction"); + await Assert.That(Render(clear, MarkupFormat.Mxp)).IsEqualTo("\e[H\e[2J").Because("MXP has no clear of its own"); await Assert.That(Render(clear, MarkupFormat.Plain)).IsEqualTo(string.Empty); } diff --git a/MarkupString/Elements/ScreenMarkup.cs b/MarkupString/Elements/ScreenMarkup.cs index 731a848..8fe04dc 100644 --- a/MarkupString/Elements/ScreenMarkup.cs +++ b/MarkupString/Elements/ScreenMarkup.cs @@ -5,7 +5,12 @@ namespace MarkupString; /// /// /// A terminal gets ESC[H ESC[2J, Pueblo <xch_page clear="text">, and an HTML page an -/// empty ms-clear element to act on. MXP has no such instruction and is sent nothing. +/// empty ms-clear element to act on. MXP has no clear of its own and is sent the terminal's. +/// +/// Most MUD clients keep a scrolling window and drop both instructions, so a clear is a request, not a +/// promise: send nothing after it that only makes sense on an empty screen. docs/formats.md lists which +/// clients clear. +/// /// public sealed class ClearScreenMarkup : IPointMarkup { diff --git a/docs/formats.md b/docs/formats.md index 786414e..7f2b2b5 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -85,7 +85,7 @@ line.Render(MarkupFormat.Ansi); // A map of the city The door creaks. | `StopSound` | `` / `` | `` | `ms-sound-stop` | nothing | | `Image` | `` | `` | `` | the description, or the address; BBCode `[img]`, Markdown `![description](address)` | | `Pane` | `…` | `…` and back to `_previous` | `ms-pane` around the text | the text | -| `ClearScreen` | nothing | `` | `ms-clear` | ANSI `ESC[H ESC[2J` | +| `ClearScreen` | `ESC[H ESC[2J` (with `WithAnsi`) | `` | `ms-clear` | ANSI `ESC[H ESC[2J` | | `Prefetch` | nothing | `` | `` | nothing | | `ExpireLinks` | `` | nothing | `ms-expire` | nothing | | `Variable`, `Gauge`, `Status` | ``, ``, `` | the text | `ms-variable`, `ms-gauge`, `ms-status` around the text | the text | @@ -117,6 +117,31 @@ carrier, so a point can never stand over words that a format would then swallow, with one out of place drops the point rather than the text. Styling *around* a point is fine: the styling is written only if the point is. +### Clearing the screen + +`MarkupText.ClearScreen()` asks the client to clear. MXP has no clear of its own, so it is sent the +terminal's erase, which its clients already read alongside SGR. Pueblo keeps `` +alone: the Pueblo client turns `ESC[2J` into that same tag, and the other Pueblo clients act on neither, +so adding the erase would clear nothing more and would make one clear read back as two. + +Most MUD clients keep a scrolling window and drop both, without showing anything: + +| Client | `ESC[H ESC[2J` | `` | Where | +|---|---|---|---| +| A terminal (telnet and the like) | clears | shown as text | — | +| Pueblo | clears (rewritten as `xch_page clear=text`) | clears | `ChWConn.cpp`, `ChHeadElement.cpp` | +| MUSHclient | dropped: only `m` and `z` are read after `ESC[` | dropped: `xch_page` only turns MXP off | `telnet_phases.cpp`, `mxp/mxpOpenAtomic.cpp` | +| Mudlet | dropped: erase in display is refused | no Pueblo | `src/TBuffer.cpp` | +| BeipMU | dropped: only SGR and OSC 8 are read | dropped: its attributes are skipped | `src/AnsiParser.cpp`, `src/TextToLine.cpp` | +| SharpMUTerm | read as a `ClearScreenMarkup`, not acted on | the same | `MarkupLineParser.Point` | +| SharpClient | read as a clear, then ignored to keep scrollback | the same | `OutputView.razor` | +| A `MarkupString.Web` page | — | — | `ms-clear` removes what came before | + +Nothing is written in place of a clear for a client that will drop it: the server cannot tell which +clients those are, and a blank line or a rule would stay on a screen that did clear. So a clear is a +request, not a promise. Send nothing after it that only makes sense on an empty screen, such as the +same screen again on the assumption the first one is gone. + ### What an MXP client said it supports MXP asks a client which elements it can render with ``, and a client that answered `-image`