diff --git a/src/Project.zig b/src/Project.zig index 80de0ef..dd401fb 100644 --- a/src/Project.zig +++ b/src/Project.zig @@ -381,7 +381,7 @@ pub fn request_n_most_recent_file(self: *Self, from: tp.pid_ref, n: usize) Clien } pub fn request_recent_files(self: *Self, from: tp.pid_ref, max: usize) ClientError!void { - defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, "", self.files.items.len }) catch {}; + defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, "" }) catch {}; for (self.files.items, 0..) |file, i| { from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, file.type, file.icon, file.color }) catch return error.ClientFailed; if (i >= max) return; @@ -468,7 +468,7 @@ pub fn request_new_or_modified_files(self: *Self, from: tp.pid_ref, max: usize) fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize { var i: usize = 0; - defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query, self.files.items.len }) catch {}; + defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {}; for (self.files.items) |file| { if (file.path.len < query.len) continue; if (std.mem.indexOf(u8, file.path, query)) |idx| { @@ -487,7 +487,7 @@ fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: [ pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize { if (query.len < 3) return self.simple_query_recent_files(from, max, query); - defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query, self.files.items.len }) catch {}; + defer from.send(.{ "PRJ", "recent_done", self.longest_file_path, query }) catch {}; var searcher = try fuzzig.Ascii.init( self.allocator, diff --git a/src/tui/InputBox.zig b/src/tui/InputBox.zig index defb7c1..828d125 100644 --- a/src/tui/InputBox.zig +++ b/src/tui/InputBox.zig @@ -10,7 +10,6 @@ const tui = @import("tui.zig"); pub fn Options(context: type) type { return struct { label: []const u8 = "Enter text", - hint: ?[]const u8 = null, pos: Widget.Box = .{ .y = 0, .x = 0, .w = 12, .h = 1 }, ctx: Context, padding: u8 = 1, @@ -25,21 +24,13 @@ pub fn Options(context: type) type { pub fn on_render_default(_: context, self: *State(Context), theme: *const Widget.Theme) bool { const style_base = theme.editor_widget; - const style_input_placeholder = theme.input_placeholder; - const style_label = if (self.text.items.len > 0) theme.input else style_input_placeholder; + const style_label = if (self.text.items.len > 0) theme.input else theme.input_placeholder; self.plane.set_base_style(style_base); self.plane.erase(); self.plane.home(); self.plane.set_style(style_label); self.plane.fill(" "); self.plane.home(); - if (self.hint.items.len > 0) { - const hint = self.hint.items; - self.plane.set_style(style_input_placeholder); - _ = self.plane.print_aligned_right(0, "{s} ", .{hint}) catch {}; - self.plane.home(); - self.plane.set_style(style_label); - } for (0..self.opts.padding) |_| _ = self.plane.putchar(" "); if (self.icon_width > 0) if (self.opts.icon) |icon| { _ = self.plane.print("{s}", .{icon}) catch {}; @@ -83,16 +74,11 @@ pub fn create(ctx_type: type, allocator: std.mem.Allocator, parent: Plane, opts: .plane = n, .opts = opts, .label = .empty, - .hint = .empty, .text = .empty, .icon_width = @intCast(if (tui.config().show_fileicons) if (opts.icon) |icon| n.egc_chunk_width(icon, 0, 1) else 0 else 0), }; try self.label.appendSlice(self.allocator, self.opts.label); self.opts.label = self.label.items; - if (self.opts.hint) |hint| { - try self.hint.appendSlice(self.allocator, hint); - self.opts.hint = self.hint.items; - } return Widget.to(self); } @@ -104,7 +90,6 @@ pub fn State(ctx_type: type) type { active: bool = false, hover: bool = false, label: std.ArrayList(u8), - hint: std.ArrayList(u8), opts: Options(ctx_type), text: std.ArrayList(u8), icon_width: c_int, @@ -115,7 +100,6 @@ pub fn State(ctx_type: type) type { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { self.text.deinit(self.allocator); - self.hint.deinit(self.allocator); self.label.deinit(self.allocator); self.plane.deinit(); allocator.destroy(self); diff --git a/src/tui/mode/overlay/open_recent.zig b/src/tui/mode/overlay/open_recent.zig index 6de797d..7bcc3b4 100644 --- a/src/tui/mode/overlay/open_recent.zig +++ b/src/tui/mode/overlay/open_recent.zig @@ -38,8 +38,6 @@ longest: usize, commands: Commands = undefined, buffer_manager: ?*BufferManager, split: enum { none, vertical } = .none, -total_items: usize = 0, -total_files_in_project: usize = 0, const inputbox_label = "Search files by name"; const MenuType = Menu.Options(*Self).MenuType; @@ -148,7 +146,6 @@ fn add_item( indicator: []const u8, matches: ?[]const u8, ) !void { - self.total_items += 1; var label: std.Io.Writer.Allocating = .init(self.allocator); defer label.deinit(); const writer = &label.writer; @@ -212,14 +209,12 @@ fn process_project_manager(self: *Self, m: tp.message) MessageFilter.Error!void self.need_select_first = false; } tui.need_render(); - } else if (try cbor.match(m.buf, .{ "PRJ", "recent_done", tp.extract(&self.longest), tp.extract(&query), tp.extract(&self.total_files_in_project) })) { - self.update_count_hint(); + } else if (try cbor.match(m.buf, .{ "PRJ", "recent_done", tp.extract(&self.longest), tp.extract(&query) })) { self.query_pending = false; self.need_reset = true; if (!std.mem.eql(u8, self.inputbox.text.items, query)) try self.start_query(); - } else if (try cbor.match(m.buf, .{ "PRJ", "open_done", tp.string, tp.extract(&self.longest), tp.extract(&self.total_files_in_project) })) { - self.update_count_hint(); + } else if (try cbor.match(m.buf, .{ "PRJ", "open_done", tp.string, tp.extract(&self.longest), tp.any })) { self.query_pending = false; self.need_reset = true; try self.start_query(); @@ -244,13 +239,7 @@ fn reset_results(self: *Self) void { self.need_select_first = true; } -fn update_count_hint(self: *Self) void { - self.inputbox.hint.clearRetainingCapacity(); - self.inputbox.hint.print(self.inputbox.allocator, "{d}/{d}", .{ self.total_items, self.total_files_in_project }) catch {}; -} - fn start_query(self: *Self) MessageFilter.Error!void { - self.total_items = 0; if (self.query_pending) return; self.query_pending = true; try project_manager.query_recent_files(max_recent_files, self.inputbox.text.items); diff --git a/src/tui/mode/overlay/palette.zig b/src/tui/mode/overlay/palette.zig index 0d92655..a7083bd 100644 --- a/src/tui/mode/overlay/palette.zig +++ b/src/tui/mode/overlay/palette.zig @@ -291,13 +291,7 @@ pub fn Create(options: type) type { return false; } - fn update_count_hint(self: *Self) void { - self.inputbox.hint.clearRetainingCapacity(); - self.inputbox.hint.print(self.inputbox.allocator, "{d}/{d}", .{ self.total_items, self.entries.items.len }) catch {}; - } - fn start_query(self: *Self, n: usize) !void { - defer self.update_count_hint(); self.items = 0; self.menu.reset_items(); self.menu.selected = null;