@@ -122,6 +122,9 @@ const Tui = struct {
122122
123123 search: ?Search = null,
124124
125+ hist_index: ?usize = null,
126+ hist_saved: []const u8 = "",
127+
125128 prompt_open: bool = false,
126129 prompt_options: []const []const u8 = &.{},
127130 prompt_ids: []const []const u8 = &.{},
@@ -516,7 +519,35 @@ const Tui = struct {
516519 self.ca = self.calls.allocator();
517520 }
518521
522+ fn resetHistory(self: *Tui) void {
523+ if (self.hist_index == null) return;
524+ self.backing.free(self.hist_saved);
525+ self.hist_saved = "";
526+ self.hist_index = null;
527+ }
528+
529+ fn historyWalk(self: *Tui, delta: isize) void {
530+ const n = self.history.entries.items.len;
531+ if (n == 0) return;
532+ if (self.hist_index == null) {
533+ self.hist_saved = self.backing.dupe(u8, self.editor.contents()) catch return;
534+ self.hist_index = n;
535+ }
536+ const idx = @as(isize, @intCast(self.hist_index.?)) + delta;
537+ if (idx < 0) return;
538+ if (idx >= @as(isize, @intCast(n))) {
539+ self.editor.setText(self.hist_saved);
540+ self.resetHistory();
541+ self.dirty = true;
542+ return;
543+ }
544+ self.hist_index = @intCast(idx);
545+ self.editor.setText(self.history.entries.items[@intCast(idx)]);
546+ self.dirty = true;
547+ }
548+
519549 fn openSearch(self: *Tui) void {
550+ self.resetHistory();
520551 const draft = self.editor.contents();
521552 self.search = .{ .saved = self.backing.dupe(u8, draft) catch return };
522553 self.editor.clear();
@@ -575,6 +606,14 @@ const Tui = struct {
575606 self.openSearch();
576607 return;
577608 }
609+ if (key == .history_prev) {
610+ self.historyWalk(-1);
611+ return;
612+ }
613+ if (key == .history_next) {
614+ self.historyWalk(1);
615+ return;
616+ }
578617 if (key == .eof) {
579618 if (!self.active and !self.command_active and self.editor.contents().len == 0) self.exit();
580619 return;
@@ -618,10 +657,16 @@ const Tui = struct {
618657 return;
619658 }
620659 const result = self.editor.handle(key);
621- if (result == .submit) self.submit() else if (result == .changed) self.dirty = true;
660+ if (result == .submit) {
661+ self.submit();
662+ } else if (result == .changed) {
663+ self.resetHistory();
664+ self.dirty = true;
665+ }
622666 }
623667
624668 fn submit(self: *Tui) void {
669+ self.resetHistory();
625670 const text = self.a.dupe(u8, self.editor.contents()) catch return;
626671 if (self.active) {
627672 if (self.paused) {
@@ -712,6 +757,7 @@ const Tui = struct {
712757 const keys = [_][2][]const u8{
713758 .{ "Enter", "submit" },
714759 .{ "Shift+Enter", "newline (Ctrl+J also works)" },
760+ .{ "Shift+Up/Down", "walk input history (Ctrl+R to search)" },
715761 .{ "Esc", "pause the turn at the next step boundary" },
716762 .{ "Ctrl+C", "cancel the turn" },
717763 .{ "Ctrl+D", "exit on an empty draft" },