mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
parse SGR really poorly
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
//! The primary terminal emulation structure. This represents a single
|
//! The primary terminal emulation structure. This represents a single
|
||||||
|
//!
|
||||||
//! "terminal" containing a grid of characters and exposes various operations
|
//! "terminal" containing a grid of characters and exposes various operations
|
||||||
//! on that grid. This also maintains the scrollback buffer.
|
//! on that grid. This also maintains the scrollback buffer.
|
||||||
const Terminal = @This();
|
const Terminal = @This();
|
||||||
@ -50,8 +51,12 @@ const Cell = struct {
|
|||||||
|
|
||||||
/// Cursor represents the cursor state.
|
/// Cursor represents the cursor state.
|
||||||
const Cursor = struct {
|
const Cursor = struct {
|
||||||
|
// x, y where the cursor currently exists (0-indexed).
|
||||||
x: usize,
|
x: usize,
|
||||||
y: usize,
|
y: usize,
|
||||||
|
|
||||||
|
// Bold specifies that text written should be bold
|
||||||
|
bold: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initialize a new terminal.
|
/// Initialize a new terminal.
|
||||||
@ -212,6 +217,20 @@ fn csiDispatch(
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// SGR - Select Graphic Rendition
|
||||||
|
'm' => if (action.params.len == 0) {
|
||||||
|
// No values defaults to code 0
|
||||||
|
try self.selectGraphicRendition(.default);
|
||||||
|
} else {
|
||||||
|
// Each parameter sets a separate aspect
|
||||||
|
for (action.params) |param| {
|
||||||
|
try self.selectGraphicRendition(@intToEnum(
|
||||||
|
ansi.RenditionAspect,
|
||||||
|
param,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
else => log.warn("unimplemented CSI: {}", .{action}),
|
else => log.warn("unimplemented CSI: {}", .{action}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,6 +274,16 @@ pub fn bell(self: *Terminal) void {
|
|||||||
log.info("bell", .{});
|
log.info("bell", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn selectGraphicRendition(self: *Terminal, aspect: ansi.RenditionAspect) !void {
|
||||||
|
switch (aspect) {
|
||||||
|
.default => self.cursor.bold = false,
|
||||||
|
.bold => self.cursor.bold = true,
|
||||||
|
.default_fg => {}, // TODO
|
||||||
|
.default_bg => {}, // TODO
|
||||||
|
else => log.warn("invalid or unimplemented rendition aspect: {}", .{aspect}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set Cursor Position. Move cursor to the position indicated
|
// Set Cursor Position. Move cursor to the position indicated
|
||||||
// by row and column (1-indexed). If column is 0, it is adjusted to 1.
|
// by row and column (1-indexed). If column is 0, it is adjusted to 1.
|
||||||
// If column is greater than the right-most column it is adjusted to
|
// If column is greater than the right-most column it is adjusted to
|
||||||
|
@ -16,3 +16,16 @@ pub const C0 = enum(u7) {
|
|||||||
/// Carriage return
|
/// Carriage return
|
||||||
CR = 0x0D,
|
CR = 0x0D,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The SGR rendition aspects that can be set, sometimes known as attributes.
|
||||||
|
/// The value corresponds to the parameter value for the SGR command (ESC [ m).
|
||||||
|
pub const RenditionAspect = enum(u16) {
|
||||||
|
default = 0,
|
||||||
|
bold = 1,
|
||||||
|
default_fg = 39,
|
||||||
|
default_bg = 49,
|
||||||
|
|
||||||
|
// Non-exhaustive so that @intToEnum never fails since the inputs are
|
||||||
|
// user-generated.
|
||||||
|
_,
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user