feat: add --list-languages
This commit is contained in:
parent
35d0de50bf
commit
9a57e1ebff
3 changed files with 15 additions and 4 deletions
|
@ -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
|
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.
|
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.
|
The default theme will be read from ~/.config/flow/config.json if found.
|
||||||
|
|
||||||
See --help for full command line.
|
See --help for full command line.
|
||||||
|
|
|
@ -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 {
|
fn load_file_types(comptime Namespace: type) []FileType {
|
||||||
comptime switch (@typeInfo(Namespace)) {
|
comptime switch (@typeInfo(Namespace)) {
|
||||||
|
|
15
src/main.zig
15
src/main.zig
|
@ -13,9 +13,10 @@ var lang_override: ?[]const u8 = null;
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const params = comptime clap.parseParamsComptime(
|
const params = comptime clap.parseParamsComptime(
|
||||||
\\-h, --help Display this help and exit.
|
\\-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.
|
\\-t, --theme <str> Select theme to use.
|
||||||
\\--list-themes Show available themes.
|
\\--list-themes Show available themes.
|
||||||
|
\\--list-languages Show available language parsers.
|
||||||
\\<str>... File to open.
|
\\<str>... File to open.
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
@ -42,6 +43,9 @@ pub fn main() !void {
|
||||||
if (res.args.@"list-themes" != 0)
|
if (res.args.@"list-themes" != 0)
|
||||||
return list_themes(std.io.getStdOut().writer());
|
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;
|
var conf_buf: ?[]const u8 = null;
|
||||||
const conf = config_loader.read_config(a, &conf_buf);
|
const conf = config_loader.read_config(a, &conf_buf);
|
||||||
const theme_name = if (res.args.theme) |theme| theme else conf.theme;
|
const theme_name = if (res.args.theme) |theme| theme else conf.theme;
|
||||||
|
@ -51,7 +55,7 @@ pub fn main() !void {
|
||||||
std.os.exit(1);
|
std.os.exit(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
lang_override = res.args.lang;
|
lang_override = res.args.language;
|
||||||
|
|
||||||
const stdout_file = std.io.getStdOut().writer();
|
const stdout_file = std.io.getStdOut().writer();
|
||||||
var bw = std.io.bufferedWriter(stdout_file);
|
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));
|
const b = @as(u8, @intCast(color & 0xFF));
|
||||||
return .{ .RGB = .{ .r = r, .g = g, .b = b } };
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue