feat: add CLi option to override detected language

This commit is contained in:
CJ van den Berg 2024-03-01 12:37:40 +01:00
parent aa74155cc1
commit de8d563739
3 changed files with 8 additions and 4 deletions

View file

@ -24,8 +24,8 @@
.hash = "1220a7cf5f59b61257993bc5b02991ffc523d103f66842fa8d8ab5c9fdba52799340",
},
.thespian = .{
.url = "https://github.com/neurocyte/thespian/archive/522813dae1ef02eb1348a3eda5710b6626a65477.tar.gz",
.hash = "1220d1a80d5419e5a89df908d44d586b99f84c7dbf37e074f1123522b81d7473a700",
.url = "https://github.com/neurocyte/thespian/archive/a740c03c11ab22b93c050bfc27cb936be86f9b39.tar.gz",
.hash = "1220ecd65090063ac90cd462b09ba603736cb03f4863d831c4f6c46189d2b1a1267a",
},
.themes = .{
.url = "https://github.com/neurocyte/flow-themes/releases/download/master-9ee6d7bc28256202aa7b3b20555bf480715c4e5c/flow-themes.tar.gz",

View file

@ -25,6 +25,7 @@ pub fn main() anyerror!void {
\\--no-trace Do not enable internal tracing.
\\--restore-session Restore restart session.
\\--show-input Open the input view on start.
\\-l, --language <str> Force the language of the file to be opened.
\\<str>... File to open.
\\ Add +<LINE> to the command line or append
\\ :LINE or :LINE:COL to the file name to jump
@ -86,9 +87,9 @@ pub fn main() anyerror!void {
env.set("show-input", (res.args.@"show-input" != 0));
env.set("no-sleep", (res.args.@"no-sleep" != 0));
env.set("dump-stack-trace", (res.args.@"debug-dump-on-error" != 0));
if (res.args.@"frame-rate") |frame_rate|
env.num_set("frame-rate", @intCast(frame_rate));
if (res.args.@"frame-rate") |s| env.num_set("frame-rate", @intCast(s));
env.proc_set("log", log_proc.ref());
if (res.args.language) |s| env.str_set("language", s);
var eh = thespian.make_exit_handler({}, print_exit_status);
const tui_proc = try tui.spawn(a, &ctx, &eh, &env);

View file

@ -357,6 +357,9 @@ pub const Editor = struct {
var content = std.ArrayList(u8).init(self.a);
defer content.deinit();
try new_buf.root.store(content.writer());
const lang_override = tp.env.get().str("language");
if (lang_override.len > 0)
break :syntax syntax.create_file_type(self.a, content.items, lang_override) catch null;
break :syntax syntax.create_guess_file_type(self.a, content.items, self.file_path) catch null;
};