feat: add --list-languages

This commit is contained in:
CJ van den Berg 2024-02-20 20:19:17 +01:00
parent 35d0de50bf
commit 9a57e1ebff
3 changed files with 15 additions and 4 deletions

View file

@ -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.

View file

@ -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)) {

View file

@ -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 <str> Override the language.
\\-l, --language <str> Override the language.
\\-t, --theme <str> Select theme to use.
\\--list-themes Show available themes.
\\--list-languages Show available language parsers.
\\<str>... 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");
}
}