mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
terminal: horizontalTabBack function
This commit is contained in:
@ -1218,6 +1218,21 @@ pub fn horizontalTab(self: *Terminal) !void {
|
||||
}
|
||||
}
|
||||
|
||||
// Same as horizontalTab but moves to the previous tabstop instead of the next.
|
||||
pub fn horizontalTabBack(self: *Terminal) !void {
|
||||
const tracy = trace(@src());
|
||||
defer tracy.end();
|
||||
|
||||
while (true) {
|
||||
// If we're already at the edge of the screen, then we're done.
|
||||
if (self.screen.cursor.x == 0) return;
|
||||
|
||||
// Move the cursor left
|
||||
self.screen.cursor.x -= 1;
|
||||
if (self.tabstops.get(self.screen.cursor.x)) return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear tab stops.
|
||||
/// TODO: test
|
||||
pub fn tabClear(self: *Terminal, cmd: csi.TabClear) void {
|
||||
@ -1798,6 +1813,29 @@ test "Terminal: horizontal tabs" {
|
||||
try testing.expectEqual(@as(usize, 19), t.screen.cursor.x);
|
||||
}
|
||||
|
||||
test "Terminal: horizontal tabs back" {
|
||||
const alloc = testing.allocator;
|
||||
var t = try init(alloc, 20, 5);
|
||||
defer t.deinit(alloc);
|
||||
|
||||
// Edge of screen
|
||||
t.screen.cursor.x = 19;
|
||||
|
||||
// HT
|
||||
try t.horizontalTabBack();
|
||||
try testing.expectEqual(@as(usize, 15), t.screen.cursor.x);
|
||||
|
||||
// HT
|
||||
try t.horizontalTabBack();
|
||||
try testing.expectEqual(@as(usize, 7), t.screen.cursor.x);
|
||||
|
||||
// HT
|
||||
try t.horizontalTabBack();
|
||||
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||
try t.horizontalTabBack();
|
||||
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||
}
|
||||
|
||||
test "Terminal: setCursorPosition" {
|
||||
var t = try init(testing.allocator, 80, 80);
|
||||
defer t.deinit(testing.allocator);
|
||||
|
Reference in New Issue
Block a user