diff --git a/src/main.zig b/src/main.zig index 7579eb5..251d5aa 100644 --- a/src/main.zig +++ b/src/main.zig @@ -76,6 +76,8 @@ pub fn main() anyerror!void { .syntax_report_timing = "Report syntax highlighting time", .exec = "Execute a command on startup", .literal = "Disable :LINE and +LINE syntax", + .scratch = "Open a scratch (temporary) buffer on start", + .new_file = "Create a new untitled file on start", .version = "Show build version and exit", }; @@ -89,6 +91,8 @@ pub fn main() anyerror!void { .language = 'l', .exec = 'e', .literal = 'L', + .scratch = 'S', + .new_file = 'n', .version = 'v', }; @@ -110,6 +114,8 @@ pub fn main() anyerror!void { syntax_report_timing: bool, exec: ?[]const u8, literal: bool, + scratch: bool, + new_file: bool, version: bool, }; @@ -320,6 +326,12 @@ pub fn main() anyerror!void { try tui_proc.send(.{ "cmd", "show_home" }); } + if (args.new_file) { + try tui_proc.send(.{ "cmd", "create_new_file", .{} }); + } else if (args.scratch) { + try tui_proc.send(.{ "cmd", "create_scratch_buffer", .{} }); + } + if (args.exec) |exec_str| { var cmds = std.mem.splitScalar(u8, exec_str, ';'); while (cmds.next()) |cmd| try tui_proc.send(.{ "cmd", cmd, .{} }); diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 942af27..a7c3644 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -4073,7 +4073,10 @@ pub const Editor = struct { } else if (ctx.args.match(.{tp.extract(&file_path)}) catch false) { try self.open_scratch(file_path, "", null); self.clamp(); - } else return error.InvalidOpenScratchBufferArgument; + } else { + try self.open_scratch("*scratch*", "", null); + self.clamp(); + } } pub const open_scratch_buffer_meta: Meta = .{ .arguments = &.{ .string, .string } }; diff --git a/src/tui/mainview.zig b/src/tui/mainview.zig index 8752c7c..af1d4c4 100644 --- a/src/tui/mainview.zig +++ b/src/tui/mainview.zig @@ -465,7 +465,8 @@ const cmds = struct { } } try command.executeName("create_scratch_buffer", command.fmt(.{name.items})); - try command.executeName("change_file_type", .{}); + if (tp.env.get().str("language").len == 0) + try command.executeName("change_file_type", .{}); } pub const create_new_file_meta: Meta = .{ .description = "Create: New File…" }; diff --git a/src/tui/tui.zig b/src/tui/tui.zig index e68ea6d..e21dc91 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -868,7 +868,7 @@ const cmds = struct { pub fn exit_overlay_mode(self: *Self, _: Ctx) Result { self.rdr_.cursor_disable(); - if (self.input_mode_outer_ == null) return; + if (self.input_mode_outer_ == null) return enter_mode_default(self, .{}); if (self.input_mode_) |*mode| mode.deinit(); self.input_mode_ = self.input_mode_outer_; self.input_mode_outer_ = null; @@ -1290,7 +1290,8 @@ pub fn message(comptime fmt: anytype, args: anytype) void { tp.self_pid().send(.{ "message", std.fmt.bufPrint(&buf, fmt, args) catch @panic("too large") }) catch {}; } -pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) void { var cell = self.cell_init(); +pub fn render_file_icon(self: *renderer.Plane, icon: []const u8, color: u24) void { + var cell = self.cell_init(); _ = self.at_cursor_cell(&cell) catch return; if (!(color == 0xFFFFFF or color == 0x000000 or color == 0x000001)) { cell.set_fg_rgb(@intCast(color)) catch {}; @@ -1307,4 +1308,3 @@ pub fn render_match_cell(self: *renderer.Plane, y: usize, x: usize, theme_: *con cell.set_style(theme_.editor_match); _ = self.putc(&cell) catch {}; } -