Compare commits

..

No commits in common. "765a5d2dc79102e70a8e3f3e48de99a76782ee67" and "a65aa237a7365f4afcdcf0140ba91fe15564f9ea" have entirely different histories.

4 changed files with 6 additions and 39 deletions

View file

@ -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 { 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| { 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; from.send(.{ "PRJ", "recent", self.longest_file_path, file.path, file.type, file.icon, file.color }) catch return error.ClientFailed;
if (i >= max) return; 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 { fn simple_query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize {
var i: usize = 0; 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| { for (self.files.items) |file| {
if (file.path.len < query.len) continue; if (file.path.len < query.len) continue;
if (std.mem.indexOf(u8, file.path, query)) |idx| { 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 { pub fn query_recent_files(self: *Self, from: tp.pid_ref, max: usize, query: []const u8) ClientError!usize {
if (query.len < 3) if (query.len < 3)
return self.simple_query_recent_files(from, max, query); 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( var searcher = try fuzzig.Ascii.init(
self.allocator, self.allocator,

View file

@ -10,7 +10,6 @@ const tui = @import("tui.zig");
pub fn Options(context: type) type { pub fn Options(context: type) type {
return struct { return struct {
label: []const u8 = "Enter text", label: []const u8 = "Enter text",
hint: ?[]const u8 = null,
pos: Widget.Box = .{ .y = 0, .x = 0, .w = 12, .h = 1 }, pos: Widget.Box = .{ .y = 0, .x = 0, .w = 12, .h = 1 },
ctx: Context, ctx: Context,
padding: u8 = 1, 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 { pub fn on_render_default(_: context, self: *State(Context), theme: *const Widget.Theme) bool {
const style_base = theme.editor_widget; 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 theme.input_placeholder;
const style_label = if (self.text.items.len > 0) theme.input else style_input_placeholder;
self.plane.set_base_style(style_base); self.plane.set_base_style(style_base);
self.plane.erase(); self.plane.erase();
self.plane.home(); self.plane.home();
self.plane.set_style(style_label); self.plane.set_style(style_label);
self.plane.fill(" "); self.plane.fill(" ");
self.plane.home(); 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(" "); for (0..self.opts.padding) |_| _ = self.plane.putchar(" ");
if (self.icon_width > 0) if (self.opts.icon) |icon| { if (self.icon_width > 0) if (self.opts.icon) |icon| {
_ = self.plane.print("{s}", .{icon}) catch {}; _ = 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, .plane = n,
.opts = opts, .opts = opts,
.label = .empty, .label = .empty,
.hint = .empty,
.text = .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), .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); try self.label.appendSlice(self.allocator, self.opts.label);
self.opts.label = self.label.items; 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); return Widget.to(self);
} }
@ -104,7 +90,6 @@ pub fn State(ctx_type: type) type {
active: bool = false, active: bool = false,
hover: bool = false, hover: bool = false,
label: std.ArrayList(u8), label: std.ArrayList(u8),
hint: std.ArrayList(u8),
opts: Options(ctx_type), opts: Options(ctx_type),
text: std.ArrayList(u8), text: std.ArrayList(u8),
icon_width: c_int, 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 { pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {
self.text.deinit(self.allocator); self.text.deinit(self.allocator);
self.hint.deinit(self.allocator);
self.label.deinit(self.allocator); self.label.deinit(self.allocator);
self.plane.deinit(); self.plane.deinit();
allocator.destroy(self); allocator.destroy(self);

View file

@ -38,8 +38,6 @@ longest: usize,
commands: Commands = undefined, commands: Commands = undefined,
buffer_manager: ?*BufferManager, buffer_manager: ?*BufferManager,
split: enum { none, vertical } = .none, split: enum { none, vertical } = .none,
total_items: usize = 0,
total_files_in_project: usize = 0,
const inputbox_label = "Search files by name"; const inputbox_label = "Search files by name";
const MenuType = Menu.Options(*Self).MenuType; const MenuType = Menu.Options(*Self).MenuType;
@ -148,7 +146,6 @@ fn add_item(
indicator: []const u8, indicator: []const u8,
matches: ?[]const u8, matches: ?[]const u8,
) !void { ) !void {
self.total_items += 1;
var label: std.Io.Writer.Allocating = .init(self.allocator); var label: std.Io.Writer.Allocating = .init(self.allocator);
defer label.deinit(); defer label.deinit();
const writer = &label.writer; 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; self.need_select_first = false;
} }
tui.need_render(); 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) })) { } else if (try cbor.match(m.buf, .{ "PRJ", "recent_done", tp.extract(&self.longest), tp.extract(&query) })) {
self.update_count_hint();
self.query_pending = false; self.query_pending = false;
self.need_reset = true; self.need_reset = true;
if (!std.mem.eql(u8, self.inputbox.text.items, query)) if (!std.mem.eql(u8, self.inputbox.text.items, query))
try self.start_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) })) { } else if (try cbor.match(m.buf, .{ "PRJ", "open_done", tp.string, tp.extract(&self.longest), tp.any })) {
self.update_count_hint();
self.query_pending = false; self.query_pending = false;
self.need_reset = true; self.need_reset = true;
try self.start_query(); try self.start_query();
@ -244,13 +239,7 @@ fn reset_results(self: *Self) void {
self.need_select_first = true; 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 { fn start_query(self: *Self) MessageFilter.Error!void {
self.total_items = 0;
if (self.query_pending) return; if (self.query_pending) return;
self.query_pending = true; self.query_pending = true;
try project_manager.query_recent_files(max_recent_files, self.inputbox.text.items); try project_manager.query_recent_files(max_recent_files, self.inputbox.text.items);

View file

@ -291,13 +291,7 @@ pub fn Create(options: type) type {
return false; 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 { fn start_query(self: *Self, n: usize) !void {
defer self.update_count_hint();
self.items = 0; self.items = 0;
self.menu.reset_items(); self.menu.reset_items();
self.menu.selected = null; self.menu.selected = null;