terminal: test REP

This commit is contained in:
Mitchell Hashimoto
2023-10-11 17:23:27 -07:00
parent d6f7b45a64
commit 96546af475
2 changed files with 100 additions and 4 deletions

View File

@ -856,11 +856,10 @@ fn clearWideSpacerHead(self: *Terminal) void {
} }
/// Print the previous printed character a repeated amount of times. /// Print the previous printed character a repeated amount of times.
pub fn printRepeat(self: *Terminal, count: usize) !void { pub fn printRepeat(self: *Terminal, count_req: usize) !void {
// TODO: test
if (self.previous_char) |c| { if (self.previous_char) |c| {
var i: usize = 0; const count = @max(count_req, 1);
while (i < count) : (i += 1) try self.print(c); for (0..count) |_| try self.print(c);
} }
} }
@ -6082,3 +6081,47 @@ test "Terminal: tabClear all" {
try t.horizontalTab(); try t.horizontalTab();
try testing.expectEqual(@as(usize, 29), t.screen.cursor.x); try testing.expectEqual(@as(usize, 29), t.screen.cursor.x);
} }
test "Terminal: printRepeat simple" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString("A");
try t.printRepeat(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("AA", str);
}
}
test "Terminal: printRepeat wrap" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString(" A");
try t.printRepeat(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings(" A\nA", str);
}
}
test "Terminal: printRepeat no previous character" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printRepeat(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("", str);
}
}

View File

@ -0,0 +1,53 @@
import VTSequence from "@/components/VTSequence";
# Repeat Previous Character (REP)
<VTSequence sequence={["CSI", "Pn", "b"]} />
Repeat the previously printed character `n` times.
The parameter `n` must be an integer greater than or equal to 1. If `n` is less than
or equal to 0, adjust `n` to be 1. If `n` is omitted, `n` defaults to 1.
In xterm, only characters with single byte (less than decimal 256) are
supported. In most other mainstream terminals, any character is supported.
Each repeated character behaves identically to if it was manually typed in.
Therefore, soft-wrapping, margins, etc. all behave the same as if the
character was typed.
The previously printed character is any character that is printed through
any means. The previously printed character is not limited to characters
a user manually types. If there is no previously typed character, this sequence
does nothing.
## Validation
### REP V-1: Simple Usage
```bash
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "A"
printf "\033[b"
```
```
|AAc_______|
```
### REP V-2: Soft-Wrap
```bash
cols=$(tput cols)
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "\033[${cols}G"
printf "A"
printf "\033[b"
```
```
|_________A|
|Ac________|
```