mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
use packed struct for modes
This commit is contained in:
@ -607,7 +607,7 @@ fn renderTimerCallback(t: *libuv.Timer) void {
|
||||
win.grid.background = bg;
|
||||
win.grid.foreground = fg;
|
||||
}
|
||||
if (win.terminal.mode_reverse_colors) {
|
||||
if (win.terminal.modes.reverse_colors == 1) {
|
||||
win.grid.background = fg;
|
||||
win.grid.foreground = bg;
|
||||
}
|
||||
@ -618,7 +618,7 @@ fn renderTimerCallback(t: *libuv.Timer) void {
|
||||
g: f32,
|
||||
b: f32,
|
||||
a: f32,
|
||||
} = if (win.terminal.mode_reverse_colors) .{
|
||||
} = if (win.terminal.modes.reverse_colors == 1) .{
|
||||
.r = @intToFloat(f32, fg.r) / 255,
|
||||
.g = @intToFloat(f32, fg.g) / 255,
|
||||
.b = @intToFloat(f32, fg.b) / 255,
|
||||
@ -699,12 +699,12 @@ pub fn setCursorUp(self: *Window, amount: u16) !void {
|
||||
}
|
||||
|
||||
pub fn setCursorCol(self: *Window, col: u16) !void {
|
||||
if (self.terminal.mode_origin) unreachable; // TODO
|
||||
if (self.terminal.modes.origin == 1) unreachable; // TODO
|
||||
self.terminal.setCursorPos(self.terminal.cursor.y + 1, col);
|
||||
}
|
||||
|
||||
pub fn setCursorRow(self: *Window, row: u16) !void {
|
||||
if (self.terminal.mode_origin) unreachable; // TODO
|
||||
if (self.terminal.modes.origin == 1) unreachable; // TODO
|
||||
self.terminal.setCursorPos(row, self.terminal.cursor.x + 1);
|
||||
}
|
||||
|
||||
@ -756,19 +756,19 @@ pub fn setTopAndBottomMargin(self: *Window, top: u16, bot: u16) !void {
|
||||
pub fn setMode(self: *Window, mode: terminal.Mode, enabled: bool) !void {
|
||||
switch (mode) {
|
||||
.reverse_colors => {
|
||||
self.terminal.mode_reverse_colors = enabled;
|
||||
self.terminal.modes.reverse_colors = @boolToInt(enabled);
|
||||
|
||||
// Schedule a render since we changed colors
|
||||
try self.render_timer.schedule();
|
||||
},
|
||||
|
||||
.origin => {
|
||||
self.terminal.mode_origin = enabled;
|
||||
self.terminal.modes.origin = @boolToInt(enabled);
|
||||
self.terminal.setCursorPos(1, 1);
|
||||
},
|
||||
|
||||
.autowrap => {
|
||||
self.terminal.mode_autowrap = enabled;
|
||||
self.terminal.modes.autowrap = @boolToInt(enabled);
|
||||
},
|
||||
|
||||
.bracketed_paste => self.bracketed_paste = true,
|
||||
@ -812,7 +812,7 @@ pub fn deviceStatusReport(
|
||||
const pos: struct {
|
||||
x: usize,
|
||||
y: usize,
|
||||
} = if (self.terminal.mode_origin) .{
|
||||
} = if (self.terminal.modes.origin == 1) .{
|
||||
// TODO: what do we do if cursor is outside scrolling region?
|
||||
.x = self.terminal.cursor.x,
|
||||
.y = self.terminal.cursor.y -| self.terminal.scrolling_region.top,
|
||||
|
@ -41,11 +41,13 @@ cols: usize,
|
||||
/// The current scrolling region.
|
||||
scrolling_region: ScrollingRegion,
|
||||
|
||||
/// Modes
|
||||
// TODO: turn into a bitset probably
|
||||
mode_origin: bool = false,
|
||||
mode_autowrap: bool = true,
|
||||
mode_reverse_colors: bool = false,
|
||||
/// Modes - This isn't exhaustive, since some modes (i.e. cursor origin)
|
||||
/// are applied to the cursor and others aren't boolean yes/no.
|
||||
modes: packed struct {
|
||||
reverse_colors: u1 = 0, // 5,
|
||||
origin: u1 = 0, // 6
|
||||
autowrap: u1 = 1, // 7
|
||||
} = .{},
|
||||
|
||||
/// Scrolling region is the area of the screen designated where scrolling
|
||||
/// occurs. Wen scrolling the screen, only this viewport is scrolled.
|
||||
@ -207,7 +209,7 @@ pub fn print(self: *Terminal, c: u21) !void {
|
||||
if (!self.screen.displayIsBottom()) self.screen.scroll(.{ .bottom = {} });
|
||||
|
||||
// If we're soft-wrapping, then handle that first.
|
||||
if (self.cursor.pending_wrap and self.mode_autowrap) {
|
||||
if (self.cursor.pending_wrap and self.modes.autowrap == 1) {
|
||||
// Mark that the cell is wrapped, which guarantees that there is
|
||||
// at least one cell after it in the next row.
|
||||
const cell = self.screen.getCell(self.cursor.y, self.cursor.x);
|
||||
@ -329,7 +331,7 @@ pub fn setCursorPos(self: *Terminal, row: usize, col: usize) void {
|
||||
y_offset: usize = 0,
|
||||
x_max: usize,
|
||||
y_max: usize,
|
||||
} = if (self.mode_origin) .{
|
||||
} = if (self.modes.origin == 1) .{
|
||||
.x_offset = 0, // TODO: left/right margins
|
||||
.x_max = self.cols, // TODO: left/right margins
|
||||
.y_offset = self.scrolling_region.top + 1,
|
||||
@ -904,7 +906,7 @@ test "Terminal: setCursorPosition" {
|
||||
try testing.expect(!t.cursor.pending_wrap);
|
||||
|
||||
// Origin mode
|
||||
t.mode_origin = true;
|
||||
t.modes.origin = 1;
|
||||
|
||||
// No change without a scroll region
|
||||
t.setCursorPos(81, 81);
|
||||
|
Reference in New Issue
Block a user