mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fixing more bugs
This commit is contained in:
15
conformance/csi_decstbm.zig
Normal file
15
conformance/csi_decstbm.zig
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//! Set Top and Bottom Margins (DECSTBM) - ESC [ r
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
const stdout = std.io.getStdOut().writer();
|
||||||
|
try stdout.print("A\nB\nC\nD", .{});
|
||||||
|
try stdout.print("\x1B[1;3r", .{}); // cursor up
|
||||||
|
try stdout.print("\x1B[1;1H", .{}); // top-left
|
||||||
|
try stdout.print("\x1B[M", .{}); // delete line
|
||||||
|
try stdout.print("E\n", .{});
|
||||||
|
try stdout.print("\x1B[7;1H", .{}); // cursor up
|
||||||
|
|
||||||
|
// const stdin = std.io.getStdIn().reader();
|
||||||
|
// _ = try stdin.readByte();
|
||||||
|
}
|
@ -664,7 +664,7 @@ pub fn insertLines(self: *Window, count: usize) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn deleteLines(self: *Window, count: usize) !void {
|
pub fn deleteLines(self: *Window, count: usize) !void {
|
||||||
self.terminal.deleteLines(self.alloc, count);
|
self.terminal.deleteLines(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reverseIndex(self: *Window) !void {
|
pub fn reverseIndex(self: *Window) !void {
|
||||||
|
@ -488,7 +488,7 @@ pub fn insertLines(self: *Terminal, alloc: Allocator, count: usize) !void {
|
|||||||
/// cleared space is colored according to the current SGR state.
|
/// cleared space is colored according to the current SGR state.
|
||||||
///
|
///
|
||||||
/// Moves the cursor to the left margin.
|
/// Moves the cursor to the left margin.
|
||||||
pub fn deleteLines(self: *Terminal, alloc: Allocator, count: usize) void {
|
pub fn deleteLines(self: *Terminal, count: usize) void {
|
||||||
// TODO: scroll region bounds
|
// TODO: scroll region bounds
|
||||||
|
|
||||||
// Move the cursor to the left margin
|
// Move the cursor to the left margin
|
||||||
@ -504,7 +504,6 @@ pub fn deleteLines(self: *Terminal, alloc: Allocator, count: usize) void {
|
|||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (i < count2) : (i += 1) {
|
while (i < count2) : (i += 1) {
|
||||||
self.scrollUpRegion(
|
self.scrollUpRegion(
|
||||||
alloc,
|
|
||||||
self.cursor.y,
|
self.cursor.y,
|
||||||
self.scrolling_region.bottom,
|
self.scrolling_region.bottom,
|
||||||
);
|
);
|
||||||
@ -526,15 +525,12 @@ pub fn scrollUp(self: *Terminal) void {
|
|||||||
/// Top and bottom are 0-indexed.
|
/// Top and bottom are 0-indexed.
|
||||||
fn scrollUpRegion(
|
fn scrollUpRegion(
|
||||||
self: *Terminal,
|
self: *Terminal,
|
||||||
alloc: Allocator,
|
|
||||||
top: usize,
|
top: usize,
|
||||||
bottom: usize,
|
bottom: usize,
|
||||||
) void {
|
) void {
|
||||||
const tracy = trace(@src());
|
const tracy = trace(@src());
|
||||||
defer tracy.end();
|
defer tracy.end();
|
||||||
|
|
||||||
_ = alloc;
|
|
||||||
|
|
||||||
// Only go to the end of the region OR the end of our lines.
|
// Only go to the end of the region OR the end of our lines.
|
||||||
const end = @minimum(bottom, self.screen.rows - 1);
|
const end = @minimum(bottom, self.screen.rows - 1);
|
||||||
|
|
||||||
@ -544,10 +540,8 @@ fn scrollUpRegion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Blank our last line if we have space.
|
// Blank our last line if we have space.
|
||||||
if (i < self.screen.rows) {
|
const row = self.screen.getRow(i);
|
||||||
const row = self.screen.getRow(i);
|
for (row) |*cell| cell.char = 0;
|
||||||
for (row) |*cell| cell.char = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scroll the text down by one row.
|
/// Scroll the text down by one row.
|
||||||
@ -706,7 +700,7 @@ test "Terminal: setScrollingRegion" {
|
|||||||
try testing.expectEqual(@as(usize, t.rows - 1), t.scrolling_region.bottom);
|
try testing.expectEqual(@as(usize, t.rows - 1), t.scrolling_region.bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "Terminal: setScrollingRegion" {
|
test "Terminal: deleteLines" {
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
var t = try init(alloc, 80, 80);
|
var t = try init(alloc, 80, 80);
|
||||||
defer t.deinit(alloc);
|
defer t.deinit(alloc);
|
||||||
@ -724,7 +718,7 @@ test "Terminal: setScrollingRegion" {
|
|||||||
try t.print('D');
|
try t.print('D');
|
||||||
|
|
||||||
t.cursorUp(2);
|
t.cursorUp(2);
|
||||||
t.deleteLines(alloc, 1);
|
t.deleteLines(1);
|
||||||
|
|
||||||
try t.print('E');
|
try t.print('E');
|
||||||
t.carriageReturn();
|
t.carriageReturn();
|
||||||
@ -741,6 +735,42 @@ test "Terminal: setScrollingRegion" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Terminal: deleteLines with scroll region" {
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
var t = try init(alloc, 80, 80);
|
||||||
|
defer t.deinit(alloc);
|
||||||
|
|
||||||
|
// Initial value
|
||||||
|
try t.print('A');
|
||||||
|
t.carriageReturn();
|
||||||
|
t.linefeed();
|
||||||
|
try t.print('B');
|
||||||
|
t.carriageReturn();
|
||||||
|
t.linefeed();
|
||||||
|
try t.print('C');
|
||||||
|
t.carriageReturn();
|
||||||
|
t.linefeed();
|
||||||
|
try t.print('D');
|
||||||
|
|
||||||
|
t.setScrollingRegion(1, 3);
|
||||||
|
t.setCursorPos(1, 1);
|
||||||
|
t.deleteLines(1);
|
||||||
|
|
||||||
|
try t.print('E');
|
||||||
|
t.carriageReturn();
|
||||||
|
t.linefeed();
|
||||||
|
|
||||||
|
// We should be
|
||||||
|
// try testing.expectEqual(@as(usize, 0), t.cursor.x);
|
||||||
|
// try testing.expectEqual(@as(usize, 2), t.cursor.y);
|
||||||
|
|
||||||
|
{
|
||||||
|
var str = try t.plainString(testing.allocator);
|
||||||
|
defer testing.allocator.free(str);
|
||||||
|
try testing.expectEqualStrings("E\nC\n\nD", str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "Terminal: insertLines" {
|
test "Terminal: insertLines" {
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
var t = try init(alloc, 2, 5);
|
var t = try init(alloc, 2, 5);
|
||||||
|
@ -48,7 +48,11 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
//log.debug("char: {x}", .{c});
|
//log.debug("char: {x}", .{c});
|
||||||
const actions = self.parser.next(c);
|
const actions = self.parser.next(c);
|
||||||
for (actions) |action_opt| {
|
for (actions) |action_opt| {
|
||||||
if (action_opt) |action| log.info("action: {}", .{action});
|
if (action_opt) |action| {
|
||||||
|
if (action != .print) {
|
||||||
|
log.info("action: {}", .{action});
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (action_opt orelse continue) {
|
switch (action_opt orelse continue) {
|
||||||
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
|
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
|
||||||
.execute => |code| try self.execute(code),
|
.execute => |code| try self.execute(code),
|
||||||
|
Reference in New Issue
Block a user