feat: display indent mode in status bar
This commit is contained in:
		
							parent
							
								
									009972309c
								
							
						
					
					
						commit
						aee7c30c65
					
				
					 3 changed files with 24 additions and 14 deletions
				
			
		| 
						 | 
					@ -330,6 +330,7 @@ pub const Editor = struct {
 | 
				
			||||||
        dirty: bool = false,
 | 
					        dirty: bool = false,
 | 
				
			||||||
        eol_mode: Buffer.EolMode = .lf,
 | 
					        eol_mode: Buffer.EolMode = .lf,
 | 
				
			||||||
        utf8_sanitized: bool = false,
 | 
					        utf8_sanitized: bool = false,
 | 
				
			||||||
 | 
					        indent_mode: IndentMode = .spaces,
 | 
				
			||||||
    } = .{},
 | 
					    } = .{},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    file_type: ?file_type_config = null,
 | 
					    file_type: ?file_type_config = null,
 | 
				
			||||||
| 
						 | 
					@ -1647,8 +1648,8 @@ pub const Editor = struct {
 | 
				
			||||||
                buf.lsp_version += 1;
 | 
					                buf.lsp_version += 1;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (self.last.eol_mode != eol_mode or self.last.utf8_sanitized != 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);
 | 
					            try self.send_editor_eol_mode(eol_mode, utf8_sanitized, self.indent_mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (self.last.dirty != dirty)
 | 
					        if (self.last.dirty != dirty)
 | 
				
			||||||
            try self.send_editor_dirty(dirty);
 | 
					            try self.send_editor_dirty(dirty);
 | 
				
			||||||
| 
						 | 
					@ -1775,8 +1776,8 @@ pub const Editor = struct {
 | 
				
			||||||
            tp.self_pid().send(.{ "cmd", "save_file", .{} }) catch {};
 | 
					            tp.self_pid().send(.{ "cmd", "save_file", .{} }) catch {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn send_editor_eol_mode(self: *const Self, eol_mode: Buffer.EolMode, utf8_sanitized: bool) !void {
 | 
					    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", @intFromEnum(eol_mode), utf8_sanitized });
 | 
					        _ = try self.handlers.msg(.{ "E", "eol_mode", eol_mode, utf8_sanitized, indent_mode });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn clamp_abs(self: *Self, abs: bool) void {
 | 
					    fn clamp_abs(self: *Self, abs: bool) void {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ const std = @import("std");
 | 
				
			||||||
const Allocator = std.mem.Allocator;
 | 
					const Allocator = std.mem.Allocator;
 | 
				
			||||||
const tp = @import("thespian");
 | 
					const tp = @import("thespian");
 | 
				
			||||||
const tracy = @import("tracy");
 | 
					const tracy = @import("tracy");
 | 
				
			||||||
 | 
					const config = @import("config");
 | 
				
			||||||
const Buffer = @import("Buffer");
 | 
					const Buffer = @import("Buffer");
 | 
				
			||||||
const root = @import("root");
 | 
					const root = @import("root");
 | 
				
			||||||
const project_manager = @import("project_manager");
 | 
					const project_manager = @import("project_manager");
 | 
				
			||||||
| 
						 | 
					@ -35,6 +36,7 @@ detailed: bool = false,
 | 
				
			||||||
file: bool = false,
 | 
					file: bool = false,
 | 
				
			||||||
eol_mode: Buffer.EolMode = .lf,
 | 
					eol_mode: Buffer.EolMode = .lf,
 | 
				
			||||||
utf8_sanitized: bool = false,
 | 
					utf8_sanitized: bool = false,
 | 
				
			||||||
 | 
					indent_mode: config.IndentMode = .spaces,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const project_icon = "";
 | 
					const project_icon = "";
 | 
				
			||||||
const Self = @This();
 | 
					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 {};
 | 
					        _ = plane.print("{s} ({s})", .{ self.name, project_name }) catch {};
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        const eol_mode = switch (self.eol_mode) {
 | 
					        const eol_mode = switch (self.eol_mode) {
 | 
				
			||||||
            .lf => " [↩ = ␊]",
 | 
					            .lf => "[↩ = ␊]",
 | 
				
			||||||
            .crlf => " [↩ = ␍␊]",
 | 
					            .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.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(" {s}:{d}:{d}", .{ self.name, self.line + 1, self.column + 1 }) catch {};
 | 
				
			||||||
        _ = plane.print(" of {d} lines", .{self.lines}) catch {};
 | 
					        _ = plane.print(" of {d} lines", .{self.lines}) catch {};
 | 
				
			||||||
        if (self.file_type.len > 0)
 | 
					        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) {
 | 
					        if (self.utf8_sanitized) {
 | 
				
			||||||
            plane.set_style(.{ .fg = theme.editor_error.fg.? });
 | 
					            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_type: []const u8 = undefined;
 | 
				
			||||||
    var file_icon: []const u8 = undefined;
 | 
					    var file_icon: []const u8 = undefined;
 | 
				
			||||||
    var file_dirty: bool = 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) }))
 | 
					    if (try m.match(.{ tp.any, "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) }))
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    if (try m.match(.{ tp.any, "dirty", tp.extract(&file_dirty) })) {
 | 
					    if (try m.match(.{ tp.any, "dirty", tp.extract(&file_dirty) })) {
 | 
				
			||||||
        self.file_dirty = 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) })) {
 | 
					    } else if (try m.match(.{ tp.any, "eol_mode", tp.extract(&self.eol_mode), tp.extract(&self.utf8_sanitized), tp.extract(&self.indent_mode) })) {
 | 
				
			||||||
        self.eol_mode = @enumFromInt(eol_mode);
 | 
					        //
 | 
				
			||||||
    } else if (try m.match(.{ tp.any, "save", tp.extract(&file_path) })) {
 | 
					    } else if (try m.match(.{ tp.any, "save", tp.extract(&file_path) })) {
 | 
				
			||||||
        @memcpy(self.name_buf[0..file_path.len], file_path);
 | 
					        @memcpy(self.name_buf[0..file_path.len], file_path);
 | 
				
			||||||
        self.name = self.name_buf[0..file_path.len];
 | 
					        self.name = self.name_buf[0..file_path.len];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ const std = @import("std");
 | 
				
			||||||
const Allocator = std.mem.Allocator;
 | 
					const Allocator = std.mem.Allocator;
 | 
				
			||||||
const tp = @import("thespian");
 | 
					const tp = @import("thespian");
 | 
				
			||||||
const Buffer = @import("Buffer");
 | 
					const Buffer = @import("Buffer");
 | 
				
			||||||
 | 
					const config = @import("config");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Plane = @import("renderer").Plane;
 | 
					const Plane = @import("renderer").Plane;
 | 
				
			||||||
const command = @import("command");
 | 
					const command = @import("command");
 | 
				
			||||||
| 
						 | 
					@ -22,6 +23,7 @@ buf: [256]u8 = undefined,
 | 
				
			||||||
rendered: [:0]const u8 = "",
 | 
					rendered: [:0]const u8 = "",
 | 
				
			||||||
eol_mode: Buffer.EolMode = .lf,
 | 
					eol_mode: Buffer.EolMode = .lf,
 | 
				
			||||||
utf8_sanitized: bool = false,
 | 
					utf8_sanitized: bool = false,
 | 
				
			||||||
 | 
					indent_mode: config.IndentMode = .spaces,
 | 
				
			||||||
padding: ?usize,
 | 
					padding: ?usize,
 | 
				
			||||||
leader: ?Leader,
 | 
					leader: ?Leader,
 | 
				
			||||||
style: ?DigitStyle,
 | 
					style: ?DigitStyle,
 | 
				
			||||||
| 
						 | 
					@ -90,7 +92,11 @@ fn format(self: *Self) void {
 | 
				
			||||||
        .lf => "",
 | 
					        .lf => "",
 | 
				
			||||||
        .crlf => " [␍␊]",
 | 
					        .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 {};
 | 
					    self.format_count(writer, self.line + 1, self.padding orelse 0) catch {};
 | 
				
			||||||
    std.fmt.format(writer, ", Col ", .{}) catch {};
 | 
					    std.fmt.format(writer, ", Col ", .{}) catch {};
 | 
				
			||||||
    self.format_count(writer, self.column + 1, self.padding orelse 0) 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 {
 | 
					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) })) {
 | 
					    if (try m.match(.{ "E", "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) })) {
 | 
				
			||||||
        self.format();
 | 
					        self.format();
 | 
				
			||||||
    } else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
 | 
					    } else if (try m.match(.{ "E", "eol_mode", tp.extract(&self.eol_mode), tp.extract(&self.utf8_sanitized), tp.extract(&self.indent_mode) })) {
 | 
				
			||||||
        self.eol_mode = @enumFromInt(eol_mode);
 | 
					 | 
				
			||||||
        self.format();
 | 
					        self.format();
 | 
				
			||||||
    } else if (try m.match(.{ "E", "open", tp.more })) {
 | 
					    } else if (try m.match(.{ "E", "open", tp.more })) {
 | 
				
			||||||
        self.eol_mode = .lf;
 | 
					        self.eol_mode = .lf;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue