地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.

refactor: rename `inputToSlice` -> `readInput` refactor: use `toOwnedSlice` when appropriate

+17 -20
+4 -1
src/app.zig
··· 207 207 self.images.cache.deinit(); 208 208 } 209 209 210 - pub fn inputToSlice(self: *App) []const u8 { 210 + /// Reads the current text input without consuming it. 211 + /// The returned slice is valid until the next call to readInput() or until 212 + /// the text_input buffer is modified. 213 + pub fn readInput(self: *App) []const u8 { 211 214 const first = self.text_input.buf.firstHalf(); 212 215 const second = self.text_input.buf.secondHalf(); 213 216 var dest_idx: usize = 0;
+1 -1
src/drawer.zig
··· 62 62 try self.drawFilePreview(app, win, file_name_bar); 63 63 } 64 64 65 - const input = app.inputToSlice(); 65 + const input = app.readInput(); 66 66 drawUserInput(app.state, &app.text_input, input, win); 67 67 68 68 // Notification should be drawn last.
+6 -6
src/event_handlers.zig
··· 162 162 .new_file => try events.createNewFile(app), 163 163 .rename => try events.rename(app), 164 164 .change_dir => { 165 - const path = app.inputToSlice(); 165 + const path = try app.text_input.toOwnedSlice(); 166 + defer app.alloc.free(path); 166 167 try commands.cd(app, path); 167 - app.text_input.clearAndFree(); 168 168 }, 169 169 .command => { 170 - const command = app.inputToSlice(); 170 + const command = try app.text_input.toOwnedSlice(); 171 + defer app.alloc.free(command); 171 172 172 173 // Push command to history if it's not empty. 173 174 if (!std.mem.eql(u8, std.mem.trim(u8, command, " "), ":")) { ··· 209 210 break :supported; 210 211 } 211 212 212 - app.text_input.clearAndFree(); 213 213 try app.text_input.insertSliceAtCursor(":UnsupportedCommand"); 214 214 } 215 215 ··· 259 259 260 260 switch (app.state) { 261 261 .fuzzy => { 262 - const fuzzy = app.inputToSlice(); 262 + const fuzzy = app.readInput(); 263 263 try app.repopulateDirectory(fuzzy); 264 264 }, 265 265 .command => { 266 - const command = app.inputToSlice(); 266 + const command = app.readInput(); 267 267 if (!std.mem.startsWith(u8, command, ":")) { 268 268 app.text_input.clearAndFree(); 269 269 app.text_input.insertSliceAtCursor(":") catch |err| {
+6 -12
src/events.zig
··· 87 87 return; 88 88 }; 89 89 90 - const new_path = app.inputToSlice(); 90 + const new_path = try app.text_input.toOwnedSlice(); 91 + defer app.alloc.free(new_path); 91 92 92 93 if (environment.fileExists(app.directories.dir, new_path)) { 93 94 message = try std.fmt.allocPrint(app.alloc, "Can not rename file - '{s}' already exists.", .{new_path}); ··· 111 112 } 112 113 113 114 try app.repopulateDirectory(""); 114 - app.text_input.clearAndFree(); 115 115 116 116 message = try std.fmt.allocPrint(app.alloc, "Renamed '{s}' to '{s}'.", .{ entry.name, new_path }); 117 117 app.notification.write(message.?, .info) catch {}; 118 118 } 119 - 120 - app.text_input.clearAndFree(); 121 119 } 122 120 123 121 pub fn forceDelete(app: *App) error{OutOfMemory}!void { ··· 445 443 var message: ?[]const u8 = null; 446 444 defer if (message) |msg| app.alloc.free(msg); 447 445 448 - const dir = app.inputToSlice(); 446 + const dir = try app.text_input.toOwnedSlice(); 447 + defer app.alloc.free(dir); 449 448 450 449 app.directories.dir.makeDir(dir) catch |err| { 451 450 message = try std.fmt.allocPrint(app.alloc, "Failed to create directory '{s}' - {}", .{ dir, err }); 452 451 app.notification.write(message.?, .err) catch {}; 453 452 if (app.file_logger) |file_logger| file_logger.write(message.?, .err) catch {}; 454 - app.text_input.clearAndFree(); 455 453 return; 456 454 }; 457 455 458 456 try app.repopulateDirectory(""); 459 - app.text_input.clearAndFree(); 460 457 461 458 message = try std.fmt.allocPrint(app.alloc, "Created new directory '{s}'.", .{dir}); 462 459 app.notification.write(message.?, .info) catch {}; ··· 466 463 var message: ?[]const u8 = null; 467 464 defer if (message) |msg| app.alloc.free(msg); 468 465 469 - const file = app.inputToSlice(); 466 + const file = try app.text_input.toOwnedSlice(); 467 + defer app.alloc.free(file); 470 468 471 469 if (environment.fileExists(app.directories.dir, file)) { 472 470 message = try std.fmt.allocPrint(app.alloc, "Can not create file - '{s}' already exists.", .{file}); ··· 476 474 message = try std.fmt.allocPrint(app.alloc, "Failed to create file '{s}' - {}", .{ file, err }); 477 475 app.notification.write(message.?, .err) catch {}; 478 476 if (app.file_logger) |file_logger| file_logger.write(message.?, .err) catch {}; 479 - app.text_input.clearAndFree(); 480 477 return; 481 478 }; 482 479 483 480 try app.repopulateDirectory(""); 484 - app.text_input.clearAndFree(); 485 481 486 482 message = try std.fmt.allocPrint(app.alloc, "Created new file '{s}'.", .{file}); 487 483 app.notification.write(message.?, .info) catch {}; 488 484 } 489 - 490 - app.text_input.clearAndFree(); 491 485 } 492 486 493 487 pub fn undo(app: *App) error{OutOfMemory}!void {