@oh-my-pi/pi-tui 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/editor.ts +19 -0
package/package.json
CHANGED
package/src/components/editor.ts
CHANGED
|
@@ -240,6 +240,15 @@ export interface EditorTopBorder {
|
|
|
240
240
|
width: number;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
interface HistoryEntry {
|
|
244
|
+
prompt: string;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface HistoryStorage {
|
|
248
|
+
add(prompt: string, cwd?: string): void;
|
|
249
|
+
getRecent(limit: number): HistoryEntry[];
|
|
250
|
+
}
|
|
251
|
+
|
|
243
252
|
export class Editor implements Component {
|
|
244
253
|
private state: EditorState = {
|
|
245
254
|
lines: [""],
|
|
@@ -273,6 +282,7 @@ export class Editor implements Component {
|
|
|
273
282
|
// Prompt history for up/down navigation
|
|
274
283
|
private history: string[] = [];
|
|
275
284
|
private historyIndex: number = -1; // -1 = not browsing, 0 = most recent, 1 = older, etc.
|
|
285
|
+
private historyStorage?: HistoryStorage;
|
|
276
286
|
|
|
277
287
|
public onSubmit?: (text: string) => void;
|
|
278
288
|
public onAltEnter?: (text: string) => void;
|
|
@@ -306,6 +316,13 @@ export class Editor implements Component {
|
|
|
306
316
|
this.useTerminalCursor = useTerminalCursor;
|
|
307
317
|
}
|
|
308
318
|
|
|
319
|
+
setHistoryStorage(storage: HistoryStorage): void {
|
|
320
|
+
this.historyStorage = storage;
|
|
321
|
+
const recent = storage.getRecent(100);
|
|
322
|
+
this.history = recent.map((entry) => entry.prompt);
|
|
323
|
+
this.historyIndex = -1;
|
|
324
|
+
}
|
|
325
|
+
|
|
309
326
|
/**
|
|
310
327
|
* Add a prompt to history for up/down arrow navigation.
|
|
311
328
|
* Called after successful submission.
|
|
@@ -320,6 +337,8 @@ export class Editor implements Component {
|
|
|
320
337
|
if (this.history.length > 100) {
|
|
321
338
|
this.history.pop();
|
|
322
339
|
}
|
|
340
|
+
|
|
341
|
+
this.historyStorage?.add(trimmed, process.cwd());
|
|
323
342
|
}
|
|
324
343
|
|
|
325
344
|
private isEditorEmpty(): boolean {
|