Compare commits

..

3 commits

Author SHA1 Message Date
47aefb6f24
refactor: cache ripgrep binary path 2025-04-30 09:24:35 +02:00
df11ec3d5f
fix: re-render on branch widget update 2025-04-30 09:24:35 +02:00
CO
9291445c64 Single line fix for palette crashing when its
items's length is exceeded.
2025-04-30 07:50:57 +02:00
3 changed files with 23 additions and 5 deletions

View file

@ -2,8 +2,7 @@ const std = @import("std");
const tp = @import("thespian"); const tp = @import("thespian");
const cbor = @import("cbor"); const cbor = @import("cbor");
const log = @import("log"); const log = @import("log");
const bin_path = @import("bin_path");
pub const ripgrep_binary = "rg";
pid: ?tp.pid, pid: ?tp.pid,
stdin_behavior: std.process.Child.StdIo, stdin_behavior: std.process.Child.StdIo,
@ -121,7 +120,7 @@ const Process = struct {
errdefer self.deinit(); errdefer self.deinit();
_ = tp.set_trap(true); _ = tp.set_trap(true);
const args = tp.message.fmt(.{ const args = tp.message.fmt(.{
ripgrep_binary, get_ripgrep(),
// "--line-buffered", // "--line-buffered",
"--fixed-strings", "--fixed-strings",
"--json", "--json",
@ -182,9 +181,9 @@ const Process = struct {
} else if (try m.match(.{ tp.any, tp.any, "exited", 1 })) { } else if (try m.match(.{ tp.any, tp.any, "exited", 1 })) {
self.logger.print("no matches found", .{}); self.logger.print("no matches found", .{});
} else if (try m.match(.{ tp.any, tp.any, "error.FileNotFound", 1 })) { } else if (try m.match(.{ tp.any, tp.any, "error.FileNotFound", 1 })) {
self.logger.print_err(ripgrep_binary, "'{s}' executable not found", .{ripgrep_binary}); self.logger.print_err(get_ripgrep(), "'{s}' executable not found", .{get_ripgrep()});
} else if (try m.match(.{ tp.any, tp.any, tp.extract(&err_msg), tp.extract(&exit_code) })) { } else if (try m.match(.{ tp.any, tp.any, tp.extract(&err_msg), tp.extract(&exit_code) })) {
self.logger.print_err(ripgrep_binary, "terminated {s} exitcode: {d}", .{ err_msg, exit_code }); self.logger.print_err(get_ripgrep(), "terminated {s} exitcode: {d}", .{ err_msg, exit_code });
} }
} }
} }
@ -256,3 +255,18 @@ const Process = struct {
self.match_count += 1; self.match_count += 1;
} }
}; };
const rg_binary = "rg";
const default_rg_binary = "/bin/" ++ rg_binary;
var rg_path: ?struct {
path: ?[:0]const u8 = null,
} = null;
pub fn get_ripgrep() []const u8 {
const allocator = std.heap.c_allocator;
if (rg_path) |p| return p.path orelse default_rg_binary;
const path = bin_path.find_binary_in_path(allocator, rg_binary) catch default_rg_binary;
rg_path = .{ .path = path };
return path orelse default_rg_binary;
}

View file

@ -213,6 +213,7 @@ pub fn Create(options: type) type {
self.items = 0; self.items = 0;
self.menu.reset_items(); self.menu.reset_items();
self.menu.selected = null; self.menu.selected = null;
self.longest = self.inputbox.text.items.len;
for (self.entries.items) |entry| for (self.entries.items) |entry|
self.longest = @max(self.longest, entry.label.len); self.longest = @max(self.longest, entry.label.len);

View file

@ -93,9 +93,12 @@ fn process_git(self: *Self, m: tp.message) MessageFilter.Error!bool {
} }
fn process_status(self: *Self, m: tp.message) MessageFilter.Error!bool { fn process_status(self: *Self, m: tp.message) MessageFilter.Error!bool {
defer Widget.need_render();
var value: []const u8 = undefined; var value: []const u8 = undefined;
var ahead: []const u8 = undefined; var ahead: []const u8 = undefined;
var behind: []const u8 = undefined; var behind: []const u8 = undefined;
if (self.done) { if (self.done) {
self.done = false; self.done = false;
self.changed = 0; self.changed = 0;