change u1 in mode to bool

This commit is contained in:
Mitchell Hashimoto
2022-08-26 11:27:44 -07:00
parent f9274bdafc
commit 43b7727cf8
2 changed files with 21 additions and 21 deletions

View File

@ -1069,7 +1069,7 @@ fn renderTimerCallback(t: *libuv.Timer) void {
win.grid.background = bg; win.grid.background = bg;
win.grid.foreground = fg; win.grid.foreground = fg;
} }
if (win.terminal.modes.reverse_colors == 1) { if (win.terminal.modes.reverse_colors) {
win.grid.background = fg; win.grid.background = fg;
win.grid.foreground = bg; win.grid.foreground = bg;
} }
@ -1080,7 +1080,7 @@ fn renderTimerCallback(t: *libuv.Timer) void {
g: f32, g: f32,
b: f32, b: f32,
a: f32, a: f32,
} = if (win.terminal.modes.reverse_colors == 1) .{ } = if (win.terminal.modes.reverse_colors) .{
.r = @intToFloat(f32, fg.r) / 255, .r = @intToFloat(f32, fg.r) / 255,
.g = @intToFloat(f32, fg.g) / 255, .g = @intToFloat(f32, fg.g) / 255,
.b = @intToFloat(f32, fg.b) / 255, .b = @intToFloat(f32, fg.b) / 255,
@ -1167,7 +1167,7 @@ pub fn setCursorCol(self: *Window, col: u16) !void {
} }
pub fn setCursorRow(self: *Window, row: u16) !void { pub fn setCursorRow(self: *Window, row: u16) !void {
if (self.terminal.modes.origin == 1) { if (self.terminal.modes.origin) {
// TODO // TODO
log.err("setCursorRow: implement origin mode", .{}); log.err("setCursorRow: implement origin mode", .{});
unreachable; unreachable;
@ -1234,19 +1234,19 @@ pub fn setTopAndBottomMargin(self: *Window, top: u16, bot: u16) !void {
pub fn setMode(self: *Window, mode: terminal.Mode, enabled: bool) !void { pub fn setMode(self: *Window, mode: terminal.Mode, enabled: bool) !void {
switch (mode) { switch (mode) {
.reverse_colors => { .reverse_colors => {
self.terminal.modes.reverse_colors = @boolToInt(enabled); self.terminal.modes.reverse_colors = enabled;
// Schedule a render since we changed colors // Schedule a render since we changed colors
try self.render_timer.schedule(); try self.render_timer.schedule();
}, },
.origin => { .origin => {
self.terminal.modes.origin = @boolToInt(enabled); self.terminal.modes.origin = enabled;
self.terminal.setCursorPos(1, 1); self.terminal.setCursorPos(1, 1);
}, },
.autowrap => { .autowrap => {
self.terminal.modes.autowrap = @boolToInt(enabled); self.terminal.modes.autowrap = enabled;
}, },
.cursor_visible => { .cursor_visible => {
@ -1323,7 +1323,7 @@ pub fn deviceStatusReport(
const pos: struct { const pos: struct {
x: usize, x: usize,
y: usize, y: usize,
} = if (self.terminal.modes.origin == 1) .{ } = if (self.terminal.modes.origin) .{
// TODO: what do we do if cursor is outside scrolling region? // TODO: what do we do if cursor is outside scrolling region?
.x = self.terminal.screen.cursor.x, .x = self.terminal.screen.cursor.x,
.y = self.terminal.screen.cursor.y -| self.terminal.scrolling_region.top, .y = self.terminal.screen.cursor.y -| self.terminal.scrolling_region.top,

View File

@ -61,12 +61,12 @@ scrolling_region: ScrollingRegion,
modes: packed struct { modes: packed struct {
const Self = @This(); const Self = @This();
reverse_colors: u1 = 0, // 5, reverse_colors: bool = false, // 5,
origin: u1 = 0, // 6 origin: bool = false, // 6
autowrap: u1 = 1, // 7 autowrap: bool = true, // 7
deccolm: u1 = 0, // 3, deccolm: bool = false, // 3,
deccolm_supported: u1 = 0, // 40 deccolm_supported: bool = false, // 40
mouse_event: MouseEvents = .none, mouse_event: MouseEvents = .none,
mouse_format: MouseFormat = .x10, mouse_format: MouseFormat = .x10,
@ -223,10 +223,10 @@ pub fn deccolm(self: *Terminal, alloc: Allocator, mode: DeccolmMode) !void {
// bit. If the mode "?40" is set, then "?3" (DECCOLM) is supported. This // bit. If the mode "?40" is set, then "?3" (DECCOLM) is supported. This
// doesn't exactly match VT100 semantics but modern terminals no longer // doesn't exactly match VT100 semantics but modern terminals no longer
// blindly accept mode 3 since its so weird in modern practice. // blindly accept mode 3 since its so weird in modern practice.
if (self.modes.deccolm_supported == 0) return; if (!self.modes.deccolm_supported) return;
// Enable it // Enable it
self.modes.deccolm = @enumToInt(mode); self.modes.deccolm = mode == .@"132_cols";
// Resize -- we can set cols to 0 because deccolm will force it // Resize -- we can set cols to 0 because deccolm will force it
try self.resize(alloc, 0, self.rows); try self.resize(alloc, 0, self.rows);
@ -243,7 +243,7 @@ pub fn setDeccolmSupported(self: *Terminal, v: bool) void {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
self.modes.deccolm_supported = @boolToInt(v); self.modes.deccolm_supported = v;
} }
/// Resize the underlying terminal. /// Resize the underlying terminal.
@ -254,8 +254,8 @@ pub fn resize(self: *Terminal, alloc: Allocator, cols_req: usize, rows: usize) !
// If we have deccolm supported then we are fixed at either 80 or 132 // If we have deccolm supported then we are fixed at either 80 or 132
// columns depending on if mode 3 is set or not. // columns depending on if mode 3 is set or not.
// TODO: test // TODO: test
const cols: usize = if (self.modes.deccolm_supported == 1) const cols: usize = if (self.modes.deccolm_supported)
@as(usize, if (self.modes.deccolm == 1) 132 else 80) @as(usize, if (self.modes.deccolm) 132 else 80)
else else
cols_req; cols_req;
@ -396,7 +396,7 @@ pub fn print(self: *Terminal, c: u21) !void {
if (width == 0) return; if (width == 0) return;
// If we're soft-wrapping, then handle that first. // If we're soft-wrapping, then handle that first.
if (self.screen.cursor.pending_wrap and self.modes.autowrap == 1) if (self.screen.cursor.pending_wrap and self.modes.autowrap)
_ = self.printWrap(); _ = self.printWrap();
switch (width) { switch (width) {
@ -624,7 +624,7 @@ pub fn setCursorPos(self: *Terminal, row_req: usize, col_req: usize) void {
y_offset: usize = 0, y_offset: usize = 0,
x_max: usize, x_max: usize,
y_max: usize, y_max: usize,
} = if (self.modes.origin == 1) .{ } = if (self.modes.origin) .{
.x_offset = 0, // TODO: left/right margins .x_offset = 0, // TODO: left/right margins
.y_offset = self.scrolling_region.top, .y_offset = self.scrolling_region.top,
.x_max = self.cols, // TODO: left/right margins .x_max = self.cols, // TODO: left/right margins
@ -656,7 +656,7 @@ pub fn setCursorColAbsolute(self: *Terminal, col_req: usize) void {
// TODO: test // TODO: test
assert(self.modes.origin == 0); // TODO assert(!self.modes.origin); // TODO
if (self.status_display != .main) return; // TODO if (self.status_display != .main) return; // TODO
@ -1351,7 +1351,7 @@ test "Terminal: setCursorPosition" {
try testing.expect(!t.screen.cursor.pending_wrap); try testing.expect(!t.screen.cursor.pending_wrap);
// Origin mode // Origin mode
t.modes.origin = 1; t.modes.origin = true;
// No change without a scroll region // No change without a scroll region
t.setCursorPos(81, 81); t.setCursorPos(81, 81);