@travisennis/acai 0.0.6 → 0.0.7
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 +186 -17
- package/bin/acai-wrapper.js +26 -0
- package/dist/agent/index.d.ts +15 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +202 -174
- package/dist/api/exa/index.js +1 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +40 -7
- package/dist/commands/add-directory-command.d.ts +1 -1
- package/dist/commands/add-directory-command.d.ts.map +1 -1
- package/dist/commands/add-directory-command.js +1 -32
- package/dist/commands/application-log-command.d.ts +1 -1
- package/dist/commands/application-log-command.d.ts.map +1 -1
- package/dist/commands/application-log-command.js +2 -38
- package/dist/commands/clear-command.d.ts +1 -1
- package/dist/commands/clear-command.d.ts.map +1 -1
- package/dist/commands/clear-command.js +1 -5
- package/dist/commands/compact-command.d.ts.map +1 -1
- package/dist/commands/compact-command.js +0 -9
- package/dist/commands/context-command.d.ts +1 -1
- package/dist/commands/context-command.d.ts.map +1 -1
- package/dist/commands/context-command.js +13 -72
- package/dist/commands/copy-command.d.ts.map +1 -1
- package/dist/commands/copy-command.js +0 -19
- package/dist/commands/edit-command.d.ts +1 -1
- package/dist/commands/edit-command.d.ts.map +1 -1
- package/dist/commands/edit-command.js +3 -49
- package/dist/commands/edit-prompt-command.d.ts +1 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -1
- package/dist/commands/edit-prompt-command.js +1 -26
- package/dist/commands/exit-command.d.ts +1 -4
- package/dist/commands/exit-command.d.ts.map +1 -1
- package/dist/commands/exit-command.js +2 -18
- package/dist/commands/files-command.d.ts +1 -1
- package/dist/commands/files-command.d.ts.map +1 -1
- package/dist/commands/files-command.js +1 -54
- package/dist/commands/generate-rules-command.d.ts +1 -1
- package/dist/commands/generate-rules-command.d.ts.map +1 -1
- package/dist/commands/generate-rules-command.js +18 -60
- package/dist/commands/handoff-command.d.ts.map +1 -1
- package/dist/commands/handoff-command.js +0 -11
- package/dist/commands/health-command.d.ts +1 -1
- package/dist/commands/health-command.d.ts.map +1 -1
- package/dist/commands/health-command.js +8 -103
- package/dist/commands/help-command.d.ts +1 -1
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +6 -14
- package/dist/commands/history-command.d.ts +1 -1
- package/dist/commands/history-command.d.ts.map +1 -1
- package/dist/commands/history-command.js +30 -106
- package/dist/commands/init-command.d.ts +1 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/init-command.js +4 -23
- package/dist/commands/last-log-command.d.ts +1 -1
- package/dist/commands/last-log-command.d.ts.map +1 -1
- package/dist/commands/last-log-command.js +1 -28
- package/dist/commands/list-directories-command.d.ts +1 -1
- package/dist/commands/list-directories-command.d.ts.map +1 -1
- package/dist/commands/list-directories-command.js +1 -14
- package/dist/commands/list-tools-command.d.ts.map +1 -1
- package/dist/commands/list-tools-command.js +55 -78
- package/dist/commands/manager.d.ts +1 -8
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +7 -42
- package/dist/commands/model-command.d.ts +0 -22
- package/dist/commands/model-command.d.ts.map +1 -1
- package/dist/commands/model-command.js +5 -126
- package/dist/commands/paste-command.d.ts +1 -1
- package/dist/commands/paste-command.d.ts.map +1 -1
- package/dist/commands/paste-command.js +1 -79
- package/dist/commands/pickup-command.d.ts.map +1 -1
- package/dist/commands/pickup-command.js +3 -55
- package/dist/commands/prompt-command.d.ts +19 -1
- package/dist/commands/prompt-command.d.ts.map +1 -1
- package/dist/commands/prompt-command.js +172 -194
- package/dist/commands/remove-directory-command.d.ts +1 -1
- package/dist/commands/remove-directory-command.d.ts.map +1 -1
- package/dist/commands/remove-directory-command.js +1 -33
- package/dist/commands/reset-command.d.ts +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/reset-command.js +3 -11
- package/dist/commands/rules-command.d.ts +1 -1
- package/dist/commands/rules-command.d.ts.map +1 -1
- package/dist/commands/rules-command.js +1 -63
- package/dist/commands/save-command.d.ts +1 -1
- package/dist/commands/save-command.d.ts.map +1 -1
- package/dist/commands/save-command.js +1 -8
- package/dist/commands/shell-command.d.ts.map +1 -1
- package/dist/commands/shell-command.js +1 -48
- package/dist/commands/types.d.ts +0 -3
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/usage-command.d.ts +1 -1
- package/dist/commands/usage-command.d.ts.map +1 -1
- package/dist/commands/usage-command.js +5 -16
- package/dist/config.d.ts +17 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +86 -53
- package/dist/execution/index.d.ts +17 -2
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +62 -20
- package/dist/formatting.d.ts +19 -0
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +54 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +212 -153
- package/dist/messages.d.ts +3 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +67 -3
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/anthropic-provider.js +0 -7
- package/dist/models/deepseek-provider.d.ts.map +1 -1
- package/dist/models/deepseek-provider.js +0 -2
- package/dist/models/google-provider.d.ts.map +1 -1
- package/dist/models/google-provider.js +0 -3
- package/dist/models/groq-provider.d.ts.map +1 -1
- package/dist/models/groq-provider.js +0 -1
- package/dist/models/openai-provider.d.ts.map +1 -1
- package/dist/models/openai-provider.js +0 -4
- package/dist/models/openrouter-provider.d.ts +10 -9
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +82 -88
- package/dist/models/providers.d.ts +4 -14
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/models/providers.js +1 -57
- package/dist/models/xai-provider.d.ts.map +1 -1
- package/dist/models/xai-provider.js +0 -2
- package/dist/prompts.d.ts +9 -4
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +427 -99
- package/dist/repl/project-status-line.d.ts +1 -0
- package/dist/repl/project-status-line.d.ts.map +1 -1
- package/dist/repl/project-status-line.js +57 -27
- package/dist/repl-new.d.ts +0 -2
- package/dist/repl-new.d.ts.map +1 -1
- package/dist/repl-new.js +34 -54
- package/dist/skills.d.ts +20 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +192 -0
- package/dist/terminal/control.d.ts +55 -0
- package/dist/terminal/control.d.ts.map +1 -0
- package/dist/terminal/control.js +109 -0
- package/dist/terminal/default-theme.d.ts +1 -1
- package/dist/terminal/default-theme.d.ts.map +1 -1
- package/dist/terminal/default-theme.js +24 -28
- package/dist/terminal/formatting.d.ts +23 -25
- package/dist/terminal/formatting.d.ts.map +1 -1
- package/dist/terminal/formatting.js +35 -52
- package/dist/terminal/highlight/index.d.ts.map +1 -1
- package/dist/terminal/highlight/index.js +3 -6
- package/dist/terminal/highlight/theme.d.ts.map +1 -1
- package/dist/terminal/highlight/theme.js +2 -6
- package/dist/terminal/index.d.ts +2 -101
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +2 -464
- package/dist/terminal/markdown.js +7 -5
- package/dist/terminal/strip-ansi.js +4 -4
- package/dist/terminal/table/cell.d.ts +114 -0
- package/dist/terminal/table/cell.d.ts.map +1 -0
- package/dist/terminal/table/cell.js +407 -0
- package/dist/terminal/table/debug.d.ts +15 -0
- package/dist/terminal/table/debug.d.ts.map +1 -0
- package/dist/terminal/table/debug.js +32 -0
- package/dist/terminal/table/index.d.ts +3 -0
- package/dist/terminal/table/index.d.ts.map +1 -0
- package/dist/terminal/table/index.js +2 -0
- package/dist/terminal/table/layout-manager.d.ts +27 -0
- package/dist/terminal/table/layout-manager.d.ts.map +1 -0
- package/dist/terminal/table/layout-manager.js +257 -0
- package/dist/terminal/table/table.d.ts +9 -0
- package/dist/terminal/table/table.d.ts.map +1 -0
- package/dist/terminal/table/table.js +97 -0
- package/dist/terminal/table/utils.d.ts +63 -0
- package/dist/terminal/table/utils.d.ts.map +1 -0
- package/dist/terminal/table/utils.js +326 -0
- package/dist/tokens/threshold.d.ts +6 -21
- package/dist/tokens/threshold.d.ts.map +1 -1
- package/dist/tokens/threshold.js +13 -31
- package/dist/tools/advanced-edit-file.d.ts.map +1 -1
- package/dist/tools/advanced-edit-file.js +5 -1
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/agent.js +19 -5
- package/dist/tools/bash.d.ts +3 -1
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +204 -42
- package/dist/tools/batch.d.ts +34 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +174 -0
- package/dist/tools/code-interpreter.d.ts.map +1 -1
- package/dist/tools/code-interpreter.js +25 -9
- package/dist/tools/delete-file.d.ts.map +1 -1
- package/dist/tools/delete-file.js +9 -2
- package/dist/tools/directory-tree.d.ts +0 -6
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +29 -18
- package/dist/tools/dynamic-tool-loader.d.ts +0 -4
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +2 -2
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +16 -3
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +24 -13
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +40 -25
- package/dist/tools/index.d.ts +17 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +43 -1
- package/dist/tools/llm-edit-fixer.d.ts +0 -1
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -1
- package/dist/tools/llm-edit-fixer.js +14 -28
- package/dist/tools/move-file.d.ts.map +1 -1
- package/dist/tools/move-file.js +8 -1
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +32 -23
- package/dist/tools/read-multiple-files.d.ts.map +1 -1
- package/dist/tools/read-multiple-files.js +102 -45
- package/dist/tools/save-file.d.ts +4 -4
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +20 -2
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +7 -1
- package/dist/tools/types.d.ts +5 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +1 -1
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +24 -9
- package/dist/tui/components/assistant-message.js +1 -1
- package/dist/tui/components/box.d.ts +20 -0
- package/dist/tui/components/box.d.ts.map +1 -0
- package/dist/tui/components/box.js +81 -0
- package/dist/tui/components/editor.d.ts +60 -5
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +577 -115
- package/dist/tui/components/footer.d.ts +0 -12
- package/dist/tui/components/footer.d.ts.map +1 -1
- package/dist/tui/components/footer.js +19 -7
- package/dist/tui/components/header.d.ts +21 -0
- package/dist/tui/components/header.d.ts.map +1 -0
- package/dist/tui/components/header.js +63 -0
- package/dist/tui/components/loader.d.ts +5 -1
- package/dist/tui/components/loader.d.ts.map +1 -1
- package/dist/tui/components/loader.js +2 -2
- package/dist/tui/components/markdown.d.ts +26 -23
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +107 -54
- package/dist/tui/components/modal.d.ts +0 -11
- package/dist/tui/components/modal.d.ts.map +1 -1
- package/dist/tui/components/modal.js +0 -29
- package/dist/tui/components/progress-bar.d.ts +19 -0
- package/dist/tui/components/progress-bar.d.ts.map +1 -0
- package/dist/tui/components/progress-bar.js +78 -0
- package/dist/tui/components/prompt-status.d.ts +2 -1
- package/dist/tui/components/prompt-status.d.ts.map +1 -1
- package/dist/tui/components/prompt-status.js +7 -2
- package/dist/tui/components/select-list.d.ts +27 -1
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +93 -29
- package/dist/tui/components/spacer.d.ts +1 -1
- package/dist/tui/components/spacer.d.ts.map +1 -1
- package/dist/tui/components/spacer.js +2 -2
- package/dist/tui/components/table.d.ts +27 -0
- package/dist/tui/components/table.d.ts.map +1 -0
- package/dist/tui/components/table.js +125 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -1
- package/dist/tui/components/thinking-block.js +4 -1
- package/dist/tui/components/tool-execution.d.ts +8 -4
- package/dist/tui/components/tool-execution.d.ts.map +1 -1
- package/dist/tui/components/tool-execution.js +88 -80
- package/dist/tui/components/user-message.d.ts.map +1 -1
- package/dist/tui/components/user-message.js +6 -4
- package/dist/tui/index.d.ts +9 -5
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +5 -1
- package/dist/tui/terminal.d.ts +2 -1
- package/dist/tui/terminal.d.ts.map +1 -1
- package/dist/tui/terminal.js +28 -38
- package/dist/tui/tui.d.ts +2 -0
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +53 -33
- package/dist/tui/utils.d.ts +5 -0
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +81 -1
- package/dist/{tools/bash-utils.d.ts → utils/bash.d.ts} +3 -3
- package/dist/utils/bash.d.ts.map +1 -0
- package/dist/{tools/bash-utils.js → utils/bash.js} +22 -11
- package/dist/utils/{filesystem.d.ts → filesystem/operations.d.ts} +1 -1
- package/dist/utils/filesystem/operations.d.ts.map +1 -0
- package/dist/{tools/filesystem-utils.d.ts → utils/filesystem/security.d.ts} +3 -2
- package/dist/utils/filesystem/security.d.ts.map +1 -0
- package/dist/{tools/filesystem-utils.js → utils/filesystem/security.js} +62 -4
- package/dist/utils/funcs.d.ts +6 -0
- package/dist/utils/funcs.d.ts.map +1 -0
- package/dist/utils/funcs.js +6 -0
- package/dist/{tools/git-utils.d.ts → utils/git.d.ts} +1 -1
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/{tools/git-utils.js → utils/git.js} +0 -6
- package/dist/utils/glob.js +1 -1
- package/dist/utils/{zod-utils.d.ts → zod.d.ts} +1 -1
- package/dist/utils/zod.d.ts.map +1 -0
- package/package.json +17 -17
- package/dist/agent/manual-loop.d.ts +0 -41
- package/dist/agent/manual-loop.d.ts.map +0 -1
- package/dist/agent/manual-loop.js +0 -278
- package/dist/repl/display-tool-messages.d.ts +0 -4
- package/dist/repl/display-tool-messages.d.ts.map +0 -1
- package/dist/repl/display-tool-messages.js +0 -58
- package/dist/repl/display-tool-use.d.ts +0 -14
- package/dist/repl/display-tool-use.d.ts.map +0 -1
- package/dist/repl/display-tool-use.js +0 -63
- package/dist/repl/get-prompt-header.d.ts +0 -8
- package/dist/repl/get-prompt-header.d.ts.map +0 -1
- package/dist/repl/get-prompt-header.js +0 -9
- package/dist/repl/prompt.d.ts +0 -21
- package/dist/repl/prompt.d.ts.map +0 -1
- package/dist/repl/prompt.js +0 -244
- package/dist/repl.d.ts +0 -29
- package/dist/repl.d.ts.map +0 -1
- package/dist/repl.js +0 -218
- package/dist/terminal/checkbox-prompt.d.ts +0 -36
- package/dist/terminal/checkbox-prompt.d.ts.map +0 -1
- package/dist/terminal/checkbox-prompt.js +0 -368
- package/dist/terminal/editor-prompt.d.ts +0 -10
- package/dist/terminal/editor-prompt.d.ts.map +0 -1
- package/dist/terminal/editor-prompt.js +0 -61
- package/dist/terminal/errors.d.ts +0 -19
- package/dist/terminal/errors.d.ts.map +0 -1
- package/dist/terminal/errors.js +0 -37
- package/dist/terminal/input-prompt.d.ts +0 -17
- package/dist/terminal/input-prompt.d.ts.map +0 -1
- package/dist/terminal/input-prompt.js +0 -181
- package/dist/terminal/search-prompt.d.ts +0 -20
- package/dist/terminal/search-prompt.d.ts.map +0 -1
- package/dist/terminal/search-prompt.js +0 -280
- package/dist/terminal/types.d.ts +0 -35
- package/dist/terminal/types.d.ts.map +0 -1
- package/dist/terminal/types.js +0 -1
- package/dist/tools/bash-utils.d.ts.map +0 -1
- package/dist/tools/filesystem-utils.d.ts.map +0 -1
- package/dist/tools/git-utils.d.ts.map +0 -1
- package/dist/utils/filesystem.d.ts.map +0 -1
- package/dist/utils/zod-utils.d.ts.map +0 -1
- /package/dist/utils/{filesystem.js → filesystem/operations.js} +0 -0
- /package/dist/utils/{zod-utils.js → zod.js} +0 -0
package/dist/terminal/index.js
CHANGED
|
@@ -4,467 +4,5 @@
|
|
|
4
4
|
* Provides a user interface for interacting with Claude Code in the terminal.
|
|
5
5
|
* Handles input/output, formatting, and display.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { getPackageVersion } from "../version.js";
|
|
10
|
-
import { clearTerminal, getTerminalSize, setTerminalTitle, link as terminalLink, } from "./formatting.js";
|
|
11
|
-
import { applyMarkdown } from "./markdown.js";
|
|
12
|
-
import stripAnsi from "./strip-ansi.js";
|
|
13
|
-
import style from "./style.js";
|
|
14
|
-
import wrapAnsi from "./wrap-ansi.js";
|
|
15
|
-
export function getShell() {
|
|
16
|
-
return process.env["ZSH_VERSION"] ? "zsh" : process.env["SHELL"] || "bash";
|
|
17
|
-
}
|
|
18
|
-
export function hr(width) {
|
|
19
|
-
return `${style.gray("─").repeat(width)} `;
|
|
20
|
-
}
|
|
21
|
-
export function table(data, options) {
|
|
22
|
-
const { header, colWidths, width } = options;
|
|
23
|
-
// Determine number of columns from data or header
|
|
24
|
-
let colCount = header?.length;
|
|
25
|
-
if (colCount === undefined) {
|
|
26
|
-
colCount = data.length > 0 && data[0] ? data[0].length : 1;
|
|
27
|
-
}
|
|
28
|
-
// Calculate column widths based on terminal width
|
|
29
|
-
const padding = 5; // Account for table borders and padding
|
|
30
|
-
const availableWidth = Math.max(20, width - padding);
|
|
31
|
-
let computedColWidths;
|
|
32
|
-
if (colWidths && colWidths.length === colCount) {
|
|
33
|
-
// Use provided percentages
|
|
34
|
-
computedColWidths = colWidths.map((percent) => Math.max(10, Math.floor((percent / 100) * availableWidth)));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
// Distribute width evenly with minimum width per column
|
|
38
|
-
const minColWidth = 15;
|
|
39
|
-
const maxColsThatFit = Math.floor(availableWidth / minColWidth);
|
|
40
|
-
const actualColCount = Math.min(colCount, maxColsThatFit);
|
|
41
|
-
if (actualColCount === 1) {
|
|
42
|
-
computedColWidths = [availableWidth];
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
// Calculate base width and distribute remaining pixels
|
|
46
|
-
const baseWidth = Math.floor(availableWidth / actualColCount);
|
|
47
|
-
const remainder = availableWidth % actualColCount;
|
|
48
|
-
computedColWidths = Array(actualColCount).fill(baseWidth);
|
|
49
|
-
// Distribute remainder pixels to first few columns
|
|
50
|
-
for (let i = 0; i < remainder && i < actualColCount; i++) {
|
|
51
|
-
computedColWidths[i] = (computedColWidths[i] || 0) + 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// If we have fewer computed widths than columns, extend the array
|
|
55
|
-
while (computedColWidths.length < colCount) {
|
|
56
|
-
computedColWidths.push(minColWidth);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
const table = new Table({
|
|
60
|
-
head: header,
|
|
61
|
-
colWidths: computedColWidths,
|
|
62
|
-
wordWrap: true,
|
|
63
|
-
wrapOnWordBoundary: true,
|
|
64
|
-
});
|
|
65
|
-
// Ensure all data rows have the same number of columns
|
|
66
|
-
const normalizedData = data.map((row) => {
|
|
67
|
-
if (row.length < colCount) {
|
|
68
|
-
// Pad with empty strings if row has fewer columns
|
|
69
|
-
return [...row, ...Array(colCount - row.length).fill("")];
|
|
70
|
-
}
|
|
71
|
-
if (row.length > colCount) {
|
|
72
|
-
// Truncate if row has more columns
|
|
73
|
-
return row.slice(0, colCount);
|
|
74
|
-
}
|
|
75
|
-
return row;
|
|
76
|
-
});
|
|
77
|
-
table.push(...normalizedData);
|
|
78
|
-
return table.toString();
|
|
79
|
-
}
|
|
80
|
-
export function displayProgressBar(current, total, width) {
|
|
81
|
-
const terminalWidth = width;
|
|
82
|
-
// Function to format numbers concisely (e.g., 1.2K, 5M)
|
|
83
|
-
const formatNumber = (num) => {
|
|
84
|
-
if (num < 1000) {
|
|
85
|
-
return num.toString();
|
|
86
|
-
}
|
|
87
|
-
if (num < 1_000_000) {
|
|
88
|
-
return `${(num / 1000).toFixed(1)}K`;
|
|
89
|
-
}
|
|
90
|
-
if (num < 1_000_000_000) {
|
|
91
|
-
return `${(num / 1_000_000).toFixed(1)}M`;
|
|
92
|
-
}
|
|
93
|
-
return `${(num / 1_000_000_000).toFixed(1)}G`;
|
|
94
|
-
};
|
|
95
|
-
const currentFormatted = formatNumber(current);
|
|
96
|
-
const totalFormatted = formatNumber(total);
|
|
97
|
-
const progressText = `${currentFormatted}/${totalFormatted}`;
|
|
98
|
-
const progressTextLength = progressText.length + 1; // Add 1 for space
|
|
99
|
-
const progressBarMaxWidth = Math.max(1, terminalWidth - progressTextLength);
|
|
100
|
-
const percentage = total === 0 ? 1 : current / total;
|
|
101
|
-
const filledWidth = Math.max(0, Math.min(progressBarMaxWidth, Math.floor(percentage * progressBarMaxWidth)));
|
|
102
|
-
const emptyWidth = Math.max(0, progressBarMaxWidth - filledWidth);
|
|
103
|
-
const a = filledWidth / progressBarMaxWidth > 0.5
|
|
104
|
-
? style.red("─")
|
|
105
|
-
: style.yellow("─"); //"█"
|
|
106
|
-
const b = style.gray("─"); // "░"
|
|
107
|
-
const filledBar = a.repeat(filledWidth);
|
|
108
|
-
const emptyBar = b.repeat(emptyWidth);
|
|
109
|
-
// Use \r to move cursor to the beginning of the line for updates
|
|
110
|
-
return `\r${filledBar}${emptyBar} ${progressText} `;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Initialize the terminal interface
|
|
114
|
-
*/
|
|
115
|
-
export function initTerminal(config = {}) {
|
|
116
|
-
logger.debug("Initializing terminal interface");
|
|
117
|
-
const terminalConfig = {
|
|
118
|
-
theme: config.theme || "system",
|
|
119
|
-
useColors: config.useColors !== false,
|
|
120
|
-
showProgressIndicators: config.showProgressIndicators !== false,
|
|
121
|
-
codeHighlighting: config.codeHighlighting !== false,
|
|
122
|
-
maxHeight: config.maxHeight,
|
|
123
|
-
maxWidth: config.maxWidth,
|
|
124
|
-
};
|
|
125
|
-
const terminal = new Terminal(terminalConfig);
|
|
126
|
-
try {
|
|
127
|
-
// Detect terminal capabilities
|
|
128
|
-
terminal.detectCapabilities();
|
|
129
|
-
return terminal;
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
logger.warn(error, "Error initializing terminal interface:");
|
|
133
|
-
// Return a basic terminal interface even if there was an error
|
|
134
|
-
return terminal;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Terminal class for handling user interaction
|
|
139
|
-
*/
|
|
140
|
-
export class Terminal {
|
|
141
|
-
config;
|
|
142
|
-
terminalWidth;
|
|
143
|
-
terminalHeight;
|
|
144
|
-
isInteractive;
|
|
145
|
-
constructor(config) {
|
|
146
|
-
this.config = config;
|
|
147
|
-
// Get initial terminal size
|
|
148
|
-
const { rows, columns } = getTerminalSize();
|
|
149
|
-
this.terminalHeight = config.maxHeight || rows;
|
|
150
|
-
this.terminalWidth = config.maxWidth || columns;
|
|
151
|
-
// Assume interactive by default
|
|
152
|
-
this.isInteractive = process.stdout.isTTY && process.stdin.isTTY;
|
|
153
|
-
// Listen for terminal resize events
|
|
154
|
-
process.stdout.on("resize", () => {
|
|
155
|
-
const { rows, columns } = getTerminalSize();
|
|
156
|
-
this.terminalHeight = config.maxHeight || rows;
|
|
157
|
-
this.terminalWidth = config.maxWidth || columns;
|
|
158
|
-
logger.debug(`Terminal resized to ${columns}x${rows}`);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Detect terminal capabilities
|
|
163
|
-
*/
|
|
164
|
-
detectCapabilities() {
|
|
165
|
-
// Check if the terminal is interactive
|
|
166
|
-
this.isInteractive = Boolean(process.stdout.isTTY && process.stdin.isTTY);
|
|
167
|
-
logger.debug({
|
|
168
|
-
isInteractive: this.isInteractive,
|
|
169
|
-
colorSupport: this.config.useColors ? "yes" : "no",
|
|
170
|
-
size: `${this.terminalWidth}x${this.terminalHeight}`,
|
|
171
|
-
}, "Terminal capabilities detected");
|
|
172
|
-
}
|
|
173
|
-
setTitle(title) {
|
|
174
|
-
setTerminalTitle(title);
|
|
175
|
-
}
|
|
176
|
-
getLogo() {
|
|
177
|
-
return `
|
|
178
|
-
█████╗ ██████╗ █████╗ ██╗
|
|
179
|
-
██╔══██╗██╔════╝██╔══██╗██║
|
|
180
|
-
███████║██║ ███████║██║
|
|
181
|
-
██╔══██║██║ ██╔══██║██║
|
|
182
|
-
██║ ██║╚██████╗██║ ██║██║
|
|
183
|
-
╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝
|
|
184
|
-
`;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Display the welcome message
|
|
188
|
-
*/
|
|
189
|
-
displayWelcome() {
|
|
190
|
-
this.clear();
|
|
191
|
-
const version = getPackageVersion();
|
|
192
|
-
this.writeln(style.magenta(this.getLogo()));
|
|
193
|
-
this.lineBreak();
|
|
194
|
-
this.writeln(style.magenta("Greetings! I am acai."));
|
|
195
|
-
this.writeln(style.gray(` Version ${version}`));
|
|
196
|
-
this.lineBreak();
|
|
197
|
-
this.writeln(style.white(` Type ${style.cyan("/help")} to see available commands.`));
|
|
198
|
-
this.writeln(style.white(" You can ask acai to explain code, fix issues, or perform tasks."));
|
|
199
|
-
this.writeln(style.white(` Example: "${style.italic("Please analyze this codebase and explain its structure.")}"`));
|
|
200
|
-
this.writeln(style.dim(" Use Ctrl+C to interrupt acai and exit."));
|
|
201
|
-
this.lineBreak();
|
|
202
|
-
this.writeln(style.yellow(`The current working directory is ${process.cwd()}`));
|
|
203
|
-
this.lineBreak();
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Clear the terminal screen
|
|
207
|
-
*/
|
|
208
|
-
clear() {
|
|
209
|
-
if (this.isInteractive) {
|
|
210
|
-
clearTerminal();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Start progress indicator in terminal
|
|
215
|
-
* Sends terminal escape sequence to show progress animation
|
|
216
|
-
*/
|
|
217
|
-
startProgress() {
|
|
218
|
-
process.stdout.write("\u001b]9;4;3;0\u0007");
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Stop progress indicator in terminal
|
|
222
|
-
* Sends terminal escape sequence to hide progress animation
|
|
223
|
-
*/
|
|
224
|
-
stopProgress() {
|
|
225
|
-
process.stdout.write("\u001b]9;4;0;0\u0007");
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Display formatted content
|
|
229
|
-
*/
|
|
230
|
-
display(content, wrap = false) {
|
|
231
|
-
this.writeln(this.formatMarkdown(content, wrap));
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Display a message with emphasis
|
|
235
|
-
*/
|
|
236
|
-
emphasize(message) {
|
|
237
|
-
if (this.config.useColors) {
|
|
238
|
-
this.writeln(style.cyan.bold(message));
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
this.writeln(message.toUpperCase());
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Display an informational message
|
|
246
|
-
*/
|
|
247
|
-
info(message) {
|
|
248
|
-
if (this.config.useColors) {
|
|
249
|
-
this.writeln(style.blue(`ℹ ${message}`));
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
this.writeln(`INFO: ${message}`);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Display a success message
|
|
257
|
-
*/
|
|
258
|
-
success(message) {
|
|
259
|
-
if (this.config.useColors) {
|
|
260
|
-
this.writeln(style.green(`✓ ${message}`));
|
|
261
|
-
}
|
|
262
|
-
else {
|
|
263
|
-
this.writeln(`SUCCESS: ${message}`);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Display a warning message
|
|
268
|
-
*/
|
|
269
|
-
warn(message) {
|
|
270
|
-
if (this.config.useColors) {
|
|
271
|
-
this.writeln(style.yellow(`⚠ ${message}`));
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
this.writeln(`WARNING: ${message}`);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Display an error message
|
|
279
|
-
*/
|
|
280
|
-
error(message) {
|
|
281
|
-
if (this.config.useColors) {
|
|
282
|
-
this.writeln(style.red(`✗ ${message}`));
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
this.writeln(`ERROR: ${message}`);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Emits an alert.
|
|
290
|
-
*/
|
|
291
|
-
alert() {
|
|
292
|
-
if (!this.isInteractive) {
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
const t = "acai";
|
|
296
|
-
const b = "";
|
|
297
|
-
try {
|
|
298
|
-
process.stdout.write("\x07");
|
|
299
|
-
const esc = "\u001b";
|
|
300
|
-
const bel = "\u0007";
|
|
301
|
-
const safe = (s) => s.replaceAll("\u0007", "").replaceAll("\u001b", "");
|
|
302
|
-
const payload = `${esc}]777;notify;${safe(t)};${safe(b)}${bel}`;
|
|
303
|
-
process.stdout.write(payload);
|
|
304
|
-
}
|
|
305
|
-
catch (err) {
|
|
306
|
-
logger.warn({ err }, "Failed to emit alert");
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
write(input) {
|
|
310
|
-
process.stdout.write(input);
|
|
311
|
-
}
|
|
312
|
-
writeln(input) {
|
|
313
|
-
process.stdout.write(`${input}\n`);
|
|
314
|
-
}
|
|
315
|
-
lineBreak() {
|
|
316
|
-
this.writeln("");
|
|
317
|
-
}
|
|
318
|
-
header(header, styleFn = style.cyan) {
|
|
319
|
-
const cols = this.terminalWidth > 0 ? this.terminalWidth : 80;
|
|
320
|
-
const width = Math.max(0, cols - header.length - 4);
|
|
321
|
-
this.writeln(`${style.gray("\n── ")}${styleFn(header)} ${style.gray("─".repeat(width))}`);
|
|
322
|
-
}
|
|
323
|
-
async box(header, content) {
|
|
324
|
-
const cols = this.terminalWidth > 0 ? this.terminalWidth : 80;
|
|
325
|
-
const width = Math.max(4, cols - 4);
|
|
326
|
-
// Helper to strip ANSI sequences for accurate visible-width calculation
|
|
327
|
-
const paddedHeader = ` ${header} `;
|
|
328
|
-
const headerVisibleLen = stripAnsi(paddedHeader).length;
|
|
329
|
-
const headerStartPos = 1;
|
|
330
|
-
// Top border with header (use visible header length)
|
|
331
|
-
const leftDashes = headerStartPos;
|
|
332
|
-
const rightDashes = Math.max(0, width - leftDashes - headerVisibleLen);
|
|
333
|
-
const topBorder = `┌${"─".repeat(leftDashes)}${paddedHeader}${"─".repeat(rightDashes)}┐`;
|
|
334
|
-
// Prepare inner content: format markdown first, then wrap to inner width
|
|
335
|
-
const innerWidth = Math.max(1, width - 2);
|
|
336
|
-
const formatted = applyMarkdown(content);
|
|
337
|
-
const wrapped = wrapAnsi(formatted, innerWidth, { trim: false });
|
|
338
|
-
const contentLines = wrapped
|
|
339
|
-
.split("\n")
|
|
340
|
-
.map((line) => {
|
|
341
|
-
const visibleLen = stripAnsi(line).length;
|
|
342
|
-
const padCount = Math.max(0, innerWidth - visibleLen);
|
|
343
|
-
return `│ ${line}${" ".repeat(padCount)} │`;
|
|
344
|
-
})
|
|
345
|
-
.join("\n");
|
|
346
|
-
// Bottom border
|
|
347
|
-
const bottomBorder = `└${"─".repeat(width)}┘`;
|
|
348
|
-
// Write the box
|
|
349
|
-
this.writeln(`${topBorder}\n${contentLines}\n${bottomBorder}`);
|
|
350
|
-
}
|
|
351
|
-
hr(styleFn = style.gray) {
|
|
352
|
-
const cols = this.terminalWidth > 0 ? this.terminalWidth : 80;
|
|
353
|
-
this.writeln(styleFn(`${"─".repeat(Math.max(1, cols - 1))} `));
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Create a clickable link in the terminal if supported
|
|
357
|
-
*/
|
|
358
|
-
link(text, url) {
|
|
359
|
-
return style.underline.blue(terminalLink(text, url));
|
|
360
|
-
}
|
|
361
|
-
/**
|
|
362
|
-
* Display a table of data
|
|
363
|
-
*/
|
|
364
|
-
table(data, options = {}) {
|
|
365
|
-
const { header, colWidths } = options;
|
|
366
|
-
// Determine number of columns from data or header
|
|
367
|
-
let colCount = header?.length;
|
|
368
|
-
if (colCount === undefined) {
|
|
369
|
-
colCount = data.length > 0 && data[0] ? data[0].length : 1;
|
|
370
|
-
}
|
|
371
|
-
// Calculate column widths based on terminal width
|
|
372
|
-
const padding = 5; // Account for table borders and padding
|
|
373
|
-
const availableWidth = Math.max(20, this.terminalWidth - padding);
|
|
374
|
-
let computedColWidths;
|
|
375
|
-
if (colWidths && colWidths.length === colCount) {
|
|
376
|
-
// Use provided percentages
|
|
377
|
-
computedColWidths = colWidths.map((percent) => Math.max(10, Math.floor((percent / 100) * availableWidth)));
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
// Distribute width evenly with minimum width per column
|
|
381
|
-
const minColWidth = 15;
|
|
382
|
-
const maxColsThatFit = Math.floor(availableWidth / minColWidth);
|
|
383
|
-
const actualColCount = Math.min(colCount, maxColsThatFit);
|
|
384
|
-
if (actualColCount === 1) {
|
|
385
|
-
computedColWidths = [availableWidth];
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
// Calculate base width and distribute remaining pixels
|
|
389
|
-
const baseWidth = Math.floor(availableWidth / actualColCount);
|
|
390
|
-
const remainder = availableWidth % actualColCount;
|
|
391
|
-
computedColWidths = Array(actualColCount).fill(baseWidth);
|
|
392
|
-
// Distribute remainder pixels to first few columns
|
|
393
|
-
for (let i = 0; i < remainder && i < actualColCount; i++) {
|
|
394
|
-
computedColWidths[i] = (computedColWidths[i] || 0) + 1;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
// If we have fewer computed widths than columns, extend the array
|
|
398
|
-
while (computedColWidths.length < colCount) {
|
|
399
|
-
computedColWidths.push(minColWidth);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
const table = new Table({
|
|
403
|
-
head: header,
|
|
404
|
-
colWidths: computedColWidths,
|
|
405
|
-
wordWrap: true,
|
|
406
|
-
wrapOnWordBoundary: true,
|
|
407
|
-
});
|
|
408
|
-
// Ensure all data rows have the same number of columns
|
|
409
|
-
const normalizedData = data.map((row) => {
|
|
410
|
-
if (row.length < colCount) {
|
|
411
|
-
// Pad with empty strings if row has fewer columns
|
|
412
|
-
return [...row, ...Array(colCount - row.length).fill("")];
|
|
413
|
-
}
|
|
414
|
-
if (row.length > colCount) {
|
|
415
|
-
// Truncate if row has more columns
|
|
416
|
-
return row.slice(0, colCount);
|
|
417
|
-
}
|
|
418
|
-
return row;
|
|
419
|
-
});
|
|
420
|
-
table.push(...normalizedData);
|
|
421
|
-
this.writeln(table.toString());
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* Displays a horizontal progress bar in the console.
|
|
425
|
-
* @param current The current value.
|
|
426
|
-
* @param total The target value.
|
|
427
|
-
*/
|
|
428
|
-
displayProgressBar(current, total) {
|
|
429
|
-
const terminalWidth = this.terminalWidth > 0 ? this.terminalWidth : 80; // Default to 80 if columns not available
|
|
430
|
-
// Function to format numbers concisely (e.g., 1.2K, 5M)
|
|
431
|
-
const formatNumber = (num) => {
|
|
432
|
-
if (num < 1000) {
|
|
433
|
-
return num.toString();
|
|
434
|
-
}
|
|
435
|
-
if (num < 1_000_000) {
|
|
436
|
-
return `${(num / 1000).toFixed(1)}K`;
|
|
437
|
-
}
|
|
438
|
-
if (num < 1_000_000_000) {
|
|
439
|
-
return `${(num / 1_000_000).toFixed(1)}M`;
|
|
440
|
-
}
|
|
441
|
-
return `${(num / 1_000_000_000).toFixed(1)}G`;
|
|
442
|
-
};
|
|
443
|
-
const currentFormatted = formatNumber(current);
|
|
444
|
-
const totalFormatted = formatNumber(total);
|
|
445
|
-
const progressText = `${currentFormatted}/${totalFormatted}`;
|
|
446
|
-
const progressTextLength = progressText.length + 1; // Add 1 for space
|
|
447
|
-
const progressBarMaxWidth = Math.max(1, terminalWidth - progressTextLength - 1);
|
|
448
|
-
const percentage = total === 0 ? 1 : current / total;
|
|
449
|
-
const filledWidth = Math.max(0, Math.min(progressBarMaxWidth, Math.floor(percentage * progressBarMaxWidth)));
|
|
450
|
-
const emptyWidth = Math.max(0, progressBarMaxWidth - filledWidth);
|
|
451
|
-
const a = filledWidth / progressBarMaxWidth > 0.5
|
|
452
|
-
? style.red("─")
|
|
453
|
-
: style.yellow("─"); //"█"
|
|
454
|
-
const b = style.gray("─"); // "░"
|
|
455
|
-
const filledBar = a.repeat(filledWidth);
|
|
456
|
-
const emptyBar = b.repeat(emptyWidth);
|
|
457
|
-
// Use \r to move cursor to the beginning of the line for updates
|
|
458
|
-
this.writeln(`\r${filledBar}${emptyBar} ${progressText} `);
|
|
459
|
-
}
|
|
460
|
-
formatMarkdown(content, wrap = false) {
|
|
461
|
-
const columns = this.terminalWidth;
|
|
462
|
-
const formatted = applyMarkdown(content);
|
|
463
|
-
if (wrap) {
|
|
464
|
-
return wrapAnsi(formatted, columns - 6, { trim: false });
|
|
465
|
-
}
|
|
466
|
-
return formatted;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
// Re-export the types
|
|
470
|
-
export * from "./types.js";
|
|
7
|
+
export { alert, getShell, isInteractive } from "./control.js";
|
|
8
|
+
export { emphasize, error, hr, info, success, warn } from "./formatting.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EOL } from "node:os";
|
|
2
|
-
import Table from "cli-table3";
|
|
3
2
|
import { marked } from "marked";
|
|
4
3
|
import { logger } from "../logger.js";
|
|
5
|
-
import {
|
|
4
|
+
import { DEFAULT_HIGHLIGHT_THEME } from "./default-theme.js";
|
|
6
5
|
import { link as terminalLink } from "./formatting.js";
|
|
7
6
|
import { highlight, supportsLanguage } from "./highlight/index.js";
|
|
8
7
|
import { getListNumber } from "./markdown-utils.js";
|
|
9
8
|
import style from "./style.js";
|
|
9
|
+
import { Table } from "./table/index.js";
|
|
10
10
|
function logError(msg) {
|
|
11
11
|
logger.error(msg);
|
|
12
12
|
}
|
|
@@ -28,12 +28,14 @@ function format(token, listDepth = 0, orderedListNumber = null, parent = null) {
|
|
|
28
28
|
if (token.lang && supportsLanguage(token.lang)) {
|
|
29
29
|
return (highlight(token.text, {
|
|
30
30
|
language: token.lang,
|
|
31
|
-
theme:
|
|
31
|
+
theme: DEFAULT_HIGHLIGHT_THEME,
|
|
32
32
|
}) + EOL);
|
|
33
33
|
}
|
|
34
34
|
logError(`Language not supported while highlighting code, falling back to markdown: ${token.lang}`);
|
|
35
|
-
return (highlight(token.text, {
|
|
36
|
-
|
|
35
|
+
return (highlight(token.text, {
|
|
36
|
+
language: "markdown",
|
|
37
|
+
theme: DEFAULT_HIGHLIGHT_THEME,
|
|
38
|
+
}) + EOL);
|
|
37
39
|
}
|
|
38
40
|
case "codespan":
|
|
39
41
|
// inline code
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Inline from sindresorhus/strip-ansi v7.1.0
|
|
2
2
|
const ansiRegex = ({ onlyFirst = false } = {}) => {
|
|
3
|
-
// Valid string terminator sequences are BEL, ESC
|
|
4
|
-
const St = "(
|
|
3
|
+
// Valid string terminator sequences are BEL, ESC\\, and 0x9c
|
|
4
|
+
const St = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
5
5
|
// OSC sequences only: ESC ] ... ST (non-greedy until the first ST)
|
|
6
|
-
const osc = `(
|
|
6
|
+
const osc = `(?:\\u001B\\][\\s\\S]*?${St})`;
|
|
7
7
|
// CSI and related: ESC/C1, optional intermediates, optional params (supports ; and :) then final byte
|
|
8
|
-
const csi = "[
|
|
8
|
+
const csi = "[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";
|
|
9
9
|
const pattern = `${osc}|${csi}`;
|
|
10
10
|
return new RegExp(pattern, onlyFirst ? undefined : "g");
|
|
11
11
|
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type CellOptions, type CharName, type HorizontalAlignment, type TableInstanceOptions, type VerticalAlignment } from "./utils.ts";
|
|
2
|
+
export declare class Cell {
|
|
3
|
+
options: CellOptions;
|
|
4
|
+
content: string;
|
|
5
|
+
colSpan: number;
|
|
6
|
+
rowSpan: number;
|
|
7
|
+
x: number | null;
|
|
8
|
+
y: number | null;
|
|
9
|
+
chars: Record<CharName, string>;
|
|
10
|
+
truncate: string;
|
|
11
|
+
paddingLeft: number;
|
|
12
|
+
paddingRight: number;
|
|
13
|
+
head: string[];
|
|
14
|
+
border: string[];
|
|
15
|
+
fixedWidth: number | null;
|
|
16
|
+
lines: string[];
|
|
17
|
+
desiredWidth: number;
|
|
18
|
+
desiredHeight: number;
|
|
19
|
+
widths: number[];
|
|
20
|
+
heights: number[];
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
hAlign: HorizontalAlignment;
|
|
24
|
+
vAlign: VerticalAlignment;
|
|
25
|
+
drawRight: boolean;
|
|
26
|
+
cells: Cell[][] | null;
|
|
27
|
+
/**
|
|
28
|
+
* A representation of a cell within the table.
|
|
29
|
+
* Implementations must have `init` and `draw` methods,
|
|
30
|
+
* as well as `colSpan`, `rowSpan`, `desiredHeight` and `desiredWidth` properties.
|
|
31
|
+
*/
|
|
32
|
+
constructor(options: CellOptions | string | number | boolean | bigint);
|
|
33
|
+
setOptions(options: CellOptions | string | number | boolean | bigint): void;
|
|
34
|
+
mergeTableOptions(tableOptions: TableInstanceOptions, cells: Cell[][]): void;
|
|
35
|
+
computeLines(tableOptions: TableInstanceOptions): string[];
|
|
36
|
+
wrapLines(computedLines: string[]): string[];
|
|
37
|
+
/**
|
|
38
|
+
* Initializes the Cells data structure.
|
|
39
|
+
*
|
|
40
|
+
* @param tableOptions - A fully populated set of tableOptions.
|
|
41
|
+
* In addition to the standard default values, tableOptions must have fully populated the
|
|
42
|
+
* `colWidths` and `rowWidths` arrays. Those arrays must have lengths equal to the number
|
|
43
|
+
* of columns or rows (respectively) in this table, and each array item must be a Number.
|
|
44
|
+
*/
|
|
45
|
+
init(tableOptions: TableInstanceOptions): void;
|
|
46
|
+
/**
|
|
47
|
+
* Draws the given line of the cell.
|
|
48
|
+
* This default implementation defers to methods `drawTop`, `drawBottom`, `drawLine` and `drawEmpty`.
|
|
49
|
+
* @param lineNum - can be `top`, `bottom` or a numerical line number.
|
|
50
|
+
* @param spanningCell - will be a number if being called from a RowSpanCell, and will represent how
|
|
51
|
+
* many rows below it's being called from. Otherwise it's undefined.
|
|
52
|
+
* @returns {String} The representation of this line.
|
|
53
|
+
*/
|
|
54
|
+
draw(lineNum: "top" | "bottom" | number, spanningCell?: number): string;
|
|
55
|
+
/**
|
|
56
|
+
* Renders the top line of the cell.
|
|
57
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
58
|
+
* @returns {String}
|
|
59
|
+
*/
|
|
60
|
+
drawTop(drawRight: boolean): string;
|
|
61
|
+
_topLeftChar(offset: number): string;
|
|
62
|
+
wrapWithStyleColors(styleProperty: "head" | "border", content: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Renders a line of text.
|
|
65
|
+
* @param lineNum - Which line of text to render. This is not necessarily the line within the cell.
|
|
66
|
+
* There may be top-padding above the first line of text.
|
|
67
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
68
|
+
* @param forceTruncationSymbol - `true` if the rendered text should end with the truncation symbol even
|
|
69
|
+
* if the text fits. This is used when the cell is vertically truncated. If `false` the text should
|
|
70
|
+
* only include the truncation symbol if the text will not fit horizontally within the cell width.
|
|
71
|
+
* @param spanningCell - a number of if being called from a RowSpanCell. (how many rows below). otherwise undefined.
|
|
72
|
+
* @returns {String}
|
|
73
|
+
*/
|
|
74
|
+
drawLine(lineNum: number, drawRight: boolean, forceTruncationSymbol: boolean, spanningCell?: number): string;
|
|
75
|
+
stylizeLine(left: string, content: string, right: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Renders the bottom line of the cell.
|
|
78
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
79
|
+
* @returns {String}
|
|
80
|
+
*/
|
|
81
|
+
drawBottom(drawRight: boolean): string;
|
|
82
|
+
/**
|
|
83
|
+
* Renders a blank line of text within the cell. Used for top and/or bottom padding.
|
|
84
|
+
* @param drawRight - true if this method should render the right edge of the cell.
|
|
85
|
+
* @param spanningCell - a number of if being called from a RowSpanCell. (how many rows below). otherwise undefined.
|
|
86
|
+
* @returns {String}
|
|
87
|
+
*/
|
|
88
|
+
drawEmpty(drawRight: boolean, spanningCell?: number): string;
|
|
89
|
+
}
|
|
90
|
+
export declare class ColSpanCell {
|
|
91
|
+
x: number | null;
|
|
92
|
+
y: number | null;
|
|
93
|
+
colSpan: number;
|
|
94
|
+
draw(lineNum: "top" | "bottom" | number): string;
|
|
95
|
+
init(): void;
|
|
96
|
+
mergeTableOptions(): void;
|
|
97
|
+
}
|
|
98
|
+
export declare class RowSpanCell {
|
|
99
|
+
originalCell: Cell;
|
|
100
|
+
x: number | null;
|
|
101
|
+
y: number | null;
|
|
102
|
+
colSpan: number;
|
|
103
|
+
cellOffset: number;
|
|
104
|
+
offset: number;
|
|
105
|
+
/**
|
|
106
|
+
* A placeholder Cell for a Cell that spans multiple rows.
|
|
107
|
+
* It delegates rendering to the original cell, but adds the appropriate offset.
|
|
108
|
+
*/
|
|
109
|
+
constructor(originalCell: Cell);
|
|
110
|
+
init(tableOptions: TableInstanceOptions): void;
|
|
111
|
+
draw(lineNum: "top" | "bottom" | number): string;
|
|
112
|
+
mergeTableOptions(): void;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=cell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../../../source/terminal/table/cell.ts"],"names":[],"mappings":"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"}
|