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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ line falls out of the scrollback — and a resize does nothing to it at all. See
## Compliance
![Compliance](https://raw.githubusercontent.com/tomlm/Iciclecreek.Avalonia.Terminal/main/compliance.png)

## Behaviour changes

**DECRQCRA is off by default.** `CSI Pid ; Pp ; Pt ; Pl ; Pb ; Pr * y` asks for a checksum of a
rectangle of the screen. Asked one cell at a time, it gives back the text, so a program, or a remote
host you've just ssh'd to, can read what was on screen before it started, alternate screen included.
WezTerm turned it off for the same reason, xterm gates it behind `allowWindowOps`, and iTerm2 asks
first. While it is off the request is ignored and nothing is sent back, which is what xterm and
WezTerm do.

esctest reads every cell back through DECRQCRA, so turn it back on for a conformance run:

```csharp
var terminal = new Terminal(new TerminalOptions { ChecksumReportsEnabled = true });
// or, on a running terminal:
terminal.Options.ChecksumReportsEnabled = true;
```

## Upgrading to 3.0

**3.0 changes how Sixel is stored.** If you only host a terminal and draw text, or draw only Kitty
Expand Down
32 changes: 30 additions & 2 deletions src/XTerm.NET.Tests/ChecksumReportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,36 @@ public class ChecksumReportTests
{
private const string Esc = "";

private static Terminal NewTerminal(int cols = 20, int rows = 5) =>
new(new TerminalOptions { Cols = cols, Rows = rows });
// Opted in, as an esctest run has to be: the report is off by default (tomlm/XTerm.NET#190).
private static Terminal NewTerminal(int cols = 20, int rows = 5, bool enabled = true) =>
new(new TerminalOptions { Cols = cols, Rows = rows, ChecksumReportsEnabled = enabled });

/// <summary>
/// Off by default: DECRQCRA reads the screen back one cell at a time, so a program could recover
/// what was displayed before it started. Like xterm and WezTerm when it is disallowed, the
/// request goes unanswered rather than drawing a reply that could pass for a sum.
/// </summary>
[Fact]
public void Is_silent_by_default()
{
var terminal = new Terminal(new TerminalOptions { Cols = 20, Rows = 5 });
terminal.Write("Hello");

Assert.Null(Reply(terminal, $"{Esc}[1;0;1;1;1;1*y"));
Assert.Null(Reply(terminal, $"{Esc}[1*y"));
}

[Fact]
public void Is_silent_when_disabled_and_answers_once_enabled()
{
var terminal = NewTerminal(enabled: false);
terminal.Write("Hello");
Assert.Null(Reply(terminal, $"{Esc}[1;0;1;1;1;1*y"));

// The option is read per request, so a host can turn it on for a running terminal.
terminal.Options.ChecksumReportsEnabled = true;
Assert.Equal(Report(1, 'H'), Reply(terminal, $"{Esc}[1;0;1;1;1;1*y"));
}

private static string? Reply(Terminal terminal, string sequence)
{
Expand Down
1 change: 1 addition & 0 deletions src/XTerm.NET.Tests/DeviceReportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void Decrqtsr_WithNoParameterAsksForNothing()
public void Decrqcra_IsSilentBelowLevel64()
{
var (terminal, replies) = Create();
terminal.Options.ChecksumReportsEnabled = true; // opt-in; the level gate is what's tested
terminal.Write(Esc + "[64\"p");
terminal.Write(Esc + "[1;0;1;1;1;1*y");
Assert.Single(replies); // answered at VT400
Expand Down
1 change: 1 addition & 0 deletions src/XTerm.NET.Tests/Options/TerminalOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void Constructor_SetsDefaultValues()
Assert.Equal(RendererType.Canvas, options.RendererType);
Assert.True(options.ClipboardWriteEnabled);
Assert.False(options.ClipboardReadEnabled);
Assert.False(options.ChecksumReportsEnabled); // DECRQCRA reads the screen back: opt-in
Assert.NotNull(options.WindowOptions);
Assert.NotNull(options.Theme);
Assert.Equal(1, options.MinimumContrastRatio);
Expand Down
1 change: 1 addition & 0 deletions src/XTerm.NET.Tests/VtTestBehaviourTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public void A_tab_stop_can_be_set_and_landed_on()
public void Rectangular_area_checksums_negate_the_sum_of_the_characters()
{
var terminal = Sized(20, 5);
terminal.Options.ChecksumReportsEnabled = true; // vttest's checksum test needs the opt-in
var replies = new List<string>();
terminal.DataReceived += (_, e) => replies.Add(e.Data);

Expand Down
5 changes: 5 additions & 0 deletions src/XTerm.NET/InputHandler.Csi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,11 @@ private void RequestChecksumRectangularArea(Params parameters)
if (!RectangularEditingAvailable)
return;

// A read-back of the screen, so opt-in; see TerminalOptions.ChecksumReportsEnabled. Silent
// when off, as xterm and WezTerm are, rather than a reply that could be mistaken for a sum.
if (!_terminal.Options.ChecksumReportsEnabled)
return;

var id = parameters.GetParam(0, 0);
// parameters[1] is the page, ignored. Coordinates are read in the ORIGIN MODE system,
// like a cursor address and like every rectangle operation: a program that addresses its
Expand Down
17 changes: 17 additions & 0 deletions src/XTerm.NET/Options/TerminalOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ public int TabStopWidth
/// </remarks>
public bool ClipboardReadEnabled { get; set; } = false;

/// <summary>
/// Whether DECRQCRA (<c>CSI Pid ; Pp ; Pt ; Pl ; Pb ; Pr * y</c>), the checksum of a
/// rectangular area, is answered.
/// </summary>
/// <remarks>
/// <para>Disabled by default for the same reason as <see cref="ClipboardReadEnabled"/>: it is a
/// read-back. Checksumming one cell at a time recovers the screen's text, so a program -- or a
/// remote host the user has just ssh'd to -- can read what was displayed before it started,
/// including the alternate screen the last full-screen application left behind. WezTerm turned
/// it off for this reason, xterm gates it behind <c>allowWindowOps</c>, and iTerm2 asks first.</para>
/// <para>While off the request is ignored and nothing is sent, which is what xterm and WezTerm
/// do when it is disallowed. esctest reads every cell back through this, so a conformance run
/// needs it set true.</para>
/// </remarks>
public bool ChecksumReportsEnabled { get; set; } = false;

/// <summary>
/// Whether control characters survive <see cref="Terminal.Paste(TerminalPaste)"/>.
/// </summary>
Expand Down Expand Up @@ -564,6 +580,7 @@ public TerminalOptions(TerminalOptions other)
KittyNotificationsEnabled = other.KittyNotificationsEnabled;
ClipboardWriteEnabled = other.ClipboardWriteEnabled;
ClipboardReadEnabled = other.ClipboardReadEnabled;
ChecksumReportsEnabled = other.ChecksumReportsEnabled;
AllowPasteControls = other.AllowPasteControls;
MaxClipboardBytes = other.MaxClipboardBytes;
KittyKeyboardEnabled = other.KittyKeyboardEnabled;
Expand Down
Loading