From 9a57e1ebff678a89ccbab8324902f5d81cfe98e4 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 20 Feb 2024 20:19:17 +0100 Subject: [PATCH] feat: add --list-languages --- README.md | 2 +- src/file_type.zig | 2 +- src/main.zig | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 98624a8..d607184 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Place it in your path for convinient access. You might want to strip it first. Supply files to highlight on the command line. Multiple files will be appended like with cat. If no files are on the command line zat will read from stdin. -Override the language with --lang and select a different theme with --theme. +Override the language with --language and select a different theme with --theme. The default theme will be read from ~/.config/flow/config.json if found. See --help for full command line. diff --git a/src/file_type.zig b/src/file_type.zig index 14e2845..eeb339a 100644 --- a/src/file_type.zig +++ b/src/file_type.zig @@ -103,7 +103,7 @@ fn DeclLang(comptime lang: []const u8, comptime args: FileTypeOptions) FileType }; } -const file_types = load_file_types(@import("file_types.zig")); +pub const file_types = load_file_types(@import("file_types.zig")); fn load_file_types(comptime Namespace: type) []FileType { comptime switch (@typeInfo(Namespace)) { diff --git a/src/main.zig b/src/main.zig index a767a0b..683f314 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,9 +13,10 @@ var lang_override: ?[]const u8 = null; pub fn main() !void { const params = comptime clap.parseParamsComptime( \\-h, --help Display this help and exit. - \\-l, --lang Override the language. + \\-l, --language Override the language. \\-t, --theme Select theme to use. \\--list-themes Show available themes. + \\--list-languages Show available language parsers. \\... File to open. \\ ); @@ -42,6 +43,9 @@ pub fn main() !void { if (res.args.@"list-themes" != 0) return list_themes(std.io.getStdOut().writer()); + if (res.args.@"list-languages" != 0) + return list_langs(std.io.getStdOut().writer()); + var conf_buf: ?[]const u8 = null; const conf = config_loader.read_config(a, &conf_buf); const theme_name = if (res.args.theme) |theme| theme else conf.theme; @@ -51,7 +55,7 @@ pub fn main() !void { std.os.exit(1); }; - lang_override = res.args.lang; + lang_override = res.args.language; const stdout_file = std.io.getStdOut().writer(); var bw = std.io.bufferedWriter(stdout_file); @@ -239,3 +243,10 @@ fn to_rgb_color(color: u24) term.style.Color { const b = @as(u8, @intCast(color & 0xFF)); return .{ .RGB = .{ .r = r, .g = g, .b = b } }; } + +fn list_langs(writer: anytype) !void { + for (syntax.FileType.file_types) |file_type| { + try writer.writeAll(file_type.name); + try writer.writeAll("\n"); + } +}