mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
terminal: test REP
This commit is contained in:
@ -856,11 +856,10 @@ fn clearWideSpacerHead(self: *Terminal) void {
|
||||
}
|
||||
|
||||
/// Print the previous printed character a repeated amount of times.
|
||||
pub fn printRepeat(self: *Terminal, count: usize) !void {
|
||||
// TODO: test
|
||||
pub fn printRepeat(self: *Terminal, count_req: usize) !void {
|
||||
if (self.previous_char) |c| {
|
||||
var i: usize = 0;
|
||||
while (i < count) : (i += 1) try self.print(c);
|
||||
const count = @max(count_req, 1);
|
||||
for (0..count) |_| try self.print(c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6082,3 +6081,47 @@ test "Terminal: tabClear all" {
|
||||
try t.horizontalTab();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
53
website/app/vt/rep/page.mdx
Normal file
53
website/app/vt/rep/page.mdx
Normal 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________|
|
||||
```
|
Reference in New Issue
Block a user