pi-open-tui 0.2.11 → 0.2.13
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 +135 -105
- package/README.zh-CN.md +135 -0
- package/extensions/open-tui/config.ts +6 -0
- package/extensions/open-tui/editor.ts +88 -9
- package/extensions/open-tui/index.ts +28 -11
- package/extensions/open-tui/settings-command.ts +27 -5
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,105 +1,135 @@
|
|
|
1
|
-
# pi-open-tui
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **Turn telemetry**
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
1
|
+
# pi-open-tui
|
|
2
|
+
|
|
3
|
+
**English** | [简体中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
A polished terminal interface for the [Pi](https://pi.dev) coding agent. It brings the strongest ideas from pi-haiku, pi-claude-code-tui, and pi-zentui into one configurable extension.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Highlights
|
|
10
|
+
|
|
11
|
+
- **Pi header** with model, thinking level, working directory, and useful slash-command hints
|
|
12
|
+
- **Responsive footer** with Git state, detected runtime, context usage, token counts, cost, and extension status
|
|
13
|
+
- **Framed editor** with block, bar, and underline cursor styles
|
|
14
|
+
- **Project awareness** for 50+ runtimes and detailed Git states, including ahead/behind, staged, modified, untracked, stashed, and detached HEAD
|
|
15
|
+
- **Turn telemetry** for TPS, time to first token (TTFT), duration, stalls, tokens, and list-price rate
|
|
16
|
+
- **Interactive settings** through `/open-tui`, available in English and Simplified Chinese
|
|
17
|
+
- **Public Pi APIs only**: no prototype patching
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Pi 0.80 or later
|
|
22
|
+
- A terminal with UTF-8 and color support
|
|
23
|
+
- A [Nerd Font](https://www.nerdfonts.com/font-downloads) for the full icon set (optional; ASCII icons are built in)
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
Install the extension:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pi install npm:pi-open-tui
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or try it for one session:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pi -e npm:pi-open-tui
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Font and icons
|
|
40
|
+
|
|
41
|
+
Download any patched font from the official [Nerd Fonts downloads page](https://www.nerdfonts.com/font-downloads) or [latest GitHub release](https://github.com/ryanoasis/nerd-fonts/releases/latest). Install it, select that font in your terminal profile, and restart the terminal.
|
|
42
|
+
|
|
43
|
+
The default `auto` mode detects the terminal environment, not the installed font file. If icons appear as boxes or incorrect symbols, open `/open-tui` and choose one of these modes under **Appearance**:
|
|
44
|
+
|
|
45
|
+
- `nerd`: force Nerd Font icons after configuring a Nerd Font in the terminal
|
|
46
|
+
- `ascii`: use plain-text icons with no patched font required
|
|
47
|
+
- `auto`: use Nerd Font icons in recognized terminals and ASCII elsewhere
|
|
48
|
+
|
|
49
|
+
If the font is installed but `auto` still selects ASCII, choose `nerd` explicitly. In VS Code, Windows Terminal, and similar apps, configure the font in the terminal profile rather than only installing it in the operating system.
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
Run `/open-tui` to open the settings dialog. It provides **General**, **Appearance**, **Footer**, and **Telemetry** tabs. Settings are stored in `~/.pi/agent/open-tui.json`:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"enabled": true,
|
|
58
|
+
"settingsLanguage": "en",
|
|
59
|
+
"cursorStyle": "block",
|
|
60
|
+
"icons": {
|
|
61
|
+
"mode": "auto"
|
|
62
|
+
},
|
|
63
|
+
"footerSegments": {
|
|
64
|
+
"cwd": true,
|
|
65
|
+
"sessionName": false,
|
|
66
|
+
"gitBranch": true,
|
|
67
|
+
"gitStatus": true,
|
|
68
|
+
"gitCommit": false,
|
|
69
|
+
"runtime": true,
|
|
70
|
+
"context": true,
|
|
71
|
+
"tokens": true,
|
|
72
|
+
"cost": true,
|
|
73
|
+
"extensionStatuses": true
|
|
74
|
+
},
|
|
75
|
+
"telemetry": {
|
|
76
|
+
"enabled": true,
|
|
77
|
+
"tps": true,
|
|
78
|
+
"ttft": true,
|
|
79
|
+
"duration": true,
|
|
80
|
+
"tokens": true,
|
|
81
|
+
"stalls": true,
|
|
82
|
+
"cost": true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Key options:
|
|
88
|
+
|
|
89
|
+
| Option | Values | Notes |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| `settingsLanguage` | `en`, `zh` | Changes the `/open-tui` interface language |
|
|
92
|
+
| `cursorStyle` | `block`, `bar`, `underline` | `bar` and `underline` require terminal cursor-shape support |
|
|
93
|
+
| `icons.mode` | `auto`, `nerd`, `ascii` | Controls footer and telemetry icons |
|
|
94
|
+
| `footerSegments` | Boolean flags | Shows or hides individual footer data |
|
|
95
|
+
| `telemetry` | Boolean flags | Enables telemetry and its individual measurements |
|
|
96
|
+
|
|
97
|
+
`sessionName` appears only when the session has a name. `gitCommit` shows the short hash and tag in detached HEAD state. Disabling `extensionStatuses` hides the entire extension status line, including MCP status.
|
|
98
|
+
|
|
99
|
+
## Turn telemetry
|
|
100
|
+
|
|
101
|
+
After each complete agent run, pi-open-tui shows one transient result. Tool-call turns are combined into that result:
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
> TPS 42.5 tok/s | ~ TTFT 1.2s | + 29.7s | ↑ 567 | ↓ 1.2k | ! stall 1x / 4.3s | $ $3.60/M
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
TPS is calculated from all provider-reported assistant output tokens divided by the total generation time across the run. Timing starts at `turn_start` and ends at the assistant `message_end`, so it includes TTFT, hidden reasoning, buffering, and stalls; tool execution between turns is excluded. Runs without output tokens or measurable generation time show `TPS —`.
|
|
108
|
+
|
|
109
|
+
The `$ / M` value is the model's list-price rate from `usage.cost.total`, not the cumulative session cost shown in the footer. Every telemetry field can be toggled from the **Telemetry** tab.
|
|
110
|
+
|
|
111
|
+
## Local development
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm install
|
|
115
|
+
npm test
|
|
116
|
+
npm run typecheck
|
|
117
|
+
pi -e .
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Acknowledgements
|
|
121
|
+
|
|
122
|
+
This project builds on several Pi community packages:
|
|
123
|
+
|
|
124
|
+
- **[pi-haiku](https://github.com/nnocte/pi-haiku)** — two-line footer structure and working timer
|
|
125
|
+
- **[pi-claude-code-tui](https://github.com/Phoobobo/pi-claude-code-tui)** — Pi logo frames and rounded editor border technique
|
|
126
|
+
- **[pi-zentui](https://github.com/lmilojevicc/pi-zentui)** — Starship-style footer segments, runtime detection, session lifecycle, and settings UI pattern
|
|
127
|
+
- **[pi-tps](https://github.com/monotykamary/pi-tps)** — turn timing, stall detection, and conservative TPS measurement
|
|
128
|
+
|
|
129
|
+
The logo frames are derived from Pi's official install script (`pi.dev/install.sh`). Runtime detection and Git porcelain parsing borrow structure from `pi-zentui`.
|
|
130
|
+
|
|
131
|
+
Special thanks to the **[LINUX DO](https://linux.do)** community for its support.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
[MIT](./LICENSE)
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# pi-open-tui
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | **简体中文**
|
|
4
|
+
|
|
5
|
+
一个为 [Pi](https://pi.dev) 编程代理打造的终端界面扩展,将 pi-haiku、pi-claude-code-tui 与 pi-zentui 的优秀设计整合为统一、可配置的使用体验。
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## 功能亮点
|
|
10
|
+
|
|
11
|
+
- **Pi 顶栏**:显示模型、思考等级、当前目录和常用斜杠命令提示
|
|
12
|
+
- **自适应底栏**:集中展示 Git 状态、运行环境、上下文用量、Token、费用和扩展状态
|
|
13
|
+
- **带边框的编辑器**:支持块状、竖线和下划线三种光标样式
|
|
14
|
+
- **项目环境感知**:识别 50 多种运行环境,并展示 ahead/behind、已暂存、已修改、未跟踪、stash 和 detached HEAD 等 Git 状态
|
|
15
|
+
- **单轮遥测**:展示 TPS、首 Token 延迟(TTFT)、耗时、停顿、Token 数量和模型标价速率
|
|
16
|
+
- **交互式设置**:通过 `/open-tui` 配置,并支持英文和简体中文界面
|
|
17
|
+
- **仅使用 Pi 公共 API**:不修改原型,降低 Pi 升级带来的兼容风险
|
|
18
|
+
|
|
19
|
+
## 环境要求
|
|
20
|
+
|
|
21
|
+
- Pi 0.80 或更高版本
|
|
22
|
+
- 支持 UTF-8 和彩色输出的终端
|
|
23
|
+
- 使用完整图标集时需要 [Nerd Font](https://www.nerdfonts.com/font-downloads)(可选;内置 ASCII 图标)
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
安装扩展:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pi install npm:pi-open-tui
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
也可以只在当前会话中试用:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pi -e npm:pi-open-tui
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 字体与图标
|
|
40
|
+
|
|
41
|
+
可从 [Nerd Fonts 官方下载页](https://www.nerdfonts.com/font-downloads)或 [GitHub 最新版本](https://github.com/ryanoasis/nerd-fonts/releases/latest)下载任意已修补字体。安装后,请在终端配置中选择该字体,并重启终端。
|
|
42
|
+
|
|
43
|
+
默认的 `auto` 模式检测的是终端环境,无法确认终端当前实际使用的字体。如果图标显示为方框、乱码或错误符号,请打开 `/open-tui`,在**外观**页选择合适的模式:
|
|
44
|
+
|
|
45
|
+
- `nerd`:终端已配置 Nerd Font 时,强制使用 Nerd Font 图标
|
|
46
|
+
- `ascii`:使用纯文本图标,无需安装修补字体
|
|
47
|
+
- `auto`:在已识别的终端中使用 Nerd Font 图标,其他环境回退到 ASCII
|
|
48
|
+
|
|
49
|
+
如果已经安装字体,但 `auto` 仍选择 ASCII,请手动切换为 `nerd`。使用 VS Code、Windows Terminal 等应用时,只在操作系统中安装字体还不够,还需要在对应的终端配置中选中该字体。
|
|
50
|
+
|
|
51
|
+
## 配置
|
|
52
|
+
|
|
53
|
+
运行 `/open-tui` 打开设置窗口,其中包含**常规**、**外观**、**底栏**和**遥测**四个页面。设置保存在 `~/.pi/agent/open-tui.json`:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"enabled": true,
|
|
58
|
+
"settingsLanguage": "zh",
|
|
59
|
+
"cursorStyle": "block",
|
|
60
|
+
"icons": {
|
|
61
|
+
"mode": "auto"
|
|
62
|
+
},
|
|
63
|
+
"footerSegments": {
|
|
64
|
+
"cwd": true,
|
|
65
|
+
"sessionName": false,
|
|
66
|
+
"gitBranch": true,
|
|
67
|
+
"gitStatus": true,
|
|
68
|
+
"gitCommit": false,
|
|
69
|
+
"runtime": true,
|
|
70
|
+
"context": true,
|
|
71
|
+
"tokens": true,
|
|
72
|
+
"cost": true,
|
|
73
|
+
"extensionStatuses": true
|
|
74
|
+
},
|
|
75
|
+
"telemetry": {
|
|
76
|
+
"enabled": true,
|
|
77
|
+
"tps": true,
|
|
78
|
+
"ttft": true,
|
|
79
|
+
"duration": true,
|
|
80
|
+
"tokens": true,
|
|
81
|
+
"stalls": true,
|
|
82
|
+
"cost": true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
主要选项:
|
|
88
|
+
|
|
89
|
+
| 选项 | 可选值 | 说明 |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| `settingsLanguage` | `en`、`zh` | 切换 `/open-tui` 设置界面的语言 |
|
|
92
|
+
| `cursorStyle` | `block`、`bar`、`underline` | `bar` 和 `underline` 需要终端支持光标形状转义序列 |
|
|
93
|
+
| `icons.mode` | `auto`、`nerd`、`ascii` | 控制底栏和遥测通知使用的图标 |
|
|
94
|
+
| `footerSegments` | 布尔开关 | 分别控制底栏中的各项数据 |
|
|
95
|
+
| `telemetry` | 布尔开关 | 控制遥测总开关和各项指标 |
|
|
96
|
+
|
|
97
|
+
`sessionName` 仅在会话有名称时显示;`gitCommit` 会在 detached HEAD 状态下显示短哈希和标签;关闭 `extensionStatuses` 会隐藏整行扩展状态,其中也包括 MCP 状态。
|
|
98
|
+
|
|
99
|
+
## 单轮遥测
|
|
100
|
+
|
|
101
|
+
每次 Agent 完整运行结束后,pi-open-tui 会显示一条临时结果,并将其中的多个工具调用轮次合并统计:
|
|
102
|
+
|
|
103
|
+
```text
|
|
104
|
+
> TPS 42.5 tok/s | ~ TTFT 1.2s | + 29.7s | ↑ 567 | ↓ 1.2k | ! stall 1x / 4.3s | $ $3.60/M
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
TPS 的计算方式是:将本次运行中服务商报告的全部 Assistant 输出 Token,除以各个生成轮次的总耗时。计时范围从 `turn_start` 到 Assistant 的 `message_end`,包含 TTFT、隐藏推理、缓冲和停顿,但不包含轮次之间的工具执行时间。没有输出 Token 或无法测得生成时间时,会显示 `TPS —`。
|
|
108
|
+
|
|
109
|
+
`$ / M` 表示根据 `usage.cost.total` 得到的模型标价速率,不是底栏中的会话累计费用。所有遥测字段都可以在**遥测**页单独开关。
|
|
110
|
+
|
|
111
|
+
## 本地开发
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm install
|
|
115
|
+
npm test
|
|
116
|
+
npm run typecheck
|
|
117
|
+
pi -e .
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## 致谢
|
|
121
|
+
|
|
122
|
+
本项目基于多个 Pi 社区包的工作:
|
|
123
|
+
|
|
124
|
+
- **[pi-haiku](https://github.com/nnocte/pi-haiku)** — 双行底栏结构和工作计时器
|
|
125
|
+
- **[pi-claude-code-tui](https://github.com/Phoobobo/pi-claude-code-tui)** — Pi Logo 帧与圆角编辑器边框技术
|
|
126
|
+
- **[pi-zentui](https://github.com/lmilojevicc/pi-zentui)** — Starship 风格底栏、运行环境检测、会话生命周期和设置界面模式
|
|
127
|
+
- **[pi-tps](https://github.com/monotykamary/pi-tps)** — 单轮计时、停顿检测和保守的 TPS 计算方式
|
|
128
|
+
|
|
129
|
+
Logo 帧源自 Pi 官方安装脚本(`pi.dev/install.sh`)。运行环境检测和 Git porcelain 解析借鉴了 `pi-zentui` 的结构。
|
|
130
|
+
|
|
131
|
+
特别感谢 **[LINUX DO](https://linux.do)** 社区的支持。
|
|
132
|
+
|
|
133
|
+
## 许可证
|
|
134
|
+
|
|
135
|
+
[MIT](./LICENSE)
|
|
@@ -4,6 +4,7 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
|
4
4
|
import type { IconMode } from "./icons.ts";
|
|
5
5
|
|
|
6
6
|
export type SettingsLanguage = "en" | "zh";
|
|
7
|
+
export type CursorStyle = "block" | "bar" | "underline";
|
|
7
8
|
|
|
8
9
|
export type { IconMode } from "./icons.ts";
|
|
9
10
|
|
|
@@ -33,6 +34,7 @@ export interface TelemetryConfig {
|
|
|
33
34
|
export interface OpenTuiConfig {
|
|
34
35
|
enabled: boolean;
|
|
35
36
|
settingsLanguage: SettingsLanguage;
|
|
37
|
+
cursorStyle: CursorStyle;
|
|
36
38
|
icons: {
|
|
37
39
|
mode: IconMode;
|
|
38
40
|
};
|
|
@@ -43,6 +45,7 @@ export interface OpenTuiConfig {
|
|
|
43
45
|
export const DEFAULT_CONFIG: OpenTuiConfig = {
|
|
44
46
|
enabled: true,
|
|
45
47
|
settingsLanguage: "en",
|
|
48
|
+
cursorStyle: "block",
|
|
46
49
|
icons: {
|
|
47
50
|
mode: "auto",
|
|
48
51
|
},
|
|
@@ -122,6 +125,9 @@ export function loadConfig(notify?: (msg: string, level: "warning" | "info") =>
|
|
|
122
125
|
if (config.settingsLanguage !== "en" && config.settingsLanguage !== "zh") {
|
|
123
126
|
config.settingsLanguage = DEFAULT_CONFIG.settingsLanguage;
|
|
124
127
|
}
|
|
128
|
+
if (config.cursorStyle !== "block" && config.cursorStyle !== "bar" && config.cursorStyle !== "underline") {
|
|
129
|
+
config.cursorStyle = DEFAULT_CONFIG.cursorStyle;
|
|
130
|
+
}
|
|
125
131
|
return config;
|
|
126
132
|
} catch (err) {
|
|
127
133
|
notify?.(`open-tui config parse error: ${err instanceof Error ? err.message : String(err)}`, "warning");
|
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
type KeybindingsManager,
|
|
6
6
|
} from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import type { EditorTheme, TUI } from "@earendil-works/pi-tui";
|
|
8
|
-
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
8
|
+
import { CURSOR_MARKER, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
9
|
+
import type { CursorStyle } from "./config.ts";
|
|
9
10
|
import { findBottomBorderIndex, isEditorBorderLine, stripAnsi } from "./utils.ts";
|
|
10
11
|
|
|
11
12
|
function fillLine(content: string, width: number): string {
|
|
@@ -14,6 +15,27 @@ function fillLine(content: string, width: number): string {
|
|
|
14
15
|
return `${truncated}${pad}`;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
const CURSOR_STYLE_SEQUENCES: Partial<Record<CursorStyle, string>> = {
|
|
19
|
+
bar: "\x1b[6 q",
|
|
20
|
+
underline: "\x1b[4 q",
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_CURSOR_STYLE_SEQUENCE = "\x1b[0 q";
|
|
23
|
+
|
|
24
|
+
function removeSoftwareCursor(line: string, cursorMarker = ""): string {
|
|
25
|
+
return line.replace(/\x1b\[7m([\s\S]*?)\x1b\[0m/g, (_match, cursor: string) => {
|
|
26
|
+
const replacement = `${cursorMarker}${cursor}`;
|
|
27
|
+
cursorMarker = "";
|
|
28
|
+
return replacement;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function configureCursor(tui: TUI, cursorStyle: CursorStyle): void {
|
|
33
|
+
if (cursorStyle === "block") return;
|
|
34
|
+
tui.setShowHardwareCursor(true);
|
|
35
|
+
const sequence = CURSOR_STYLE_SEQUENCES[cursorStyle];
|
|
36
|
+
if (sequence) tui.terminal.write(sequence);
|
|
37
|
+
}
|
|
38
|
+
|
|
17
39
|
function roundedBorder(
|
|
18
40
|
width: number,
|
|
19
41
|
kind: "top" | "bottom",
|
|
@@ -39,13 +61,18 @@ function roundedBorder(
|
|
|
39
61
|
export class OpenTuiEditor extends CustomEditor {
|
|
40
62
|
private readonly getRail: () => string;
|
|
41
63
|
private readonly getBorder: (s: string) => string;
|
|
64
|
+
private cursorStyle: CursorStyle;
|
|
65
|
+
private previewHardwareCursor = false;
|
|
42
66
|
|
|
43
67
|
constructor(
|
|
44
68
|
tui: TUI,
|
|
45
69
|
editorTheme: EditorTheme,
|
|
46
70
|
keybindings: KeybindingsManager,
|
|
71
|
+
cursorStyle: CursorStyle = "block",
|
|
47
72
|
) {
|
|
48
73
|
super(tui, editorTheme, keybindings, { paddingX: 0 });
|
|
74
|
+
this.cursorStyle = cursorStyle;
|
|
75
|
+
configureCursor(tui, cursorStyle);
|
|
49
76
|
// ponytail: route the frame through this.borderColor so Pi can recolor it
|
|
50
77
|
// via updateEditorBorderColor() — bash mode ("! " prefix → green) and
|
|
51
78
|
// thinking-level borders both flow through this one property.
|
|
@@ -58,14 +85,44 @@ export class OpenTuiEditor extends CustomEditor {
|
|
|
58
85
|
super.setPaddingX(0);
|
|
59
86
|
}
|
|
60
87
|
|
|
88
|
+
setCursorStyle(cursorStyle: CursorStyle, blockHardwareCursor = false): void {
|
|
89
|
+
const styleChanged = cursorStyle !== this.cursorStyle;
|
|
90
|
+
this.previewHardwareCursor = cursorStyle !== "block";
|
|
91
|
+
this.cursorStyle = cursorStyle;
|
|
92
|
+
if (styleChanged) {
|
|
93
|
+
if (cursorStyle === "block") {
|
|
94
|
+
this.tui.terminal.write(DEFAULT_CURSOR_STYLE_SEQUENCE);
|
|
95
|
+
this.tui.setShowHardwareCursor(blockHardwareCursor);
|
|
96
|
+
} else {
|
|
97
|
+
configureCursor(this.tui, cursorStyle);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.tui.requestRender();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private renderBase(width: number): string[] {
|
|
104
|
+
const renderedLines = super.render(width);
|
|
105
|
+
if (this.cursorStyle === "block") return renderedLines;
|
|
106
|
+
|
|
107
|
+
// A focused overlay suppresses the editor's cursor marker. Preserve its
|
|
108
|
+
// position only for the live settings preview, then clear it on refocus.
|
|
109
|
+
let cursorMarker = this.previewHardwareCursor && !this.focused ? CURSOR_MARKER : "";
|
|
110
|
+
if (this.focused) this.previewHardwareCursor = false;
|
|
111
|
+
return renderedLines.map((line) => {
|
|
112
|
+
const rendered = removeSoftwareCursor(line, cursorMarker);
|
|
113
|
+
if (rendered !== line) cursorMarker = "";
|
|
114
|
+
return rendered;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
61
118
|
render(width: number): string[] {
|
|
62
|
-
if (width < 4) return
|
|
119
|
+
if (width < 4) return this.renderBase(width);
|
|
63
120
|
|
|
64
121
|
const rail = this.getRail();
|
|
65
122
|
const borderPaint = this.getBorder;
|
|
66
123
|
// ponytail: 1-char rail + 1-char gap on each side = 4 chars of chrome.
|
|
67
124
|
const innerWidth = Math.max(0, width - 4);
|
|
68
|
-
const baseLines =
|
|
125
|
+
const baseLines = this.renderBase(innerWidth);
|
|
69
126
|
const bottomIdx = findBottomBorderIndex(baseLines);
|
|
70
127
|
|
|
71
128
|
const result: string[] = [];
|
|
@@ -90,11 +147,33 @@ export class OpenTuiEditor extends CustomEditor {
|
|
|
90
147
|
}
|
|
91
148
|
}
|
|
92
149
|
|
|
93
|
-
export function installEditor(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
150
|
+
export function installEditor(
|
|
151
|
+
_pi: ExtensionAPI,
|
|
152
|
+
ctx: ExtensionContext,
|
|
153
|
+
cursorStyle: CursorStyle = "block",
|
|
154
|
+
) {
|
|
155
|
+
let activeTui: TUI | undefined;
|
|
156
|
+
let activeEditor: OpenTuiEditor | undefined;
|
|
157
|
+
let previousHardwareCursor: boolean | undefined;
|
|
158
|
+
let currentCursorStyle = cursorStyle;
|
|
159
|
+
|
|
160
|
+
ctx.ui.setEditorComponent((tui, editorTheme, keybindings) => {
|
|
161
|
+
activeTui = tui;
|
|
162
|
+
previousHardwareCursor = tui.getShowHardwareCursor();
|
|
163
|
+
activeEditor = new OpenTuiEditor(tui, editorTheme, keybindings, currentCursorStyle);
|
|
164
|
+
return activeEditor;
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
setCursorStyle(nextCursorStyle: CursorStyle): void {
|
|
168
|
+
currentCursorStyle = nextCursorStyle;
|
|
169
|
+
activeEditor?.setCursorStyle(nextCursorStyle, previousHardwareCursor);
|
|
170
|
+
},
|
|
171
|
+
cleanup(): void {
|
|
172
|
+
ctx.ui.setEditorComponent(undefined);
|
|
173
|
+
if (activeTui) {
|
|
174
|
+
if (currentCursorStyle !== "block") activeTui.terminal.write(DEFAULT_CURSOR_STYLE_SEQUENCE);
|
|
175
|
+
if (previousHardwareCursor !== undefined) activeTui.setShowHardwareCursor(previousHardwareCursor);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
99
178
|
};
|
|
100
179
|
}
|
|
@@ -26,6 +26,13 @@ function isInteractiveLaunch(): boolean {
|
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
type PendingUiChange = "install" | "uninstall";
|
|
30
|
+
|
|
31
|
+
export function getPendingUiChange(enabled: boolean, active: boolean): PendingUiChange | undefined {
|
|
32
|
+
if (enabled === active) return undefined;
|
|
33
|
+
return enabled ? "install" : "uninstall";
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
function clearVisibleScreen(): void {
|
|
30
37
|
if (process.stdout.isTTY) {
|
|
31
38
|
process.stdout.write("\x1b[2J\x1b[H");
|
|
@@ -53,7 +60,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
53
60
|
let workingTimer: ReturnType<typeof setInterval> | undefined;
|
|
54
61
|
let cleanupHeader: (() => void) | undefined;
|
|
55
62
|
let cleanupFooter: (() => void) | undefined;
|
|
56
|
-
let
|
|
63
|
+
let editor: ReturnType<typeof installEditor> | undefined;
|
|
64
|
+
let pendingUiChange: PendingUiChange | undefined;
|
|
57
65
|
|
|
58
66
|
const getThinkingLevel = () => (sessionLifecycle.isCurrent() ? pi.getThinkingLevel() : "off");
|
|
59
67
|
|
|
@@ -79,7 +87,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
79
87
|
},
|
|
80
88
|
},
|
|
81
89
|
);
|
|
82
|
-
|
|
90
|
+
editor = installEditor(pi, ctx, config.cursorStyle);
|
|
83
91
|
active = true;
|
|
84
92
|
}
|
|
85
93
|
};
|
|
@@ -89,10 +97,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
89
97
|
if (active) {
|
|
90
98
|
cleanupHeader?.();
|
|
91
99
|
cleanupFooter?.();
|
|
92
|
-
|
|
100
|
+
editor?.cleanup();
|
|
93
101
|
cleanupHeader = undefined;
|
|
94
102
|
cleanupFooter = undefined;
|
|
95
|
-
|
|
103
|
+
editor = undefined;
|
|
96
104
|
requestFooterRender = undefined;
|
|
97
105
|
active = false;
|
|
98
106
|
}
|
|
@@ -264,15 +272,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
264
272
|
registerSettingsCommand(pi, {
|
|
265
273
|
getConfig: () => config,
|
|
266
274
|
onConfigChanged: (newConfig) => {
|
|
267
|
-
const
|
|
275
|
+
const cursorStyleChanged = config.cursorStyle !== newConfig.cursorStyle;
|
|
268
276
|
saveConfig(newConfig);
|
|
269
277
|
config = newConfig;
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
278
|
+
if (cursorStyleChanged && active && editor) {
|
|
279
|
+
editor.setCursorStyle(newConfig.cursorStyle);
|
|
280
|
+
}
|
|
281
|
+
if (lastCtx) {
|
|
282
|
+
pendingUiChange = getPendingUiChange(newConfig.enabled, active);
|
|
276
283
|
}
|
|
277
284
|
const gitNeeded = newConfig.footerSegments.gitBranch || newConfig.footerSegments.gitStatus || newConfig.footerSegments.gitCommit;
|
|
278
285
|
if (lastCtx && gitNeeded) {
|
|
@@ -282,5 +289,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
282
289
|
}
|
|
283
290
|
requestFooterRender?.();
|
|
284
291
|
},
|
|
292
|
+
onOverlayClosed: () => {
|
|
293
|
+
if (!lastCtx || pendingUiChange === undefined) return;
|
|
294
|
+
const change = pendingUiChange;
|
|
295
|
+
pendingUiChange = undefined;
|
|
296
|
+
if (!config.enabled || change === "uninstall") {
|
|
297
|
+
uninstallUi(lastCtx);
|
|
298
|
+
} else {
|
|
299
|
+
applyUi(lastCtx);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
285
302
|
});
|
|
286
303
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
type TUI,
|
|
9
9
|
Text,
|
|
10
10
|
} from "@earendil-works/pi-tui";
|
|
11
|
-
import type { IconMode, OpenTuiConfig, SettingsLanguage } from "./config.ts";
|
|
11
|
+
import type { CursorStyle, IconMode, OpenTuiConfig, SettingsLanguage } from "./config.ts";
|
|
12
12
|
|
|
13
13
|
interface SettingItem {
|
|
14
14
|
id: string;
|
|
@@ -23,11 +23,12 @@ const TABS: Tab[] = ["features", "icons", "segments", "telemetry"];
|
|
|
23
23
|
const COPY = {
|
|
24
24
|
en: {
|
|
25
25
|
title: "Open TUI Settings",
|
|
26
|
-
tabs: { features: "General", icons: "
|
|
26
|
+
tabs: { features: "General", icons: "Appearance", segments: "Footer", telemetry: "Telemetry" },
|
|
27
27
|
hint: "Tab/Shift+Tab/←/→: tabs · ↑/↓: move · Enter/Space: change · Esc/q: close",
|
|
28
28
|
labels: {
|
|
29
29
|
enabled: "Enabled",
|
|
30
30
|
language: "Language",
|
|
31
|
+
cursorStyle: "Cursor style",
|
|
31
32
|
iconMode: "Icon mode",
|
|
32
33
|
cwd: "CWD",
|
|
33
34
|
sessionName: "Session name",
|
|
@@ -48,16 +49,18 @@ const COPY = {
|
|
|
48
49
|
on: "On",
|
|
49
50
|
off: "Off",
|
|
50
51
|
languages: { en: "English", zh: "简体中文" },
|
|
52
|
+
cursorStyles: { block: "Block", bar: "Bar", underline: "Underline" },
|
|
51
53
|
icons: { auto: "Auto", nerd: "Nerd", ascii: "ASCII" },
|
|
52
54
|
},
|
|
53
55
|
},
|
|
54
56
|
zh: {
|
|
55
57
|
title: "Open TUI 设置",
|
|
56
|
-
tabs: { features: "常规", icons: "
|
|
58
|
+
tabs: { features: "常规", icons: "外观", segments: "Footer", telemetry: "遥测" },
|
|
57
59
|
hint: "Tab/Shift+Tab/←/→:切页 · ↑/↓:移动 · Enter/Space:更改 · Esc/q:关闭",
|
|
58
60
|
labels: {
|
|
59
61
|
enabled: "启用",
|
|
60
62
|
language: "语言",
|
|
63
|
+
cursorStyle: "光标样式",
|
|
61
64
|
iconMode: "图标模式",
|
|
62
65
|
cwd: "当前目录",
|
|
63
66
|
sessionName: "会话名",
|
|
@@ -78,6 +81,7 @@ const COPY = {
|
|
|
78
81
|
on: "开启",
|
|
79
82
|
off: "关闭",
|
|
80
83
|
languages: { en: "English", zh: "简体中文" },
|
|
84
|
+
cursorStyles: { block: "块", bar: "竖线", underline: "下划线" },
|
|
81
85
|
icons: { auto: "自动", nerd: "Nerd", ascii: "ASCII" },
|
|
82
86
|
},
|
|
83
87
|
},
|
|
@@ -110,6 +114,13 @@ function toggleLanguage(config: OpenTuiConfig): OpenTuiConfig {
|
|
|
110
114
|
return { ...config, settingsLanguage: config.settingsLanguage === "en" ? "zh" : "en" };
|
|
111
115
|
}
|
|
112
116
|
|
|
117
|
+
function cycleCursorStyle(config: OpenTuiConfig): OpenTuiConfig {
|
|
118
|
+
const order: CursorStyle[] = ["block", "bar", "underline"];
|
|
119
|
+
const currentIdx = order.indexOf(config.cursorStyle);
|
|
120
|
+
const next = order[(currentIdx + 1) % order.length]!;
|
|
121
|
+
return { ...config, cursorStyle: next };
|
|
122
|
+
}
|
|
123
|
+
|
|
113
124
|
function toggleTelemetry(config: OpenTuiConfig, key: keyof OpenTuiConfig["telemetry"]): OpenTuiConfig {
|
|
114
125
|
return {
|
|
115
126
|
...config,
|
|
@@ -125,7 +136,10 @@ function buildFeaturesItems(config: OpenTuiConfig, copy: SettingsCopy): SettingI
|
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
function buildIconsItems(config: OpenTuiConfig, copy: SettingsCopy): SettingItem[] {
|
|
128
|
-
return [
|
|
139
|
+
return [
|
|
140
|
+
{ id: "mode", label: copy.labels.iconMode, currentValue: copy.values.icons[config.icons.mode] },
|
|
141
|
+
{ id: "cursorStyle", label: copy.labels.cursorStyle, currentValue: copy.values.cursorStyles[config.cursorStyle] },
|
|
142
|
+
];
|
|
129
143
|
}
|
|
130
144
|
|
|
131
145
|
function buildSegmentsItems(config: OpenTuiConfig, copy: SettingsCopy): SettingItem[] {
|
|
@@ -178,7 +192,10 @@ function handleSettingChange(
|
|
|
178
192
|
if (itemId === "enabled") return toggleEnabled(config);
|
|
179
193
|
if (itemId === "settingsLanguage") return toggleLanguage(config);
|
|
180
194
|
}
|
|
181
|
-
if (tab === "icons"
|
|
195
|
+
if (tab === "icons") {
|
|
196
|
+
if (itemId === "mode") return cycleIconMode(config);
|
|
197
|
+
if (itemId === "cursorStyle") return cycleCursorStyle(config);
|
|
198
|
+
}
|
|
182
199
|
if (tab === "segments") {
|
|
183
200
|
return toggleSetting(config, itemId as keyof OpenTuiConfig["footerSegments"]);
|
|
184
201
|
}
|
|
@@ -334,6 +351,7 @@ export function registerSettingsCommand(
|
|
|
334
351
|
hooks: {
|
|
335
352
|
getConfig: () => OpenTuiConfig;
|
|
336
353
|
onConfigChanged: (config: OpenTuiConfig) => void;
|
|
354
|
+
onOverlayClosed?: () => void;
|
|
337
355
|
},
|
|
338
356
|
): void {
|
|
339
357
|
pi.registerCommand("open-tui", {
|
|
@@ -356,6 +374,10 @@ export function registerSettingsCommand(
|
|
|
356
374
|
},
|
|
357
375
|
};
|
|
358
376
|
}, { overlay: true });
|
|
377
|
+
// Overlay is closed and focus is back on the editor. Deferred UI changes
|
|
378
|
+
// (e.g. toggling the extension) run here, so pi core's focus restore
|
|
379
|
+
// cannot strand the overlay without keyboard input.
|
|
380
|
+
hooks.onOverlayClosed?.();
|
|
359
381
|
},
|
|
360
382
|
});
|
|
361
383
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-open-tui",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "A polished TUI for Pi coding agent: animated logo header, Starship-style footer, rounded editor with model metadata, and prompt-box user messages.
|
|
3
|
+
"version": "0.2.13",
|
|
4
|
+
"description": "A polished TUI for Pi coding agent: animated logo header, Starship-style footer, rounded editor with model metadata, and prompt-box user messages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"extensions/",
|
|
22
22
|
"assets/",
|
|
23
23
|
"README.md",
|
|
24
|
+
"README.zh-CN.md",
|
|
24
25
|
"LICENSE"
|
|
25
26
|
],
|
|
26
27
|
"scripts": {
|