mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
implement CUD, CUU
This commit is contained in:
@ -525,6 +525,14 @@ pub fn setCursorRight(self: *Window, amount: u16) !void {
|
|||||||
self.terminal.cursorRight(amount);
|
self.terminal.cursorRight(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setCursorDown(self: *Window, amount: u16) !void {
|
||||||
|
self.terminal.cursorDown(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn setCursorUp(self: *Window, amount: u16) !void {
|
||||||
|
self.terminal.cursorUp(amount);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setCursorCol(self: *Window, col: u16) !void {
|
pub fn setCursorCol(self: *Window, col: u16) !void {
|
||||||
try self.terminal.setCursorPos(self.terminal.cursor.y + 1, col);
|
try self.terminal.setCursorPos(self.terminal.cursor.y + 1, col);
|
||||||
}
|
}
|
||||||
|
@ -295,11 +295,36 @@ pub fn cursorRight(self: *Terminal, count: usize) void {
|
|||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
self.cursor.x += count;
|
self.cursor.x += count;
|
||||||
if (self.cursor.x == self.cols) {
|
if (self.cursor.x >= self.cols) {
|
||||||
self.cursor.x -= 1;
|
self.cursor.x = self.cols - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Move the cursor down amount lines. If amount is greater than the maximum
|
||||||
|
/// move distance then it is internally adjusted to the maximum. This sequence
|
||||||
|
/// will not scroll the screen or scroll region. If amount is 0, adjust it to 1.
|
||||||
|
// TODO: test
|
||||||
|
pub fn cursorDown(self: *Terminal, count: usize) void {
|
||||||
|
const tracy = trace(@src());
|
||||||
|
defer tracy.end();
|
||||||
|
|
||||||
|
self.cursor.y += count;
|
||||||
|
if (self.cursor.y >= self.rows) {
|
||||||
|
self.cursor.y = self.rows - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Move the cursor up amount lines. If amount is greater than the maximum
|
||||||
|
/// move distance then it is internally adjusted to the maximum. If amount is
|
||||||
|
/// 0, adjust it to 1.
|
||||||
|
// TODO: test
|
||||||
|
pub fn cursorUp(self: *Terminal, count: usize) void {
|
||||||
|
const tracy = trace(@src());
|
||||||
|
defer tracy.end();
|
||||||
|
|
||||||
|
self.cursor.y -|= count;
|
||||||
|
}
|
||||||
|
|
||||||
/// Backspace moves the cursor back a column (but not less than 0).
|
/// Backspace moves the cursor back a column (but not less than 0).
|
||||||
pub fn backspace(self: *Terminal) void {
|
pub fn backspace(self: *Terminal) void {
|
||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
|
@ -94,6 +94,30 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
|
|
||||||
fn csiDispatch(self: *Self, action: Parser.Action.CSI) !void {
|
fn csiDispatch(self: *Self, action: Parser.Action.CSI) !void {
|
||||||
switch (action.final) {
|
switch (action.final) {
|
||||||
|
// CUU - Cursor Up
|
||||||
|
'A' => if (@hasDecl(T, "setCursorUp")) try self.handler.setCursorUp(
|
||||||
|
switch (action.params.len) {
|
||||||
|
0 => 1,
|
||||||
|
1 => action.params[0],
|
||||||
|
else => {
|
||||||
|
log.warn("invalid cursor up command: {}", .{action});
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
) else log.warn("unimplemented CSI callback: {}", .{action}),
|
||||||
|
|
||||||
|
// CUD - Cursor Down
|
||||||
|
'B' => if (@hasDecl(T, "setCursorDown")) try self.handler.setCursorDown(
|
||||||
|
switch (action.params.len) {
|
||||||
|
0 => 1,
|
||||||
|
1 => action.params[0],
|
||||||
|
else => {
|
||||||
|
log.warn("invalid cursor down command: {}", .{action});
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
) else log.warn("unimplemented CSI callback: {}", .{action}),
|
||||||
|
|
||||||
// CUF - Cursor Right
|
// CUF - Cursor Right
|
||||||
'C' => if (@hasDecl(T, "setCursorRight")) try self.handler.setCursorRight(
|
'C' => if (@hasDecl(T, "setCursorRight")) try self.handler.setCursorRight(
|
||||||
switch (action.params.len) {
|
switch (action.params.len) {
|
||||||
|
Reference in New Issue
Block a user