ccstatusline-zh 2.2.34 → 2.2.36
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 +31 -7
- package/dist/{ccstatusline-rdsx5ab1.js → ccstatusline-71188a0p.js} +23 -25
- package/dist/{ccstatusline-jp52tswn.js → ccstatusline-abxfvbek.js} +4173 -8161
- package/dist/ccstatusline-er9fa25f.js +6056 -0
- package/dist/ccstatusline-mkma8vq8.js +228 -0
- package/dist/ccstatusline.js +696 -19
- package/dist/dev-reload-z0a689mw.js +23 -0
- package/dist/hooks-vgtb1rd1.js +159 -0
- package/dist/{index-pzts8765.js → index-48pdkn43.js} +1488 -1278
- package/package.json +3 -3
- package/dist/hooks-0wev7tf6.js +0 -103
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SettingsSchema
|
|
3
|
+
} from "./ccstatusline-er9fa25f.js";
|
|
4
|
+
|
|
5
|
+
// src/utils/dev-reload.ts
|
|
6
|
+
import { spawn as spawnProcess } from "node:child_process";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as os from "node:os";
|
|
10
|
+
import * as path from "node:path";
|
|
11
|
+
var DEV_RELOAD_ENV = "CCSTATUSLINE_DEV_RELOAD";
|
|
12
|
+
var DEV_RELOAD_CHILD_ARG_PREFIX = "--ccstatusline-dev-reload-child=";
|
|
13
|
+
var DEV_RELOAD_EXIT_CODE2 = 75;
|
|
14
|
+
var DEV_RELOAD_STATE_DIR_PREFIX = "ccstatusline-dev-reload-";
|
|
15
|
+
var DEV_RELOAD_CAPABILITY_PATTERN = /^[a-f0-9]{64}$/;
|
|
16
|
+
function getDevReloadStateDir(args) {
|
|
17
|
+
const childArgs = args.filter((arg) => arg.startsWith(DEV_RELOAD_CHILD_ARG_PREFIX));
|
|
18
|
+
if (childArgs.length !== 1) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const capability = childArgs[0]?.slice(DEV_RELOAD_CHILD_ARG_PREFIX.length);
|
|
22
|
+
if (!capability || !DEV_RELOAD_CAPABILITY_PATTERN.test(capability)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const stateDir = path.join(os.tmpdir(), `${DEV_RELOAD_STATE_DIR_PREFIX}${capability}`);
|
|
26
|
+
try {
|
|
27
|
+
const stats = fs.lstatSync(stateDir);
|
|
28
|
+
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if (typeof process.getuid === "function" && stats.uid !== process.getuid()) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (process.platform !== "win32" && (stats.mode & 63) !== 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return stateDir;
|
|
41
|
+
}
|
|
42
|
+
function getDevReloadMode2(env, args = process.argv) {
|
|
43
|
+
if (env[DEV_RELOAD_ENV] !== "1") {
|
|
44
|
+
return "off";
|
|
45
|
+
}
|
|
46
|
+
return getDevReloadStateDir(args) ? "child" : "supervisor";
|
|
47
|
+
}
|
|
48
|
+
function getDevReloadStateFile2(env, args = process.argv) {
|
|
49
|
+
if (env[DEV_RELOAD_ENV] !== "1") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const stateDir = getDevReloadStateDir(args);
|
|
53
|
+
return stateDir ? path.join(stateDir, "snapshot.json") : null;
|
|
54
|
+
}
|
|
55
|
+
var RESTORABLE_SCREENS = [
|
|
56
|
+
"main",
|
|
57
|
+
"lines",
|
|
58
|
+
"items",
|
|
59
|
+
"colorLines",
|
|
60
|
+
"colors",
|
|
61
|
+
"terminalConfig",
|
|
62
|
+
"globalOverrides",
|
|
63
|
+
"powerline"
|
|
64
|
+
];
|
|
65
|
+
function toRestorableScreen(screen) {
|
|
66
|
+
return RESTORABLE_SCREENS.find((restorable) => restorable === screen) ?? "main";
|
|
67
|
+
}
|
|
68
|
+
function toCount(value) {
|
|
69
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : 0;
|
|
70
|
+
}
|
|
71
|
+
function writeDevReloadSnapshot2(stateFile, snapshot) {
|
|
72
|
+
fs.writeFileSync(stateFile, JSON.stringify(snapshot), "utf-8");
|
|
73
|
+
}
|
|
74
|
+
function discardDevReloadSnapshot2(stateFile) {
|
|
75
|
+
fs.rmSync(stateFile, { force: true });
|
|
76
|
+
}
|
|
77
|
+
function readDevReloadSnapshot2(stateFile) {
|
|
78
|
+
let raw;
|
|
79
|
+
try {
|
|
80
|
+
raw = JSON.parse(fs.readFileSync(stateFile, "utf-8"));
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (typeof raw !== "object" || raw === null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const candidate = raw;
|
|
88
|
+
const settings = SettingsSchema.safeParse(candidate.settings);
|
|
89
|
+
const originalSettings = SettingsSchema.safeParse(candidate.originalSettings);
|
|
90
|
+
if (!settings.success || !originalSettings.success) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const menuSelections = typeof candidate.menuSelections === "object" && candidate.menuSelections !== null ? Object.fromEntries(Object.entries(candidate.menuSelections).map(([key, value]) => [key, toCount(value)])) : {};
|
|
94
|
+
return {
|
|
95
|
+
settings: settings.data,
|
|
96
|
+
originalSettings: originalSettings.data,
|
|
97
|
+
screen: toRestorableScreen(candidate.screen),
|
|
98
|
+
selectedLine: toCount(candidate.selectedLine),
|
|
99
|
+
menuSelections,
|
|
100
|
+
itemsCursor: toCount(candidate.itemsCursor)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function createDevReloadState() {
|
|
104
|
+
for (let attempt = 0;attempt < 10; attempt += 1) {
|
|
105
|
+
const capability = randomBytes(32).toString("hex");
|
|
106
|
+
const stateDir = path.join(os.tmpdir(), `${DEV_RELOAD_STATE_DIR_PREFIX}${capability}`);
|
|
107
|
+
try {
|
|
108
|
+
fs.mkdirSync(stateDir, { mode: 448 });
|
|
109
|
+
return { stateDir, capability };
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error.code !== "EEXIST") {
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw new Error("Unable to create a unique dev reload state directory");
|
|
117
|
+
}
|
|
118
|
+
function removeDevReloadStateDir(stateDir) {
|
|
119
|
+
fs.rmSync(stateDir, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
var reloadRequested = false;
|
|
122
|
+
function requestDevReload2() {
|
|
123
|
+
reloadRequested = true;
|
|
124
|
+
}
|
|
125
|
+
function isDevReloadRequested2() {
|
|
126
|
+
return reloadRequested;
|
|
127
|
+
}
|
|
128
|
+
async function runDevReloadSupervisor(deps) {
|
|
129
|
+
for (;; ) {
|
|
130
|
+
const exitCode = await deps.launch();
|
|
131
|
+
if (exitCode === DEV_RELOAD_EXIT_CODE2) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (exitCode === 0 || !await deps.promptRetry(exitCode)) {
|
|
135
|
+
deps.cleanup();
|
|
136
|
+
return exitCode;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function promptRetryOnTerminal(exitCode, terminal = process) {
|
|
141
|
+
terminal.stdout.write(`
|
|
142
|
+
重载失败(退出码 ${exitCode})。修复代码后按 Enter 重试,或按 q 退出。
|
|
143
|
+
`);
|
|
144
|
+
return new Promise((resolve) => {
|
|
145
|
+
const stdin = terminal.stdin;
|
|
146
|
+
const onData = (data) => {
|
|
147
|
+
const key = data.toString();
|
|
148
|
+
const retry = key === "\r" || key === `
|
|
149
|
+
`;
|
|
150
|
+
const quit = key === "q" || key === "Q" || key === "\x03";
|
|
151
|
+
if (!retry && !quit) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
stdin.off("data", onData);
|
|
155
|
+
stdin.setRawMode(false);
|
|
156
|
+
stdin.pause();
|
|
157
|
+
resolve(retry);
|
|
158
|
+
};
|
|
159
|
+
stdin.setRawMode(true);
|
|
160
|
+
stdin.resume();
|
|
161
|
+
stdin.on("data", onData);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function spawnInTerminal(command, args, env) {
|
|
165
|
+
const child = spawnProcess(command, args, { stdio: "inherit", env });
|
|
166
|
+
return {
|
|
167
|
+
exited: new Promise((resolve) => {
|
|
168
|
+
child.once("exit", (code) => {
|
|
169
|
+
resolve(code ?? 1);
|
|
170
|
+
});
|
|
171
|
+
child.once("error", () => {
|
|
172
|
+
resolve(1);
|
|
173
|
+
});
|
|
174
|
+
}),
|
|
175
|
+
kill: (signal) => {
|
|
176
|
+
child.kill(signal);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
var STOP_SIGNALS = ["SIGTERM", "SIGINT", "SIGHUP"];
|
|
181
|
+
function signalExitCode(signal) {
|
|
182
|
+
return 128 + os.constants.signals[signal];
|
|
183
|
+
}
|
|
184
|
+
async function superviseDevReload2(launchArgs, spawn = spawnInTerminal, host = process) {
|
|
185
|
+
const { stateDir, capability } = createDevReloadState();
|
|
186
|
+
const script = process.argv[1];
|
|
187
|
+
const childArg = `${DEV_RELOAD_CHILD_ARG_PREFIX}${capability}`;
|
|
188
|
+
const command = [...process.execArgv, ...script ? [script] : [], childArg, ...launchArgs];
|
|
189
|
+
const env = {
|
|
190
|
+
...process.env,
|
|
191
|
+
[DEV_RELOAD_ENV]: "1"
|
|
192
|
+
};
|
|
193
|
+
delete env.CCSTATUSLINE_DEV_RELOAD_STATE;
|
|
194
|
+
let child = null;
|
|
195
|
+
let stopSignal = null;
|
|
196
|
+
const stop = (signal) => {
|
|
197
|
+
stopSignal = signal;
|
|
198
|
+
if (child) {
|
|
199
|
+
child.kill(signal);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
removeDevReloadStateDir(stateDir);
|
|
203
|
+
host.exit(signalExitCode(signal));
|
|
204
|
+
};
|
|
205
|
+
for (const signal of STOP_SIGNALS) {
|
|
206
|
+
host.on(signal, stop);
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
return await runDevReloadSupervisor({
|
|
210
|
+
launch: async () => {
|
|
211
|
+
child = spawn(process.execPath, command, env);
|
|
212
|
+
const exitCode = await child.exited;
|
|
213
|
+
child = null;
|
|
214
|
+
return stopSignal ? signalExitCode(stopSignal) : exitCode;
|
|
215
|
+
},
|
|
216
|
+
promptRetry: (exitCode) => stopSignal ? Promise.resolve(false) : promptRetryOnTerminal(exitCode, host),
|
|
217
|
+
cleanup: () => {
|
|
218
|
+
removeDevReloadStateDir(stateDir);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
} finally {
|
|
222
|
+
for (const signal of STOP_SIGNALS) {
|
|
223
|
+
host.off(signal, stop);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { DEV_RELOAD_EXIT_CODE2, getDevReloadMode2, getDevReloadStateFile2, writeDevReloadSnapshot2, discardDevReloadSnapshot2, readDevReloadSnapshot2, requestDevReload2, isDevReloadRequested2, superviseDevReload2 };
|