@yivan-lab/pretty-please 1.0.0 → 1.2.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 +381 -28
- package/bin/pls.tsx +1138 -109
- package/dist/bin/pls.d.ts +1 -1
- package/dist/bin/pls.js +994 -91
- package/dist/package.json +80 -0
- package/dist/src/ai.d.ts +1 -41
- package/dist/src/ai.js +9 -190
- package/dist/src/alias.d.ts +41 -0
- package/dist/src/alias.js +240 -0
- package/dist/src/builtin-detector.d.ts +14 -8
- package/dist/src/builtin-detector.js +36 -16
- package/dist/src/chat-history.d.ts +16 -11
- package/dist/src/chat-history.js +35 -4
- package/dist/src/components/Chat.js +5 -4
- package/dist/src/components/CodeColorizer.js +26 -20
- package/dist/src/components/CommandBox.js +3 -17
- package/dist/src/components/ConfirmationPrompt.d.ts +2 -1
- package/dist/src/components/ConfirmationPrompt.js +9 -4
- package/dist/src/components/Duration.js +2 -1
- package/dist/src/components/InlineRenderer.js +2 -1
- package/dist/src/components/MarkdownDisplay.js +2 -1
- package/dist/src/components/MultiStepCommandGenerator.d.ts +5 -1
- package/dist/src/components/MultiStepCommandGenerator.js +127 -14
- package/dist/src/components/TableRenderer.js +2 -1
- package/dist/src/config.d.ts +59 -9
- package/dist/src/config.js +147 -48
- package/dist/src/history.d.ts +19 -5
- package/dist/src/history.js +26 -11
- package/dist/src/mastra-agent.d.ts +0 -1
- package/dist/src/mastra-agent.js +3 -4
- package/dist/src/mastra-chat.d.ts +28 -0
- package/dist/src/mastra-chat.js +93 -0
- package/dist/src/multi-step.d.ts +23 -7
- package/dist/src/multi-step.js +29 -6
- package/dist/src/prompts.d.ts +11 -0
- package/dist/src/prompts.js +140 -0
- package/dist/src/remote-history.d.ts +63 -0
- package/dist/src/remote-history.js +315 -0
- package/dist/src/remote.d.ts +113 -0
- package/dist/src/remote.js +634 -0
- package/dist/src/shell-hook.d.ts +87 -12
- package/dist/src/shell-hook.js +315 -17
- package/dist/src/sysinfo.d.ts +9 -5
- package/dist/src/sysinfo.js +2 -2
- package/dist/src/ui/theme.d.ts +27 -24
- package/dist/src/ui/theme.js +71 -21
- package/dist/src/upgrade.d.ts +41 -0
- package/dist/src/upgrade.js +348 -0
- package/dist/src/utils/console.d.ts +11 -11
- package/dist/src/utils/console.js +26 -17
- package/package.json +11 -9
- package/src/alias.ts +301 -0
- package/src/builtin-detector.ts +126 -0
- package/src/chat-history.ts +140 -0
- package/src/components/Chat.tsx +6 -5
- package/src/components/CodeColorizer.tsx +27 -19
- package/src/components/CommandBox.tsx +3 -17
- package/src/components/ConfirmationPrompt.tsx +11 -3
- package/src/components/Duration.tsx +2 -1
- package/src/components/InlineRenderer.tsx +2 -1
- package/src/components/MarkdownDisplay.tsx +2 -1
- package/src/components/MultiStepCommandGenerator.tsx +167 -16
- package/src/components/TableRenderer.tsx +2 -1
- package/src/config.ts +394 -0
- package/src/history.ts +160 -0
- package/src/mastra-agent.ts +3 -4
- package/src/mastra-chat.ts +124 -0
- package/src/multi-step.ts +45 -8
- package/src/prompts.ts +154 -0
- package/src/remote-history.ts +390 -0
- package/src/remote.ts +800 -0
- package/src/shell-hook.ts +754 -0
- package/src/{sysinfo.js → sysinfo.ts} +28 -16
- package/src/ui/theme.ts +101 -24
- package/src/upgrade.ts +397 -0
- package/src/utils/{console.js → console.ts} +36 -27
- package/bin/pls.js +0 -681
- package/src/ai.js +0 -324
- package/src/builtin-detector.js +0 -98
- package/src/chat-history.js +0 -94
- package/src/components/ChatStatus.tsx +0 -53
- package/src/components/CommandGenerator.tsx +0 -184
- package/src/components/ConfigDisplay.tsx +0 -64
- package/src/components/ConfigWizard.tsx +0 -101
- package/src/components/HistoryDisplay.tsx +0 -69
- package/src/components/HookManager.tsx +0 -150
- package/src/config.js +0 -221
- package/src/history.js +0 -131
- package/src/shell-hook.js +0 -393
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
|
+
import { getCurrentTheme } from '../ui/theme.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 原生控制台输出工具函数
|
|
5
6
|
* 用于不需要 Ink 的场景,避免清屏和性能问题
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
// 获取当前主题颜色
|
|
10
|
+
function getColors() {
|
|
11
|
+
const theme = getCurrentTheme()
|
|
12
|
+
return {
|
|
13
|
+
primary: theme.primary,
|
|
14
|
+
secondary: theme.secondary,
|
|
15
|
+
accent: theme.accent,
|
|
16
|
+
success: theme.success,
|
|
17
|
+
error: theme.error,
|
|
18
|
+
warning: theme.warning,
|
|
19
|
+
info: theme.info,
|
|
20
|
+
muted: theme.text.muted,
|
|
21
|
+
}
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* 计算字符串的显示宽度(中文占2个宽度)
|
|
22
26
|
*/
|
|
23
|
-
export function getDisplayWidth(str) {
|
|
27
|
+
export function getDisplayWidth(str: string): number {
|
|
24
28
|
let width = 0
|
|
25
29
|
for (const char of str) {
|
|
26
30
|
if (char.match(/[\u4e00-\u9fff\u3400-\u4dbf\uff00-\uffef\u3000-\u303f]/)) {
|
|
@@ -35,10 +39,11 @@ export function getDisplayWidth(str) {
|
|
|
35
39
|
/**
|
|
36
40
|
* 绘制命令框(原生版本)
|
|
37
41
|
*/
|
|
38
|
-
export function drawCommandBox(command, title = '生成命令') {
|
|
42
|
+
export function drawCommandBox(command: string, title: string = '生成命令'): void {
|
|
43
|
+
const colors = getColors()
|
|
39
44
|
const lines = command.split('\n')
|
|
40
45
|
const titleWidth = getDisplayWidth(title)
|
|
41
|
-
const maxContentWidth = Math.max(...lines.map(l => getDisplayWidth(l)))
|
|
46
|
+
const maxContentWidth = Math.max(...lines.map((l) => getDisplayWidth(l)))
|
|
42
47
|
const boxWidth = Math.max(maxContentWidth + 4, titleWidth + 6, 20)
|
|
43
48
|
|
|
44
49
|
const topPadding = boxWidth - titleWidth - 5
|
|
@@ -50,10 +55,7 @@ export function drawCommandBox(command, title = '生成命令') {
|
|
|
50
55
|
const lineWidth = getDisplayWidth(line)
|
|
51
56
|
const padding = ' '.repeat(boxWidth - lineWidth - 4)
|
|
52
57
|
console.log(
|
|
53
|
-
chalk.hex(colors.warning)('│ ') +
|
|
54
|
-
chalk.hex(colors.primary)(line) +
|
|
55
|
-
padding +
|
|
56
|
-
chalk.hex(colors.warning)(' │')
|
|
58
|
+
chalk.hex(colors.warning)('│ ') + chalk.hex(colors.primary)(line) + padding + chalk.hex(colors.warning)(' │')
|
|
57
59
|
)
|
|
58
60
|
}
|
|
59
61
|
console.log(chalk.hex(colors.warning)(bottomBorder))
|
|
@@ -62,7 +64,7 @@ export function drawCommandBox(command, title = '生成命令') {
|
|
|
62
64
|
/**
|
|
63
65
|
* 格式化耗时
|
|
64
66
|
*/
|
|
65
|
-
export function formatDuration(ms) {
|
|
67
|
+
export function formatDuration(ms: number): string {
|
|
66
68
|
if (ms < 1000) {
|
|
67
69
|
return `${ms}ms`
|
|
68
70
|
}
|
|
@@ -72,9 +74,10 @@ export function formatDuration(ms) {
|
|
|
72
74
|
/**
|
|
73
75
|
* 输出分隔线
|
|
74
76
|
*/
|
|
75
|
-
export function printSeparator(text = '输出', length = 38) {
|
|
77
|
+
export function printSeparator(text: string = '输出', length: number = 38): void {
|
|
76
78
|
const textPart = text ? ` ${text} ` : ''
|
|
77
|
-
const
|
|
79
|
+
const textWidth = getDisplayWidth(textPart) // 使用显示宽度而不是字符数
|
|
80
|
+
const lineLength = Math.max(0, length - textWidth)
|
|
78
81
|
const leftDashes = '─'.repeat(Math.floor(lineLength / 2))
|
|
79
82
|
const rightDashes = '─'.repeat(Math.ceil(lineLength / 2))
|
|
80
83
|
console.log(chalk.gray(`${leftDashes}${textPart}${rightDashes}`))
|
|
@@ -83,48 +86,54 @@ export function printSeparator(text = '输出', length = 38) {
|
|
|
83
86
|
/**
|
|
84
87
|
* 输出成功消息
|
|
85
88
|
*/
|
|
86
|
-
export function success(message) {
|
|
89
|
+
export function success(message: string): void {
|
|
90
|
+
const colors = getColors()
|
|
87
91
|
console.log(chalk.hex(colors.success)('✓ ' + message))
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
/**
|
|
91
95
|
* 输出错误消息
|
|
92
96
|
*/
|
|
93
|
-
export function error(message) {
|
|
97
|
+
export function error(message: string): void {
|
|
98
|
+
const colors = getColors()
|
|
94
99
|
console.log(chalk.hex(colors.error)('✗ ' + message))
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
/**
|
|
98
103
|
* 输出警告消息
|
|
99
104
|
*/
|
|
100
|
-
export function warning(message) {
|
|
105
|
+
export function warning(message: string): void {
|
|
106
|
+
const colors = getColors()
|
|
101
107
|
console.log(chalk.hex(colors.warning)('⚠️ ' + message))
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
/**
|
|
105
111
|
* 输出信息消息
|
|
106
112
|
*/
|
|
107
|
-
export function info(message) {
|
|
113
|
+
export function info(message: string): void {
|
|
114
|
+
const colors = getColors()
|
|
108
115
|
console.log(chalk.hex(colors.info)(message))
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
/**
|
|
112
119
|
* 输出灰色文本
|
|
113
120
|
*/
|
|
114
|
-
export function muted(message) {
|
|
121
|
+
export function muted(message: string): void {
|
|
122
|
+
const colors = getColors()
|
|
115
123
|
console.log(chalk.hex(colors.muted)(message))
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
/**
|
|
119
127
|
* 输出标题
|
|
120
128
|
*/
|
|
121
|
-
export function title(message) {
|
|
129
|
+
export function title(message: string): void {
|
|
122
130
|
console.log(chalk.bold(message))
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
/**
|
|
126
134
|
* 输出主色文本
|
|
127
135
|
*/
|
|
128
|
-
export function primary(message) {
|
|
136
|
+
export function primary(message: string): void {
|
|
137
|
+
const colors = getColors()
|
|
129
138
|
console.log(chalk.hex(colors.primary)(message))
|
|
130
139
|
}
|