refactor: move default file type constants to file_types_config module
This commit is contained in:
parent
924b3a2a75
commit
abd1e683a3
3 changed files with 16 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
name: []const u8 = "none",
|
||||
name: []const u8 = default.name,
|
||||
description: ?[]const u8 = null,
|
||||
extensions: ?[]const []const u8 = null,
|
||||
icon: ?[]const u8 = null,
|
||||
|
@ -12,7 +12,14 @@ first_line_matches: ?[]const u8 = null,
|
|||
|
||||
include_files: []const u8 = "",
|
||||
|
||||
fn from_file_type(file_type: *const syntax.FileType) @This() {
|
||||
pub const default = struct {
|
||||
pub const name = "text";
|
||||
pub const description = "Plain Text";
|
||||
pub const icon = "🖹";
|
||||
pub const color = 0x000000;
|
||||
};
|
||||
|
||||
fn from_file_type(file_type: syntax.FileType) @This() {
|
||||
return .{
|
||||
.name = file_type.name,
|
||||
.color = file_type.color,
|
||||
|
|
|
@ -616,9 +616,9 @@ pub const Editor = struct {
|
|||
self.syntax_no_render = tp.env.get().is("no-syntax");
|
||||
self.syntax_report_timing = tp.env.get().is("syntax-report-timing");
|
||||
|
||||
const ftn = if (self.file_type) |ft| ft.name else "text";
|
||||
const fti = if (self.file_type) |ft| ft.icon orelse "🖹" else "🖹";
|
||||
const ftc = if (self.file_type) |ft| ft.color orelse 0x000000 else 0x000000;
|
||||
const ftn = if (self.file_type) |ft| ft.name else file_type_config.default.name;
|
||||
const fti = if (self.file_type) |ft| ft.icon orelse file_type_config.default.icon else file_type_config.default.icon;
|
||||
const ftc = if (self.file_type) |ft| ft.color orelse file_type_config.default.color else file_type_config.default.color;
|
||||
if (self.buffer) |buffer| {
|
||||
buffer.file_type_name = ftn;
|
||||
buffer.file_type_icon = fti;
|
||||
|
|
|
@ -40,14 +40,14 @@ pub fn Variant(comptime command: []const u8, comptime label_: []const u8, allow_
|
|||
break :blk null;
|
||||
};
|
||||
|
||||
for (syntax.FileType.static_file_types) |static_file_type| {
|
||||
for (file_type_config.get_all()) |static_file_type| {
|
||||
const file_type = try file_type_config.get(static_file_type.name) orelse unreachable;
|
||||
idx += 1;
|
||||
(try palette.entries.addOne()).* = .{
|
||||
.label = file_type.description orelse static_file_type.description,
|
||||
.label = file_type.description orelse file_type_config.default.description,
|
||||
.name = file_type.name,
|
||||
.icon = file_type.icon orelse static_file_type.icon,
|
||||
.color = file_type.color orelse static_file_type.color,
|
||||
.icon = file_type.icon orelse file_type_config.default.icon,
|
||||
.color = file_type.color orelse file_type_config.default.color,
|
||||
};
|
||||
if (previous_file_type) |file_type_name| if (std.mem.eql(u8, file_type.name, file_type_name)) {
|
||||
palette.initial_selected = idx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue