terminal: insert mode tests, fix insertBlanks multi-cell char split

This commit is contained in:
Mitchell Hashimoto
2023-10-12 19:24:27 -07:00
parent 6a065540dd
commit 89d2827910
4 changed files with 132 additions and 1 deletions

View File

@ -1573,6 +1573,11 @@ pub fn insertBlanks(self: *Terminal, count: usize) void {
// This is the index of the final copyable value that we need to copy. // This is the index of the final copyable value that we need to copy.
const copyable_end = start + copyable - 1; const copyable_end = start + copyable - 1;
// If our last cell we're shifting is wide, then we need to clear
// it to be empty so we don't split the multi-cell char.
const cell = row.getCellPtr(copyable_end);
if (cell.attrs.wide) cell.char = 0;
// Shift count cells. We have to do this backwards since we're not // Shift count cells. We have to do this backwards since we're not
// allocated new space, otherwise we'll copy duplicates. // allocated new space, otherwise we'll copy duplicates.
var i: usize = 0; var i: usize = 0;
@ -3949,6 +3954,23 @@ test "Terminal: insertBlanks shift off screen" {
} }
} }
test "Terminal: insertBlanks split multi-cell character" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 10);
defer t.deinit(alloc);
for ("123") |c| try t.print(c);
try t.print('橋');
t.setCursorPos(1, 1);
t.insertBlanks(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings(" 123", str);
}
}
test "Terminal: insertBlanks inside left/right scroll region" { test "Terminal: insertBlanks inside left/right scroll region" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 10); var t = try init(alloc, 10, 10);
@ -4073,6 +4095,24 @@ test "Terminal: insert mode with wide characters at end" {
} }
} }
test "Terminal: insert mode pushing off wide character" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 2);
defer t.deinit(alloc);
for ("123") |c| try t.print(c);
try t.print('😀'); // 0x1F600
t.modes.set(.insert, true);
t.setCursorPos(1, 1);
try t.print('X');
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("X123", str);
}
}
test "Terminal: cursorIsAtPrompt" { test "Terminal: cursorIsAtPrompt" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 3, 2); var t = try init(alloc, 3, 2);

View File

@ -0,0 +1,89 @@
import VTMode from "@/components/VTMode";
# Insert
<VTMode value={4} ansi={true} />
When enabled, text is written to the cell under the cursor
and all existing content is shifted right. When disabled, text
overwrites existing content.
This mode is unset as part of both [full reset (RIS)](/vt/ris)
and [soft reset (DECSTR)](/vt/decstr).
If a multi-cell character (such as "橋") is shifted so that the cell is split
in half, the multi-cell character can either be clipped or erased.
This mode is typically disabled on terminal startup.
## Validation
### INSERT V-1: Simple Usage
```bash
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "123456"
printf "\033[1G"
printf "\033[4h"
printf "ABC"
```
```
|ABC123456_|
```
### INSERT V-2: Pushing Off the Screen Edge
```bash
cols=$(tput cols)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[${cols}G"
printf "\033[6D"
printf "123456"
printf "\033[6D"
printf "\033[4h"
printf "ABC"
```
```
|____ABC1234|
```
### INSERT V-3: Writing on the Screen Edge
```bash
cols=$(tput cols)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[${cols}G"
printf "\033[6D"
printf "123456"
printf "\033[1D"
printf "\033[4h"
printf "ABC"
```
```
|____12345AB|
|Cc_________|
```
### INSERT V-3: Splitting a Multi-Cell Character
```bash
cols=$(tput cols)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[${cols}G"
printf "\033[6D"
printf "1234橋"
printf "\033[6D"
printf "\033[4h"
printf "A"
```
```
|_____A1234_|
```

View File

@ -13,6 +13,8 @@ A poorly behaved terminal program can lock the terminal emulator
using this command. Terminal emulators should provide a mechanism using this command. Terminal emulators should provide a mechanism
to reset this or outright disable it. to reset this or outright disable it.
This mode is typically disabled on terminal startup.
## Validation ## Validation
### KAM V-1: Disable Keyboard Input ### KAM V-1: Disable Keyboard Input

View File

@ -9,7 +9,7 @@ export default function VTMode({
<div className="flex my-2.5"> <div className="flex my-2.5">
<div className="border px-1 grid grid-rows-2 grid-cols-1 text-center"> <div className="border px-1 grid grid-rows-2 grid-cols-1 text-center">
<div> <div>
{ansi ? "?" : ""} {ansi ? "" : "?"}
{value} {value}
</div> </div>
</div> </div>