feat: display indent mode in status bar

This commit is contained in:
CJ van den Berg 2025-08-08 21:30:42 +02:00
parent 009972309c
commit aee7c30c65
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
3 changed files with 24 additions and 14 deletions

View file

@ -330,6 +330,7 @@ pub const Editor = struct {
dirty: bool = false,
eol_mode: Buffer.EolMode = .lf,
utf8_sanitized: bool = false,
indent_mode: IndentMode = .spaces,
} = .{},
file_type: ?file_type_config = null,
@ -1647,8 +1648,8 @@ pub const Editor = struct {
buf.lsp_version += 1;
}
if (self.last.eol_mode != eol_mode or self.last.utf8_sanitized != utf8_sanitized)
try self.send_editor_eol_mode(eol_mode, utf8_sanitized);
if (self.last.eol_mode != eol_mode or self.last.utf8_sanitized != utf8_sanitized or self.last.indent_mode != self.indent_mode)
try self.send_editor_eol_mode(eol_mode, utf8_sanitized, self.indent_mode);
if (self.last.dirty != dirty)
try self.send_editor_dirty(dirty);
@ -1775,8 +1776,8 @@ pub const Editor = struct {
tp.self_pid().send(.{ "cmd", "save_file", .{} }) catch {};
}
fn send_editor_eol_mode(self: *const Self, eol_mode: Buffer.EolMode, utf8_sanitized: bool) !void {
_ = try self.handlers.msg(.{ "E", "eol_mode", @intFromEnum(eol_mode), utf8_sanitized });
fn send_editor_eol_mode(self: *const Self, eol_mode: Buffer.EolMode, utf8_sanitized: bool, indent_mode: IndentMode) !void {
_ = try self.handlers.msg(.{ "E", "eol_mode", eol_mode, utf8_sanitized, indent_mode });
}
fn clamp_abs(self: *Self, abs: bool) void {

View file

@ -2,6 +2,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const tp = @import("thespian");
const tracy = @import("tracy");
const config = @import("config");
const Buffer = @import("Buffer");
const root = @import("root");
const project_manager = @import("project_manager");
@ -35,6 +36,7 @@ detailed: bool = false,
file: bool = false,
eol_mode: Buffer.EolMode = .lf,
utf8_sanitized: bool = false,
indent_mode: config.IndentMode = .spaces,
const project_icon = "";
const Self = @This();
@ -155,15 +157,19 @@ fn render_detailed(self: *Self, plane: *Plane, theme: *const Widget.Theme) void
_ = plane.print("{s} ({s})", .{ self.name, project_name }) catch {};
} else {
const eol_mode = switch (self.eol_mode) {
.lf => " [↩ = ␊]",
.crlf => " [↩ = ␍␊]",
.lf => "[↩ = ␊]",
.crlf => "[↩ = ␍␊]",
};
const indent_mode = switch (self.indent_mode) {
.spaces, .auto => "[⭾ = ␠]",
.tabs => "[⭾ = ␉]",
};
_ = plane.putstr(if (!self.file_exists) "󰽂" else if (self.file_dirty) "󰆓" else "󱣪") catch {};
_ = plane.print(" {s}:{d}:{d}", .{ self.name, self.line + 1, self.column + 1 }) catch {};
_ = plane.print(" of {d} lines", .{self.lines}) catch {};
if (self.file_type.len > 0)
_ = plane.print(" ({s}){s}", .{ self.file_type, eol_mode }) catch {};
_ = plane.print(" ({s}) {s}{s}", .{ self.file_type, eol_mode, indent_mode }) catch {};
if (self.utf8_sanitized) {
plane.set_style(.{ .fg = theme.editor_error.fg.? });
@ -214,13 +220,12 @@ fn process_event(self: *Self, m: tp.message) error{Exit}!bool {
var file_type: []const u8 = undefined;
var file_icon: []const u8 = undefined;
var file_dirty: bool = undefined;
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
if (try m.match(.{ tp.any, "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) }))
return false;
if (try m.match(.{ tp.any, "dirty", tp.extract(&file_dirty) })) {
self.file_dirty = file_dirty;
} else if (try m.match(.{ tp.any, "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
self.eol_mode = @enumFromInt(eol_mode);
} else if (try m.match(.{ tp.any, "eol_mode", tp.extract(&self.eol_mode), tp.extract(&self.utf8_sanitized), tp.extract(&self.indent_mode) })) {
//
} else if (try m.match(.{ tp.any, "save", tp.extract(&file_path) })) {
@memcpy(self.name_buf[0..file_path.len], file_path);
self.name = self.name_buf[0..file_path.len];

View file

@ -2,6 +2,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator;
const tp = @import("thespian");
const Buffer = @import("Buffer");
const config = @import("config");
const Plane = @import("renderer").Plane;
const command = @import("command");
@ -22,6 +23,7 @@ buf: [256]u8 = undefined,
rendered: [:0]const u8 = "",
eol_mode: Buffer.EolMode = .lf,
utf8_sanitized: bool = false,
indent_mode: config.IndentMode = .spaces,
padding: ?usize,
leader: ?Leader,
style: ?DigitStyle,
@ -90,7 +92,11 @@ fn format(self: *Self) void {
.lf => "",
.crlf => " [␍␊]",
};
std.fmt.format(writer, "{s} Ln ", .{eol_mode}) catch {};
const indent_mode = switch (self.indent_mode) {
.spaces, .auto => "",
.tabs => " [⭾]",
};
std.fmt.format(writer, "{s}{s} Ln ", .{ eol_mode, indent_mode }) catch {};
self.format_count(writer, self.line + 1, self.padding orelse 0) catch {};
std.fmt.format(writer, ", Col ", .{}) catch {};
self.format_count(writer, self.column + 1, self.padding orelse 0) catch {};
@ -115,11 +121,9 @@ fn format_count(self: *Self, writer: anytype, value: usize, width: usize) !void
}
pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message) error{Exit}!bool {
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
if (try m.match(.{ "E", "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) })) {
self.format();
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
self.eol_mode = @enumFromInt(eol_mode);
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&self.eol_mode), tp.extract(&self.utf8_sanitized), tp.extract(&self.indent_mode) })) {
self.format();
} else if (try m.match(.{ "E", "open", tp.more })) {
self.eol_mode = .lf;