Compare commits

..

No commits in common. "4ee7a26817735c056153709fc475ec5ab405b2f8" and "625c89ab958cba8e789fdc5d19910d3fb4c39a5a" have entirely different histories.

5 changed files with 22 additions and 28 deletions

View file

@ -188,20 +188,16 @@ pub fn get_arguments(id: ID) ?[]const ArgumentType {
return (commands.items[id] orelse return null).meta.arguments; return (commands.items[id] orelse return null).meta.arguments;
} }
const suppressed_errors = std.StaticStringMap(void).initComptime(.{ const suppressed_errors = .{
.{ "enable_fast_scroll", void }, "enable_fast_scroll",
.{ "disable_fast_scroll", void }, "disable_fast_scroll",
.{ "clear_diagnostics", void }, "clear_diagnostics",
}); };
pub fn executeName(name: []const u8, ctx: Context) tp.result { pub fn executeName(name: []const u8, ctx: Context) tp.result {
const id = get_id(name); const id = get_id(name);
if (id) |id_| return execute(id_, ctx); if (id) |id_| return execute(id_, ctx);
return notFoundError(name); inline for (suppressed_errors) |err| if (std.mem.eql(u8, err, name)) return;
}
pub fn notFoundError(name: []const u8) !void {
if (!suppressed_errors.has(name))
return tp.exit_fmt("CommandNotFound: {s}", .{name}); return tp.exit_fmt("CommandNotFound: {s}", .{name});
} }

View file

@ -18,7 +18,7 @@ const SelectionStyle = @import("Buffer").Selection.Style;
const parse_flow = @import("parse_flow.zig"); const parse_flow = @import("parse_flow.zig");
const parse_vim = @import("parse_vim.zig"); const parse_vim = @import("parse_vim.zig");
const builtin_keybinds = std.StaticStringMap([]const u8).initComptime(.{ const builtin_keybinds = std.static_string_map.StaticStringMap([]const u8).initComptime(.{
.{ "flow", @embedFile("builtin/flow.json") }, .{ "flow", @embedFile("builtin/flow.json") },
.{ "vim", @embedFile("builtin/vim.json") }, .{ "vim", @embedFile("builtin/vim.json") },
.{ "helix", @embedFile("builtin/helix.json") }, .{ "helix", @embedFile("builtin/helix.json") },
@ -291,7 +291,7 @@ const Command = struct {
fn execute(self: *@This()) !void { fn execute(self: *@This()) !void {
const id = self.command_id orelse const id = self.command_id orelse
command.get_id_cache(self.command, &self.command_id) orelse { command.get_id_cache(self.command, &self.command_id) orelse {
return command.notFoundError(self.command); return tp.exit_fmt("CommandNotFound: {s}", .{self.command});
}; };
var buf: [2048]u8 = undefined; var buf: [2048]u8 = undefined;
@memcpy(buf[0..self.args.len], self.args); @memcpy(buf[0..self.args.len], self.args);

View file

@ -95,7 +95,7 @@ pub const FirstLineMatch = struct {
}; };
const static_file_type_list = load_file_types(@import("file_types.zig")); const static_file_type_list = load_file_types(@import("file_types.zig"));
const static_file_types = std.StaticStringMap(FileType).initComptime(static_file_type_list); const static_file_types = std.static_string_map.StaticStringMap(FileType).initComptime(static_file_type_list);
fn vec(comptime args: anytype) []const []const u8 { fn vec(comptime args: anytype) []const []const u8 {
var cmd: []const []const u8 = &[_][]const u8{}; var cmd: []const []const u8 = &[_][]const u8{};
@ -147,7 +147,7 @@ pub const FileTypeQueries = struct {
injections_bin: ?[]const u8, injections_bin: ?[]const u8,
}; };
pub const queries = std.StaticStringMap(FileTypeQueries).initComptime(load_queries()); pub const queries = std.static_string_map.StaticStringMap(FileTypeQueries).initComptime(load_queries());
fn load_queries() []const struct { []const u8, FileTypeQueries } { fn load_queries() []const struct { []const u8, FileTypeQueries } {
if (!build_options.use_tree_sitter) return &.{}; if (!build_options.use_tree_sitter) return &.{};

View file

@ -5,7 +5,7 @@ const log = @import("log");
const Widget = @import("../Widget.zig"); const Widget = @import("../Widget.zig");
const widgets = std.StaticStringMap(CreateFunction).initComptime(.{ const widgets = std.static_string_map.StaticStringMap(CreateFunction).initComptime(.{
.{ "mode", @import("modestate.zig").create }, .{ "mode", @import("modestate.zig").create },
.{ "file", @import("filestate.zig").create }, .{ "file", @import("filestate.zig").create },
.{ "log", @import("minilog.zig").create }, .{ "log", @import("minilog.zig").create },

View file

@ -2,31 +2,29 @@ const FontFace = @This();
const std = @import("std"); const std = @import("std");
// it seems that Windows only supports font faces with up to 31 characters, // it seems that Windows only supports font faces with up to 31 characters
// but we use a larger buffer here because GetFamilyNames can apparently pub const max = 31;
// return longer strings
pub const max = 254;
buf: [max + 1]u16, buf: [max + 1]u16,
len: usize, len: u5,
pub fn initUtf8(utf8: []const u8) error{ TooLong, InvalidUtf8 }!FontFace { pub fn initUtf8(utf8: []const u8) error{ TooLong, InvalidUtf8 }!FontFace {
const utf16_len = std.unicode.calcUtf16LeLen(utf8) catch return error.InvalidUtf8; const utf16_len = std.unicode.calcUtf16LeLen(utf8) catch return error.InvalidUtf8;
if (utf16_len > max) if (utf16_len > max)
return error.TooLong; return error.TooLong;
var self: FontFace = .{ .buf = undefined, .len = utf16_len }; var result: FontFace = .{ .buf = undefined, .len = @intCast(utf16_len) };
const actual_len = try std.unicode.utf8ToUtf16Le(&self.buf, utf8); result.buf[utf16_len] = 0;
const actual_len = try std.unicode.utf8ToUtf16Le(&result.buf, utf8);
std.debug.assert(actual_len == utf16_len); std.debug.assert(actual_len == utf16_len);
self.buf[actual_len] = 0; return result;
return self;
} }
pub fn ptr(self: *const FontFace) [*:0]const u16 { pub fn ptr(self: *const FontFace) [*:0]const u16 {
return self.slice().ptr; std.debug.assert(self.buf[@as(usize, self.len)] == 0);
return @ptrCast(&self.buf);
} }
pub fn slice(self: *const FontFace) [:0]const u16 { pub fn slice(self: *const FontFace) [:0]const u16 {
std.debug.assert(self.buf[self.len] == 0); return self.ptr()[0..self.len :0];
return self.buf[0..self.len :0];
} }
pub fn eql(self: *const FontFace, other: *const FontFace) bool { pub fn eql(self: *const FontFace, other: *const FontFace) bool {
return std.mem.eql(u16, self.slice(), other.slice()); return std.mem.eql(u16, self.slice(), other.slice());