Compare commits

..

No commits in common. "e76daa879944760ebfdaf2c44140714725b539f7" and "8b9cc87cabb45baa48864b8bb799f243a02f580c" have entirely different histories.

4 changed files with 38 additions and 31 deletions

View file

@ -14,7 +14,7 @@ highlight_current_line_gutter: bool = true,
highlight_columns: []const u16 = &.{ 80, 100, 120 }, highlight_columns: []const u16 = &.{ 80, 100, 120 },
highlight_columns_alpha: u8 = 240, highlight_columns_alpha: u8 = 240,
highlight_columns_enabled: bool = false, highlight_columns_enabled: bool = false,
whitespace_mode: WhitespaceMode = .indent, whitespace_mode: []const u8 = "none",
inline_diagnostics: bool = true, inline_diagnostics: bool = true,
animation_min_lag: usize = 0, //milliseconds animation_min_lag: usize = 0, //milliseconds
animation_max_lag: usize = 50, //milliseconds animation_max_lag: usize = 50, //milliseconds
@ -48,7 +48,6 @@ pane_right_style: WidgetStyle = .bar_left,
centered_view: bool = false, centered_view: bool = false,
centered_view_width: usize = 145, centered_view_width: usize = 145,
centered_view_min_screen_width: usize = 145,
lsp_output: enum { quiet, verbose } = .quiet, lsp_output: enum { quiet, verbose } = .quiet,
@ -104,13 +103,3 @@ pub const WidgetStyle = enum {
spacious, spacious,
compact, compact,
}; };
pub const WhitespaceMode = enum {
indent,
leading,
eol,
tabs,
visible,
full,
none,
};

View file

@ -25,7 +25,6 @@ const Widget = @import("Widget.zig");
const WidgetList = @import("WidgetList.zig"); const WidgetList = @import("WidgetList.zig");
const tui = @import("tui.zig"); const tui = @import("tui.zig");
const IndentMode = @import("config").IndentMode; const IndentMode = @import("config").IndentMode;
const WhitespaceMode = @import("config").WhitespaceMode;
pub const Cursor = Buffer.Cursor; pub const Cursor = Buffer.Cursor;
pub const View = Buffer.View; pub const View = Buffer.View;
@ -409,6 +408,7 @@ pub const Editor = struct {
} = null, } = null,
} = null, } = null,
const WhitespaceMode = enum { indent, leading, eol, tabs, visible, full, none };
const StyleCache = std.AutoHashMap(u32, ?Widget.Theme.Token); const StyleCache = std.AutoHashMap(u32, ?Widget.Theme.Token);
const Context = command.Context; const Context = command.Context;
@ -539,7 +539,7 @@ pub const Editor = struct {
.animation_last_time = time.microTimestamp(), .animation_last_time = time.microTimestamp(),
.enable_format_on_save = tui.config().enable_format_on_save, .enable_format_on_save = tui.config().enable_format_on_save,
.enable_terminal_cursor = tui.config().enable_terminal_cursor, .enable_terminal_cursor = tui.config().enable_terminal_cursor,
.render_whitespace = tui.config().whitespace_mode, .render_whitespace = from_whitespace_mode(tui.config().whitespace_mode),
}; };
} }
@ -558,6 +558,23 @@ pub const Editor = struct {
if (self.buffer) |p| self.buffer_manager.retire(p, meta.written()); if (self.buffer) |p| self.buffer_manager.retire(p, meta.written());
} }
fn from_whitespace_mode(whitespace_mode: []const u8) WhitespaceMode {
return if (std.mem.eql(u8, whitespace_mode, "indent"))
.indent
else if (std.mem.eql(u8, whitespace_mode, "leading"))
.leading
else if (std.mem.eql(u8, whitespace_mode, "eol"))
.eol
else if (std.mem.eql(u8, whitespace_mode, "tabs"))
.tabs
else if (std.mem.eql(u8, whitespace_mode, "visible"))
.visible
else if (std.mem.eql(u8, whitespace_mode, "full"))
.full
else
.none;
}
pub fn need_render(_: *Self) void { pub fn need_render(_: *Self) void {
Widget.need_render(); Widget.need_render();
} }
@ -6461,7 +6478,6 @@ pub const EditorWidget = struct {
var ypx: c_int = undefined; var ypx: c_int = undefined;
var pos: u32 = 0; var pos: u32 = 0;
var bytes: []const u8 = ""; var bytes: []const u8 = "";
var whitespace_mode: WhitespaceMode = .none;
if (try m.match(.{ "M", tp.extract(&x), tp.extract(&y), tp.extract(&xpx), tp.extract(&ypx) })) { if (try m.match(.{ "M", tp.extract(&x), tp.extract(&y), tp.extract(&xpx), tp.extract(&ypx) })) {
const hover_y, const hover_x = self.editor.plane.abs_yx_to_rel(y, x); const hover_y, const hover_x = self.editor.plane.abs_yx_to_rel(y, x);
@ -6510,8 +6526,8 @@ pub const EditorWidget = struct {
try self.editor.highlight_references(.{}); try self.editor.highlight_references(.{});
}, },
}; };
} else if (try m.match(.{ "whitespace_mode", tp.extract(&whitespace_mode) })) { } else if (try m.match(.{ "whitespace_mode", tp.extract(&bytes) })) {
self.editor.render_whitespace = whitespace_mode; self.editor.render_whitespace = Editor.from_whitespace_mode(bytes);
} else { } else {
return false; return false;
} }

View file

@ -195,10 +195,7 @@ pub fn update_panes_layout(self: *Self) !void {
const centered_view_width = tui.config().centered_view_width; const centered_view_width = tui.config().centered_view_width;
const screen_width = tui.screen().w; const screen_width = tui.screen().w;
const need_padding = screen_width > centered_view_width; const need_padding = screen_width > centered_view_width;
const have_vsplits = self.views.widgets.items.len > 1; if (need_padding and tui.config().centered_view and self.views.widgets.items.len == 1) {
const have_min_screen_width = screen_width > tui.config().centered_view_min_screen_width;
const centered_view = need_padding and tui.config().centered_view and !have_vsplits and have_min_screen_width;
if (centered_view) {
const padding = (screen_width - centered_view_width) / 2; const padding = (screen_width - centered_view_width) / 2;
try self.panes.add(try self.create_padding_pane(padding, .pane_left)); try self.panes.add(try self.create_padding_pane(padding, .pane_left));
try self.panes.add(self.views_widget); try self.panes.add(self.views_widget);

View file

@ -990,20 +990,25 @@ const cmds = struct {
pub const theme_prev_meta: Meta = .{ .description = "Previous color theme" }; pub const theme_prev_meta: Meta = .{ .description = "Previous color theme" };
pub fn toggle_whitespace_mode(self: *Self, _: Ctx) Result { pub fn toggle_whitespace_mode(self: *Self, _: Ctx) Result {
self.config_.whitespace_mode = switch (self.config_.whitespace_mode) { self.config_.whitespace_mode = if (std.mem.eql(u8, self.config_.whitespace_mode, "none"))
.none => .indent, "indent"
.indent => .leading, else if (std.mem.eql(u8, self.config_.whitespace_mode, "indent"))
.leading => .eol, "leading"
.eol => .tabs, else if (std.mem.eql(u8, self.config_.whitespace_mode, "leading"))
.tabs => .visible, "eol"
.visible => .full, else if (std.mem.eql(u8, self.config_.whitespace_mode, "eol"))
.full => .none, "tabs"
}; else if (std.mem.eql(u8, self.config_.whitespace_mode, "tabs"))
"visible"
else if (std.mem.eql(u8, self.config_.whitespace_mode, "visible"))
"full"
else
"none";
try save_config(); try save_config();
var buf: [32]u8 = undefined; var buf: [32]u8 = undefined;
const m = try tp.message.fmtbuf(&buf, .{ "whitespace_mode", self.config_.whitespace_mode }); const m = try tp.message.fmtbuf(&buf, .{ "whitespace_mode", self.config_.whitespace_mode });
_ = try self.send_widgets(tp.self_pid(), m); _ = try self.send_widgets(tp.self_pid(), m);
self.logger.print("whitespace rendering {s}", .{@tagName(self.config_.whitespace_mode)}); self.logger.print("whitespace rendering {s}", .{self.config_.whitespace_mode});
} }
pub const toggle_whitespace_mode_meta: Meta = .{ .description = "Next whitespace mode" }; pub const toggle_whitespace_mode_meta: Meta = .{ .description = "Next whitespace mode" };