pi-tui-prompt-box 0.2.0 → 0.3.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/CHANGELOG.md +6 -0
- package/README.md +14 -6
- package/package.json +4 -4
- package/src/config.ts +15 -6
- package/src/index.ts +1 -1
- package/src/ui/chat-messages.ts +8 -7
- package/src/ui/padded-containers.ts +1 -1
- package/src/ui/padded-footer.ts +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ completion menu, or any other styling extension.
|
|
|
24
24
|
|
|
25
25
|
The accent bar and spinner colors show the selected thinking level:
|
|
26
26
|
|
|
27
|
-

|
|
28
28
|
|
|
29
29
|
## Demo: `Message Colors`
|
|
30
30
|
|
|
@@ -32,6 +32,13 @@ Each message in the chat keeps the color of the thinking level it was sent with:
|
|
|
32
32
|
|
|
33
33
|

|
|
34
34
|
|
|
35
|
+
## Demo: `Message Indent`
|
|
36
|
+
|
|
37
|
+
Set [`userMessageIndent`](#configuration) to move your messages right, for a
|
|
38
|
+
messenger-like look:
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
35
42
|
## Install
|
|
36
43
|
|
|
37
44
|
```bash
|
|
@@ -55,13 +62,14 @@ pi install npm:pi-tui-prompt-box
|
|
|
55
62
|
|
|
56
63
|
## Configuration
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
in the chat, create
|
|
60
|
-
`~/.pi/agent/extensions/pi-tui-prompt-box.json` and run `/reload`:
|
|
65
|
+
Save overrides in `~/.pi/agent/extensions/pi-tui-prompt-box.json` and run `/reload`.
|
|
61
66
|
|
|
62
|
-
```
|
|
67
|
+
```jsonc
|
|
63
68
|
{
|
|
64
|
-
|
|
69
|
+
// Draw user messages in the chat as boxes and hide Pi's thinking level status.
|
|
70
|
+
"userMessageBoxes": true,
|
|
71
|
+
// Add this many columns to the left of each box when userMessageBoxes is on.
|
|
72
|
+
"userMessageIndent": 0
|
|
65
73
|
}
|
|
66
74
|
```
|
|
67
75
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-tui-prompt-box",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A prompt box style for Pi that combines with other styling extensions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"@earendil-works/pi-tui": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@earendil-works/pi-ai": "1.
|
|
43
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
44
|
-
"@earendil-works/pi-tui": "1.
|
|
42
|
+
"@earendil-works/pi-ai": "1.7.0",
|
|
43
|
+
"@earendil-works/pi-coding-agent": "1.7.0",
|
|
44
|
+
"@earendil-works/pi-tui": "1.7.0",
|
|
45
45
|
"@types/node": "^22.20.1",
|
|
46
46
|
"typescript": "^7.0.2"
|
|
47
47
|
},
|
package/src/config.ts
CHANGED
|
@@ -20,6 +20,8 @@ export const CONFIG_FILE_NAME = "pi-tui-prompt-box.json";
|
|
|
20
20
|
export interface PromptBoxConfig {
|
|
21
21
|
/** Draw user messages in the chat as prompt boxes and hide Pi's thinking level status; see doc/ui.md. */
|
|
22
22
|
userMessageBoxes: boolean;
|
|
23
|
+
/** Columns added to the left of the user message boxes; used only with `userMessageBoxes`. */
|
|
24
|
+
userMessageIndent: number;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
/**
|
|
@@ -33,7 +35,7 @@ export interface ConfigLoadResult {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/** Configuration used when no override file exists. */
|
|
36
|
-
export const DEFAULT_CONFIG: Readonly<PromptBoxConfig> = { userMessageBoxes: true };
|
|
38
|
+
export const DEFAULT_CONFIG: Readonly<PromptBoxConfig> = { userMessageBoxes: true, userMessageIndent: 0 };
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* Returns the absolute path of the global override file.
|
|
@@ -78,12 +80,19 @@ function applyOverrides(overrides: object, filePath: string): ConfigLoadResult {
|
|
|
78
80
|
const config = { ...DEFAULT_CONFIG };
|
|
79
81
|
const warnings: string[] = [];
|
|
80
82
|
for (const [key, value] of Object.entries(overrides)) {
|
|
81
|
-
if (key
|
|
83
|
+
if (key === "userMessageBoxes") {
|
|
84
|
+
if (typeof value === "boolean")
|
|
85
|
+
config.userMessageBoxes = value;
|
|
86
|
+
else
|
|
87
|
+
warnings.push(`"${key}" in ${filePath} must be true or false.`);
|
|
88
|
+
} else if (key === "userMessageIndent") {
|
|
89
|
+
if (typeof value === "number" && Number.isInteger(value) && value >= 0)
|
|
90
|
+
config.userMessageIndent = value;
|
|
91
|
+
else
|
|
92
|
+
warnings.push(`"${key}" in ${filePath} must be a non-negative integer.`);
|
|
93
|
+
} else {
|
|
82
94
|
warnings.push(`Unknown key "${key}" in ${filePath}.`);
|
|
83
|
-
|
|
84
|
-
warnings.push(`"${key}" in ${filePath} must be true or false.`);
|
|
85
|
-
else
|
|
86
|
-
config.userMessageBoxes = value;
|
|
95
|
+
}
|
|
87
96
|
}
|
|
88
97
|
|
|
89
98
|
return { config, warnings };
|
package/src/index.ts
CHANGED
|
@@ -86,7 +86,7 @@ export default function promptBox(pi: ExtensionAPI): void {
|
|
|
86
86
|
};
|
|
87
87
|
const chat = config.userMessageBoxes ? findPiContainers(editorTui, editor)?.chat : undefined;
|
|
88
88
|
if (chat)
|
|
89
|
-
restoreChatMessages = styleChatMessages(chat, { readBoxColors, resolveBarColor });
|
|
89
|
+
restoreChatMessages = styleChatMessages(chat, { readBoxColors, resolveBarColor, indent: config.userMessageIndent });
|
|
90
90
|
|
|
91
91
|
// Search before setFooter(): it removes the current footer from the tree before calling the factory
|
|
92
92
|
const builtInFooter = findBuiltInFooter(editorTui);
|
package/src/ui/chat-messages.ts
CHANGED
|
@@ -12,8 +12,6 @@ import { BAR_WIDTH, INNER_PADDING, renderBoxRow } from "./prompt-box-editor.ts";
|
|
|
12
12
|
|
|
13
13
|
// Pi's chat status after a thinking level change; the user message boxes show the level by their color
|
|
14
14
|
const THINKING_LEVEL_STATUS = /^Thinking level: \S+$/;
|
|
15
|
-
// The chat is already moved by the box margins
|
|
16
|
-
const NO_MARGINS = { left: 0, right: 0 };
|
|
17
15
|
// Fields of Pi's Markdown that draw the padding and the background of a user message
|
|
18
16
|
const MARKDOWN_BLOCK_FIELDS = ["paddingX", "paddingY", "defaultTextStyle"] as const;
|
|
19
17
|
|
|
@@ -29,6 +27,8 @@ export interface ChatMessageStyle {
|
|
|
29
27
|
* every render.
|
|
30
28
|
*/
|
|
31
29
|
resolveBarColor: (messageId: string | undefined) => (text: string) => string;
|
|
30
|
+
/** Columns before the user message boxes, on top of the box margins the chat is already moved by. */
|
|
31
|
+
indent: number;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -70,7 +70,7 @@ export function styleChatMessages(chat: ParentComponent, style: ChatMessageStyle
|
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Makes the user `message` render as a prompt box: accent bar, and the text lines between a top and a bottom
|
|
73
|
-
* padding row on the box background; see doc/ui.md.
|
|
73
|
+
* padding row on the box background, moved right by the style indent; see doc/ui.md.
|
|
74
74
|
*
|
|
75
75
|
* Pi's Markdown inside the message keeps rendering the text, without its own padding and background. Pi
|
|
76
76
|
* replaces it when the `outputPad` setting changes, so it is looked up on every render. When it is not found,
|
|
@@ -81,14 +81,15 @@ export function styleChatMessages(chat: ParentComponent, style: ChatMessageStyle
|
|
|
81
81
|
function boxUserMessage(message: UserMessageComponent, style: ChatMessageStyle): () => void {
|
|
82
82
|
const render = message.render.bind(message);
|
|
83
83
|
const barColor = style.resolveBarColor(readMessageId(message));
|
|
84
|
+
const margins = { left: style.indent, right: 0 };
|
|
84
85
|
let unpadded: { markdown: Markdown; restore: () => void } | undefined;
|
|
85
86
|
const restoreMarkdown = () => {
|
|
86
87
|
unpadded?.restore();
|
|
87
88
|
unpadded = undefined;
|
|
88
89
|
};
|
|
89
90
|
|
|
90
|
-
message.render = (width: number): string[] => {
|
|
91
|
-
const textWidth = width - BAR_WIDTH - 2 * INNER_PADDING;
|
|
91
|
+
message.render = (width: number): readonly string[] => {
|
|
92
|
+
const textWidth = width - margins.left - BAR_WIDTH - 2 * INNER_PADDING;
|
|
92
93
|
const markdown = textWidth < 1 ? undefined : findMarkdown(message);
|
|
93
94
|
if (!markdown) {
|
|
94
95
|
restoreMarkdown();
|
|
@@ -102,7 +103,7 @@ function boxUserMessage(message: UserMessageComponent, style: ChatMessageStyle):
|
|
|
102
103
|
if (textLines.length === 0)
|
|
103
104
|
return textLines;
|
|
104
105
|
|
|
105
|
-
const boxStyle = { margins
|
|
106
|
+
const boxStyle = { margins, barColor, colors: style.readBoxColors() };
|
|
106
107
|
|
|
107
108
|
return [
|
|
108
109
|
renderBoxRow("", textWidth, boxStyle),
|
|
@@ -206,7 +207,7 @@ function isStatusText(component: Component): component is StatusText {
|
|
|
206
207
|
*/
|
|
207
208
|
function hideWhile(component: Component, isHidden: () => boolean): () => void {
|
|
208
209
|
const render = component.render.bind(component);
|
|
209
|
-
component.render = (width: number): string[] => (isHidden() ? [] : render(width));
|
|
210
|
+
component.render = (width: number): readonly string[] => (isHidden() ? [] : render(width));
|
|
210
211
|
|
|
211
212
|
return () => {
|
|
212
213
|
Reflect.deleteProperty(component, "render");
|
|
@@ -75,7 +75,7 @@ export function padComponent(
|
|
|
75
75
|
const handleMouse = component.handleMouse?.bind(component);
|
|
76
76
|
const readInnerWidth = (width: number) => width - LEFT_MARGIN - RIGHT_MARGIN - readRightPadding();
|
|
77
77
|
|
|
78
|
-
component.render = (width: number): string[] => {
|
|
78
|
+
component.render = (width: number): readonly string[] => {
|
|
79
79
|
if (!shouldPad()) return render(width);
|
|
80
80
|
const innerWidth = readInnerWidth(width);
|
|
81
81
|
if (innerWidth < 1) return render(width);
|
package/src/ui/padded-footer.ts
CHANGED
|
@@ -105,7 +105,7 @@ export class PaddedFooter implements Component {
|
|
|
105
105
|
this.readRightPadding = readRightPadding;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
render(width: number): string[] {
|
|
108
|
+
render(width: number): readonly string[] {
|
|
109
109
|
const innerWidth = width - LEFT_MARGIN - RIGHT_MARGIN - this.readRightPadding();
|
|
110
110
|
if (innerWidth < 1)
|
|
111
111
|
return this.footer.render(width);
|