@wayofmono/wo-tui 1.0.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/README.md +18 -0
- package/dist/index.js +32 -0
- package/package.json +38 -0
- package/src/autocomplete.ts +783 -0
- package/src/components/box.ts +137 -0
- package/src/components/cancellable-loader.ts +40 -0
- package/src/components/editor.ts +2292 -0
- package/src/components/image.ts +121 -0
- package/src/components/input.ts +503 -0
- package/src/components/loader.ts +86 -0
- package/src/components/markdown.ts +797 -0
- package/src/components/select-list.ts +229 -0
- package/src/components/settings-list.ts +250 -0
- package/src/components/spacer.ts +28 -0
- package/src/components/text.ts +106 -0
- package/src/components/truncated-text.ts +65 -0
- package/src/editor-component.ts +74 -0
- package/src/fuzzy.ts +137 -0
- package/src/index.ts +106 -0
- package/src/keybindings.ts +244 -0
- package/src/keys.ts +1400 -0
- package/src/kill-ring.ts +46 -0
- package/src/stdin-buffer.ts +411 -0
- package/src/terminal-image.ts +423 -0
- package/src/terminal.ts +395 -0
- package/src/tui.ts +1319 -0
- package/src/undo-stack.ts +28 -0
- package/src/utils.ts +1140 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic undo stack with clone-on-push semantics.
|
|
3
|
+
*
|
|
4
|
+
* Stores deep clones of state snapshots. Popped snapshots are returned
|
|
5
|
+
* directly (no re-cloning) since they are already detached.
|
|
6
|
+
*/
|
|
7
|
+
export class UndoStack<S> {
|
|
8
|
+
private stack: S[] = [];
|
|
9
|
+
|
|
10
|
+
/** Push a deep clone of the given state onto the stack. */
|
|
11
|
+
push(state: S): void {
|
|
12
|
+
this.stack.push(structuredClone(state));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Pop and return the most recent snapshot, or undefined if empty. */
|
|
16
|
+
pop(): S | undefined {
|
|
17
|
+
return this.stack.pop();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Remove all snapshots. */
|
|
21
|
+
clear(): void {
|
|
22
|
+
this.stack.length = 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get length(): number {
|
|
26
|
+
return this.stack.length;
|
|
27
|
+
}
|
|
28
|
+
}
|