mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-22 19:56:08 +03:00
terminal: implement origin mode and left margin handling for CR
This commit is contained in:
@ -1534,11 +1534,16 @@ pub fn carriageReturn(self: *Terminal) void {
|
|||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
// TODO: left/right margin mode
|
// Always reset pending wrap state
|
||||||
// TODO: origin mode
|
|
||||||
|
|
||||||
self.screen.cursor.x = 0;
|
|
||||||
self.screen.cursor.pending_wrap = false;
|
self.screen.cursor.pending_wrap = false;
|
||||||
|
|
||||||
|
// In origin mode we always move to the left margin
|
||||||
|
self.screen.cursor.x = if (self.modes.get(.origin))
|
||||||
|
self.scrolling_region.left
|
||||||
|
else if (self.screen.cursor.x >= self.scrolling_region.left)
|
||||||
|
self.scrolling_region.left
|
||||||
|
else
|
||||||
|
0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Linefeed moves the cursor to the next line.
|
/// Linefeed moves the cursor to the next line.
|
||||||
@ -2207,6 +2212,37 @@ test "Terminal: carriage return unsets pending wrap" {
|
|||||||
try testing.expect(t.screen.cursor.pending_wrap == false);
|
try testing.expect(t.screen.cursor.pending_wrap == false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Terminal: carriage return origin mode moves to left margin" {
|
||||||
|
var t = try init(testing.allocator, 5, 80);
|
||||||
|
defer t.deinit(testing.allocator);
|
||||||
|
|
||||||
|
t.modes.set(.origin, true);
|
||||||
|
t.screen.cursor.x = 0;
|
||||||
|
t.scrolling_region.left = 2;
|
||||||
|
t.carriageReturn();
|
||||||
|
try testing.expectEqual(@as(usize, 2), t.screen.cursor.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Terminal: carriage return left of left margin moves to zero" {
|
||||||
|
var t = try init(testing.allocator, 5, 80);
|
||||||
|
defer t.deinit(testing.allocator);
|
||||||
|
|
||||||
|
t.screen.cursor.x = 1;
|
||||||
|
t.scrolling_region.left = 2;
|
||||||
|
t.carriageReturn();
|
||||||
|
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Terminal: carriage return right of left margin moves to left margin" {
|
||||||
|
var t = try init(testing.allocator, 5, 80);
|
||||||
|
defer t.deinit(testing.allocator);
|
||||||
|
|
||||||
|
t.screen.cursor.x = 3;
|
||||||
|
t.scrolling_region.left = 2;
|
||||||
|
t.carriageReturn();
|
||||||
|
try testing.expectEqual(@as(usize, 2), t.screen.cursor.x);
|
||||||
|
}
|
||||||
|
|
||||||
test "Terminal: backspace" {
|
test "Terminal: backspace" {
|
||||||
var t = try init(testing.allocator, 80, 80);
|
var t = try init(testing.allocator, 80, 80);
|
||||||
defer t.deinit(testing.allocator);
|
defer t.deinit(testing.allocator);
|
||||||
|
Reference in New Issue
Block a user