From 1f6bc86265d323595e5551195c036e8db0eb0424 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 16 Aug 2024 22:00:25 +0200 Subject: [PATCH] feat: add cli option to disable syntax highlighting --- src/main.zig | 2 ++ src/tui/editor.zig | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main.zig b/src/main.zig index 7155a5c..64c869a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -44,6 +44,7 @@ pub fn main() anyerror!void { \\--show-log Open the log view on start. \\-l, --language Force the language of the file to be opened. \\--list-languages Show available languages. + \\--no-syntax Disable syntax highlighting. \\-e, --exec ... Execute a command on startup. \\-v, --version Show build version and exit. \\... File or directory to open. @@ -154,6 +155,7 @@ pub fn main() anyerror!void { env.set("show-input", (res.args.@"show-input" != 0)); env.set("show-log", (res.args.@"show-log" != 0)); env.set("no-sleep", (res.args.@"no-sleep" != 0)); + env.set("no-syntax", (res.args.@"no-syntax" != 0)); env.set("dump-stack-trace", (res.args.@"debug-dump-on-error" != 0)); if (res.args.@"frame-rate") |s| env.num_set("frame-rate", @intCast(s)); env.proc_set("log", log_proc.ref()); diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 0f5dd5a..4f37dca 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -404,7 +404,7 @@ pub const Editor = struct { if (self.buffer) |_| try self.close(); self.buffer = new_buf; - self.syntax = syntax: { + self.syntax = if (tp.env.get().is("no-syntax")) null else syntax: { if (new_buf.root.lines() > root_mod.max_syntax_lines) break :syntax null; const lang_override = tp.env.get().str("language"); @@ -2932,10 +2932,13 @@ pub const Editor = struct { var content = std.ArrayList(u8).init(self.a); defer content.deinit(); try root.store(content.writer()); - self.syntax = syntax.create_guess_file_type(self.a, content.items, self.file_path) catch |e| switch (e) { - error.NotFound => null, - else => return e, - }; + self.syntax = if (tp.env.get().is("no-syntax")) + null + else + syntax.create_guess_file_type(self.a, content.items, self.file_path) catch |e| switch (e) { + error.NotFound => null, + else => return e, + }; } }