@narumitw/pi-starship 0.60.0 → 0.62.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 +63 -6
- package/dist/chunks/chunk-43VIENBN.ts +1586 -0
- package/dist/chunks/chunk-43VIENBN.ts.map +7 -0
- package/dist/chunks/chunk-HPZTMIZS.ts +646 -0
- package/dist/chunks/chunk-HPZTMIZS.ts.map +7 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
- package/dist/chunks/chunk-KP33I6BR.ts +579 -0
- package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
- package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-PWTSHSP3.ts} +853 -1001
- package/dist/chunks/chunk-PWTSHSP3.ts.map +7 -0
- package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
- package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
- package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
- package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
- package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
- package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
- package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
- package/dist/chunks/command-configuration-menu-S2LXCOJG.ts +147 -0
- package/dist/chunks/command-configuration-menu-S2LXCOJG.ts.map +7 -0
- package/dist/chunks/command-settings-chat-O34BEU4X.ts +1041 -0
- package/dist/chunks/command-settings-chat-O34BEU4X.ts.map +7 -0
- package/dist/chunks/commands-ZYIJVIEJ.ts +1022 -0
- package/dist/chunks/commands-ZYIJVIEJ.ts.map +7 -0
- package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
- package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
- package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
- package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
- package/dist/chunks/directory-OX6BWJZA.ts +31 -0
- package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
- package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
- package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
- package/dist/chunks/languages-CBQNNYXM.ts +262 -0
- package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
- package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
- package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
- package/dist/chunks/system-574MHB4R.ts +165 -0
- package/dist/chunks/system-574MHB4R.ts.map +7 -0
- package/dist/index.ts +558 -150
- package/dist/index.ts.map +4 -4
- package/package.json +5 -1
- package/skills/configure-pi-starship/SKILL.md +29 -1
- package/skills/configure-pi-starship/references/configuration.md +109 -24
- package/skills/configure-pi-starship/references/module-catalog.md +278 -25
- package/skills/configure-pi-starship/references/modules.md +213 -36
- package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
- package/skills/configure-pi-starship/scripts/config-path.mjs +63 -3
- package/src/command-configuration-menu.ts +155 -0
- package/src/command-configuration.ts +9 -84
- package/src/command-preview.ts +3 -3
- package/src/command-settings-chat.ts +210 -0
- package/src/commands.ts +54 -98
- package/src/config/module-options.ts +112 -0
- package/src/config.ts +17 -53
- package/src/effective-config.ts +5 -4
- package/src/format/bounded-regex.ts +66 -0
- package/src/format/version.ts +24 -0
- package/src/modules/catalog.ts +10 -0
- package/src/modules/cloud.ts +1 -0
- package/src/modules/deployment.ts +8 -0
- package/src/modules/development.ts +20 -2
- package/src/modules/directory.ts +171 -51
- package/src/modules/execution.ts +2 -0
- package/src/modules/git/branch.ts +19 -4
- package/src/modules/git/commit.ts +9 -2
- package/src/modules/git/metrics.ts +9 -4
- package/src/modules/git/runtime.ts +122 -33
- package/src/modules/git/state.ts +23 -2
- package/src/modules/git/status-templates.ts +58 -0
- package/src/modules/git/status.ts +96 -30
- package/src/modules/jujutsu.ts +225 -0
- package/src/modules/languages.ts +26 -2
- package/src/modules/package.ts +1 -0
- package/src/modules/render.ts +42 -16
- package/src/modules/system.ts +54 -0
- package/src/modules/time-format.ts +188 -0
- package/src/modules/time.ts +11 -5
- package/src/modules/types.ts +42 -4
- package/src/pi-starship.ts +56 -12
- package/src/profile-store.ts +5 -0
- package/src/runtime/cloud.ts +3 -0
- package/src/runtime/command.ts +1 -1
- package/src/runtime/deployment.ts +120 -4
- package/src/runtime/development.ts +86 -13
- package/src/runtime/directory.ts +33 -0
- package/src/runtime/execution.ts +12 -2
- package/src/runtime/helpers.ts +57 -8
- package/src/runtime/jujutsu.ts +225 -0
- package/src/runtime/languages.ts +106 -19
- package/src/runtime/package.ts +3 -0
- package/src/runtime/system.ts +202 -0
- package/src/runtime/types.ts +3 -0
- package/src/runtime/version-requirements.ts +30 -0
- package/src/runtime/workspace.ts +12 -1
- package/src/settings-agent.ts +80 -0
- package/src/settings-chat-transcript.ts +140 -0
- package/src/settings-chat-ui.ts +426 -0
- package/src/settings-draft.ts +260 -0
- package/src/settings-snapshots.ts +41 -0
- package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
- package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
- package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
- package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
- package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
- package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
- package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
- package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
- package/dist/chunks/languages-JO6R2PHL.ts +0 -168
- package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
- package/dist/chunks/package-H24VJEX3.ts.map +0 -7
- package/src/command-inspector.ts +0 -41
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2
|
+
import { type FormatNode, formatVariables, parseFormat, renderFormat, styleVariables } from "../../format/formatter.js";
|
|
3
|
+
import { type ColorPalette, isFillChunk, type StyledChunk } from "../../format/style.js";
|
|
4
|
+
|
|
5
|
+
const MAX_TEMPLATE_LENGTH = 4_096;
|
|
6
|
+
const MAX_TEMPLATE_DEPTH = 16;
|
|
7
|
+
|
|
8
|
+
/** Status templates use the normal formatter, but cannot resolve other module data. */
|
|
9
|
+
export function renderStatusTemplate(
|
|
10
|
+
template: string,
|
|
11
|
+
variables: Readonly<Record<string, string>>,
|
|
12
|
+
palette: ColorPalette,
|
|
13
|
+
): StyledChunk[] {
|
|
14
|
+
const nodes = parseStatusTemplate(template, Object.keys(variables));
|
|
15
|
+
return nodes
|
|
16
|
+
? renderFormat(nodes, { variables, palette }).filter(
|
|
17
|
+
(chunk): chunk is StyledChunk => !isFillChunk(chunk) && chunk.text.length > 0,
|
|
18
|
+
)
|
|
19
|
+
: [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function validStatusTemplate(template: string, variables: readonly string[]): boolean {
|
|
23
|
+
return parseStatusTemplate(template, variables) !== undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseStatusTemplate(template: string, variables: readonly string[]): FormatNode[] | undefined {
|
|
27
|
+
if (template.length > MAX_TEMPLATE_LENGTH) return undefined;
|
|
28
|
+
const safe = sanitizeTerminalText(template);
|
|
29
|
+
let depth = 0;
|
|
30
|
+
for (let index = 0; index < safe.length; index += 1) {
|
|
31
|
+
const character = safe[index];
|
|
32
|
+
if (character === "\\") {
|
|
33
|
+
index += 1;
|
|
34
|
+
} else if (character === "[" || character === "(") {
|
|
35
|
+
if (++depth > MAX_TEMPLATE_DEPTH) return undefined;
|
|
36
|
+
} else if (character === "]" || character === ")") {
|
|
37
|
+
depth -= 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const nodes = parseFormat(safe);
|
|
42
|
+
if ([...formatVariables(nodes)].some((variable) => !variables.includes(variable))) return undefined;
|
|
43
|
+
if (styleVariables(nodes).size > 0) return undefined;
|
|
44
|
+
return nodes;
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function joinStatusTemplates(values: readonly (readonly StyledChunk[])[]): StyledChunk[] {
|
|
51
|
+
const result: StyledChunk[] = [];
|
|
52
|
+
for (const value of values) {
|
|
53
|
+
if (value.length === 0) continue;
|
|
54
|
+
if (result.length > 0) result.push({ text: " " });
|
|
55
|
+
result.push(...value);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
@@ -1,5 +1,33 @@
|
|
|
1
|
+
import type { ColorPalette, StyledChunk } from "../../format/style.js";
|
|
1
2
|
import { formatCount } from "../helpers.js";
|
|
2
|
-
import { defineModule } from "../types.js";
|
|
3
|
+
import { defineModule, type ModuleOptionValue } from "../types.js";
|
|
4
|
+
import { joinStatusTemplates, renderStatusTemplate } from "./status-templates.js";
|
|
5
|
+
|
|
6
|
+
const COUNT_VARIABLES = ["count"] as const;
|
|
7
|
+
const DEFAULT_TEMPLATES = {
|
|
8
|
+
ahead: "⇡$count",
|
|
9
|
+
behind: "⇣$count",
|
|
10
|
+
up_to_date: "",
|
|
11
|
+
diverged: "⇕⇡$ahead_count⇣$behind_count",
|
|
12
|
+
conflicted: "=$count",
|
|
13
|
+
stashed: "\\$$count",
|
|
14
|
+
deleted: "✘$count",
|
|
15
|
+
renamed: "»$count",
|
|
16
|
+
modified: "!$count",
|
|
17
|
+
typechanged: "T$count",
|
|
18
|
+
staged: "+$count",
|
|
19
|
+
untracked: "?$count",
|
|
20
|
+
worktree_added: "A$count",
|
|
21
|
+
worktree_deleted: "D$count",
|
|
22
|
+
worktree_modified: "M$count",
|
|
23
|
+
worktree_typechanged: "T$count",
|
|
24
|
+
index_added: "A$count",
|
|
25
|
+
index_deleted: "D$count",
|
|
26
|
+
index_modified: "M$count",
|
|
27
|
+
index_typechanged: "T$count",
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
type StatusTemplate = keyof typeof DEFAULT_TEMPLATES;
|
|
3
31
|
|
|
4
32
|
export const gitStatusModule = defineModule({
|
|
5
33
|
name: "git_status",
|
|
@@ -34,37 +62,59 @@ export const gitStatusModule = defineModule({
|
|
|
34
62
|
style: "red bold",
|
|
35
63
|
disabled: false,
|
|
36
64
|
},
|
|
37
|
-
|
|
65
|
+
options: {
|
|
66
|
+
...Object.fromEntries(
|
|
67
|
+
Object.entries(DEFAULT_TEMPLATES).map(([name, template]) => [
|
|
68
|
+
name,
|
|
69
|
+
{
|
|
70
|
+
kind: "string" as const,
|
|
71
|
+
default: template,
|
|
72
|
+
templateVariables:
|
|
73
|
+
name === "diverged" ? ["ahead_count", "behind_count"] : name === "up_to_date" ? [] : COUNT_VARIABLES,
|
|
74
|
+
},
|
|
75
|
+
]),
|
|
76
|
+
),
|
|
77
|
+
ignore_submodules: { kind: "boolean", default: false },
|
|
78
|
+
},
|
|
79
|
+
values: ({ runtime, options, palette, requestedVariables }) => {
|
|
38
80
|
if (!runtime.gitBranch || !runtime.gitStatus) return undefined;
|
|
39
81
|
const status = runtime.gitStatus;
|
|
40
|
-
const
|
|
41
|
-
const
|
|
82
|
+
const hasAhead = Number.isSafeInteger(status.ahead) && status.ahead > 0;
|
|
83
|
+
const hasBehind = Number.isSafeInteger(status.behind) && status.behind > 0;
|
|
84
|
+
const template = (name: StatusTemplate, variables: Readonly<Record<string, string>>) =>
|
|
85
|
+
renderStatusTemplate(templateOption(options, name), variables, palette);
|
|
86
|
+
const count = (name: StatusTemplate, value: number) => countTemplate(options, name, value, palette);
|
|
87
|
+
const ahead = count("ahead", status.ahead);
|
|
88
|
+
const behind = count("behind", status.behind);
|
|
42
89
|
const diverged =
|
|
43
|
-
|
|
90
|
+
hasAhead && hasBehind
|
|
91
|
+
? template("diverged", { ahead_count: formatCount(status.ahead), behind_count: formatCount(status.behind) })
|
|
92
|
+
: [];
|
|
93
|
+
const upToDate = status.upToDate && status.ahead === 0 && status.behind === 0 ? template("up_to_date", {}) : [];
|
|
44
94
|
const values = {
|
|
45
95
|
ahead,
|
|
46
96
|
behind,
|
|
47
|
-
up_to_date:
|
|
97
|
+
up_to_date: upToDate,
|
|
48
98
|
diverged,
|
|
49
|
-
ahead_behind: diverged
|
|
50
|
-
conflicted: count("
|
|
51
|
-
stashed: count("
|
|
52
|
-
deleted: count("
|
|
53
|
-
renamed: count("
|
|
54
|
-
modified: count("
|
|
55
|
-
typechanged: count("
|
|
56
|
-
staged: count("
|
|
57
|
-
untracked: count("
|
|
58
|
-
worktree_added: count("
|
|
59
|
-
worktree_deleted: count("
|
|
60
|
-
worktree_modified: count("
|
|
61
|
-
worktree_typechanged: count("
|
|
62
|
-
index_added: count("
|
|
63
|
-
index_deleted: count("
|
|
64
|
-
index_modified: count("
|
|
65
|
-
index_typechanged: count("
|
|
99
|
+
ahead_behind: hasAhead && hasBehind ? diverged : hasAhead ? ahead : hasBehind ? behind : upToDate,
|
|
100
|
+
conflicted: count("conflicted", status.conflicted),
|
|
101
|
+
stashed: count("stashed", status.stashed),
|
|
102
|
+
deleted: count("deleted", status.deleted),
|
|
103
|
+
renamed: count("renamed", status.renamed),
|
|
104
|
+
modified: count("modified", status.modified),
|
|
105
|
+
typechanged: count("typechanged", status.typechanged),
|
|
106
|
+
staged: count("staged", status.staged),
|
|
107
|
+
untracked: count("untracked", status.untracked),
|
|
108
|
+
worktree_added: count("worktree_added", status.worktreeAdded),
|
|
109
|
+
worktree_deleted: count("worktree_deleted", status.worktreeDeleted),
|
|
110
|
+
worktree_modified: count("worktree_modified", status.worktreeModified),
|
|
111
|
+
worktree_typechanged: count("worktree_typechanged", status.worktreeTypechanged),
|
|
112
|
+
index_added: count("index_added", status.indexAdded),
|
|
113
|
+
index_deleted: count("index_deleted", status.indexDeleted),
|
|
114
|
+
index_modified: count("index_modified", status.indexModified),
|
|
115
|
+
index_typechanged: count("index_typechanged", status.indexTypechanged),
|
|
66
116
|
};
|
|
67
|
-
const allStatus = [
|
|
117
|
+
const allStatus = joinStatusTemplates([
|
|
68
118
|
values.conflicted,
|
|
69
119
|
values.stashed,
|
|
70
120
|
values.deleted,
|
|
@@ -73,13 +123,29 @@ export const gitStatusModule = defineModule({
|
|
|
73
123
|
values.typechanged,
|
|
74
124
|
values.staged,
|
|
75
125
|
values.untracked,
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
126
|
+
]);
|
|
127
|
+
const available = { ...values, all_status: allStatus };
|
|
128
|
+
const requested = [...(requestedVariables ?? [])].filter((name) => Object.hasOwn(available, name));
|
|
129
|
+
const visible =
|
|
130
|
+
requested.length > 0
|
|
131
|
+
? requested.map((name) => available[name as keyof typeof available])
|
|
132
|
+
: [allStatus, values.ahead_behind];
|
|
133
|
+
return visible.some((value) => value.length > 0) ? available : undefined;
|
|
80
134
|
},
|
|
81
135
|
});
|
|
82
136
|
|
|
83
|
-
function
|
|
84
|
-
|
|
137
|
+
function templateOption(options: Readonly<Record<string, ModuleOptionValue>>, name: StatusTemplate): string {
|
|
138
|
+
const option = options[name];
|
|
139
|
+
return typeof option === "string" ? option : DEFAULT_TEMPLATES[name];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function countTemplate(
|
|
143
|
+
options: Readonly<Record<string, ModuleOptionValue>>,
|
|
144
|
+
name: StatusTemplate,
|
|
145
|
+
value: number,
|
|
146
|
+
palette: ColorPalette,
|
|
147
|
+
): StyledChunk[] {
|
|
148
|
+
return Number.isSafeInteger(value) && value > 0
|
|
149
|
+
? renderStatusTemplate(templateOption(options, name), { count: formatCount(value) }, palette)
|
|
150
|
+
: [];
|
|
85
151
|
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2
|
+
import type { FormatValue } from "../format/formatter.js";
|
|
3
|
+
import { type LayoutChunk, parseStyle } from "../format/style.js";
|
|
4
|
+
import { renderStatusTemplate } from "./git/status-templates.js";
|
|
5
|
+
import { truncateLeadingGraphemes } from "./truncation.js";
|
|
6
|
+
import { defineModule, type ModuleValueContext } from "./types.js";
|
|
7
|
+
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
8
|
+
|
|
9
|
+
export const jjBookmarkModule = defineModule({
|
|
10
|
+
name: "jj_bookmark",
|
|
11
|
+
variables: ["symbol", "bookmark", "remote", "diverged", "overflow_count"],
|
|
12
|
+
defaults: {
|
|
13
|
+
format: "on [$symbol$bookmark(@$remote)$diverged( \\(+$overflow_count others\\))]($style) ",
|
|
14
|
+
symbol: " ",
|
|
15
|
+
style: "bold purple",
|
|
16
|
+
disabled: true,
|
|
17
|
+
},
|
|
18
|
+
options: {
|
|
19
|
+
truncation_length: { kind: "integer", default: 65_535, minimum: 0, maximum: 65_535 },
|
|
20
|
+
truncation_symbol: { kind: "string", default: "…", allowEmpty: true },
|
|
21
|
+
diverged_symbol: { kind: "string", default: "*", allowEmpty: true },
|
|
22
|
+
ignore_names: { kind: "string-array", default: [] },
|
|
23
|
+
ignore_remotes: { kind: "string-array", default: [] },
|
|
24
|
+
},
|
|
25
|
+
values(context) {
|
|
26
|
+
const values = workspaceModuleValues("jj_bookmark", context);
|
|
27
|
+
if (!values?.bookmarks) return undefined;
|
|
28
|
+
let raw: unknown;
|
|
29
|
+
try {
|
|
30
|
+
raw = JSON.parse(values.bookmarks);
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (!Array.isArray(raw)) return undefined;
|
|
35
|
+
const parsed = raw.map(parseBookmark);
|
|
36
|
+
if (parsed.some((bookmark) => bookmark === undefined)) return undefined;
|
|
37
|
+
const ignoredNames = stringList(context, "ignore_names");
|
|
38
|
+
const ignoredRemotes = stringList(context, "ignore_remotes");
|
|
39
|
+
const bookmarks = parsed
|
|
40
|
+
.filter((bookmark): bookmark is NonNullable<typeof bookmark> => bookmark !== undefined)
|
|
41
|
+
.filter(
|
|
42
|
+
({ name, remote }) =>
|
|
43
|
+
!ignoredNames.includes(name) && (remote === undefined || !ignoredRemotes.includes(remote)),
|
|
44
|
+
);
|
|
45
|
+
const bookmark = bookmarks[0];
|
|
46
|
+
if (!bookmark) return undefined;
|
|
47
|
+
const length = integerOption(context, "truncation_length", 65_535);
|
|
48
|
+
const symbol = stringOption(context, "truncation_symbol", "…");
|
|
49
|
+
const truncate = (value: string) => truncateLeadingGraphemes(value, length, symbol);
|
|
50
|
+
return {
|
|
51
|
+
bookmark: truncate(bookmark.name),
|
|
52
|
+
remote: bookmark.remote === undefined ? "" : truncate(bookmark.remote),
|
|
53
|
+
diverged: bookmark.diverged ? stringOption(context, "diverged_symbol", "*") : "",
|
|
54
|
+
overflow_count: bookmarks.length > 1 ? String(bookmarks.length - 1) : "",
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const jjChangeModule = defineModule({
|
|
60
|
+
name: "jj_change",
|
|
61
|
+
variables: ["change", "commit", "change_prefix", "change_suffix", "change_offset", "commit_prefix", "commit_suffix"],
|
|
62
|
+
defaults: { format: "$change ", symbol: "", style: "none", disabled: true },
|
|
63
|
+
styleDefaults: { prefix_style: "green bold", suffix_style: "dimmed", change_offset_style: "bold" },
|
|
64
|
+
styleVariables: ["prefix_style", "suffix_style", "change_offset_style"],
|
|
65
|
+
resolveStyleVariables: ({ styles }) => styles,
|
|
66
|
+
options: {
|
|
67
|
+
change_hash_length: { kind: "integer", default: 7, minimum: 0, maximum: 255 },
|
|
68
|
+
commit_hash_length: { kind: "integer", default: 7, minimum: 0, maximum: 255 },
|
|
69
|
+
},
|
|
70
|
+
values(context) {
|
|
71
|
+
const values = workspaceModuleValues("jj_change", context);
|
|
72
|
+
if (!values) return undefined;
|
|
73
|
+
const change = idParts(
|
|
74
|
+
values.change_id ?? "",
|
|
75
|
+
Number(values.change_prefix_len),
|
|
76
|
+
integerOption(context, "change_hash_length", 7),
|
|
77
|
+
);
|
|
78
|
+
const commit = idParts(
|
|
79
|
+
values.commit_id ?? "",
|
|
80
|
+
Number(values.commit_prefix_len),
|
|
81
|
+
integerOption(context, "commit_hash_length", 7),
|
|
82
|
+
);
|
|
83
|
+
const styled = (text: string, role: string): LayoutChunk => ({
|
|
84
|
+
text,
|
|
85
|
+
style: parseStyle(context.styles?.[role] ?? "", context.palette),
|
|
86
|
+
});
|
|
87
|
+
const changeChunks = [styled(change.prefix, "prefix_style"), styled(change.suffix, "suffix_style")];
|
|
88
|
+
if (values.change_offset !== undefined)
|
|
89
|
+
changeChunks.push(styled(`/${values.change_offset}`, "change_offset_style"));
|
|
90
|
+
return {
|
|
91
|
+
change: changeChunks,
|
|
92
|
+
commit: [styled(commit.prefix, "prefix_style"), styled(commit.suffix, "suffix_style")],
|
|
93
|
+
change_prefix: change.prefix,
|
|
94
|
+
change_suffix: change.suffix,
|
|
95
|
+
change_offset: values.change_offset ?? "",
|
|
96
|
+
commit_prefix: commit.prefix,
|
|
97
|
+
commit_suffix: commit.suffix,
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export const jjMetricsModule = defineModule({
|
|
103
|
+
name: "jj_metrics",
|
|
104
|
+
variables: ["added", "deleted"],
|
|
105
|
+
defaults: {
|
|
106
|
+
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
|
107
|
+
symbol: "",
|
|
108
|
+
style: "none",
|
|
109
|
+
disabled: true,
|
|
110
|
+
},
|
|
111
|
+
styleDefaults: { added_style: "bold green", deleted_style: "bold red" },
|
|
112
|
+
styleVariables: ["added_style", "deleted_style"],
|
|
113
|
+
resolveStyleVariables: ({ styles }) => styles,
|
|
114
|
+
options: { only_nonzero_diffs: { kind: "boolean", default: true } },
|
|
115
|
+
values(context) {
|
|
116
|
+
const values = workspaceModuleValues("jj_metrics", context);
|
|
117
|
+
if (!values) return undefined;
|
|
118
|
+
if (context.options.only_nonzero_diffs === false) return values;
|
|
119
|
+
return { added: values.added === "0" ? "" : values.added, deleted: values.deleted === "0" ? "" : values.deleted };
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const statusTemplates = {
|
|
124
|
+
conflicted: "!",
|
|
125
|
+
description_empty: "◌",
|
|
126
|
+
description_present: "",
|
|
127
|
+
hidden: "",
|
|
128
|
+
immutable: "◆",
|
|
129
|
+
added: "+",
|
|
130
|
+
copied: "=",
|
|
131
|
+
deleted: "✘",
|
|
132
|
+
modified: "~",
|
|
133
|
+
renamed: "»",
|
|
134
|
+
} as const;
|
|
135
|
+
|
|
136
|
+
export const jjStatusModule = defineModule({
|
|
137
|
+
name: "jj_status",
|
|
138
|
+
variables: [
|
|
139
|
+
"all",
|
|
140
|
+
"conflicted",
|
|
141
|
+
"description",
|
|
142
|
+
"hidden",
|
|
143
|
+
"immutable",
|
|
144
|
+
"added",
|
|
145
|
+
"copied",
|
|
146
|
+
"deleted",
|
|
147
|
+
"modified",
|
|
148
|
+
"renamed",
|
|
149
|
+
],
|
|
150
|
+
defaults: { format: "([\\[$all\\]]($style) )", symbol: "", style: "bold red", disabled: true },
|
|
151
|
+
options: Object.fromEntries(
|
|
152
|
+
Object.entries(statusTemplates).map(([key, value]) => [
|
|
153
|
+
key,
|
|
154
|
+
{
|
|
155
|
+
kind: "string" as const,
|
|
156
|
+
default: value,
|
|
157
|
+
allowEmpty: true,
|
|
158
|
+
templateVariables: ["added", "copied", "deleted", "modified", "renamed"].includes(key) ? ["count"] : [],
|
|
159
|
+
},
|
|
160
|
+
]),
|
|
161
|
+
),
|
|
162
|
+
values(context) {
|
|
163
|
+
const snapshot = workspaceModuleValues("jj_status", context);
|
|
164
|
+
if (!snapshot) return undefined;
|
|
165
|
+
const values: Record<string, FormatValue> = {};
|
|
166
|
+
const symbol = (name: keyof typeof statusTemplates, active = true, count?: string) =>
|
|
167
|
+
active ? statusValue(stringOption(context, name, statusTemplates[name]), count, context) : [];
|
|
168
|
+
values.conflicted = symbol("conflicted", snapshot.conflicted === "true");
|
|
169
|
+
values.description = symbol(snapshot.has_description === "true" ? "description_present" : "description_empty");
|
|
170
|
+
values.hidden = symbol("hidden", snapshot.hidden === "true");
|
|
171
|
+
values.immutable = symbol("immutable", snapshot.immutable === "true");
|
|
172
|
+
for (const name of ["added", "copied", "deleted", "modified", "renamed"] as const) {
|
|
173
|
+
values[name] = symbol(name, Number(snapshot[name]) > 0, snapshot[name]);
|
|
174
|
+
}
|
|
175
|
+
values.all = Object.values(values).flatMap((value) => (Array.isArray(value) ? value : []));
|
|
176
|
+
return values;
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
export const jujutsuModules = [jjBookmarkModule, jjChangeModule, jjMetricsModule, jjStatusModule] as const;
|
|
181
|
+
|
|
182
|
+
function parseBookmark(raw: unknown): { name: string; remote?: string; diverged: boolean } | undefined {
|
|
183
|
+
if (
|
|
184
|
+
!raw ||
|
|
185
|
+
typeof raw !== "object" ||
|
|
186
|
+
!("name" in raw) ||
|
|
187
|
+
!("remote" in raw) ||
|
|
188
|
+
!("diverged" in raw) ||
|
|
189
|
+
typeof raw.name !== "string" ||
|
|
190
|
+
typeof raw.remote !== "string" ||
|
|
191
|
+
typeof raw.diverged !== "boolean"
|
|
192
|
+
)
|
|
193
|
+
return undefined;
|
|
194
|
+
// Transport raw fields, not JJ revset display labels: @, quotes and trailing *
|
|
195
|
+
// can be literal name characters. Sanitize before filtering and truncation.
|
|
196
|
+
const remote = sanitizeTerminalText(raw.remote);
|
|
197
|
+
return { name: sanitizeTerminalText(raw.name), remote: remote || undefined, diverged: raw.diverged };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function idParts(id: string, prefixLength: number, hashLength: number) {
|
|
201
|
+
const text = sanitizeTerminalText(id);
|
|
202
|
+
const start = Math.min(text.length, Number.isFinite(prefixLength) ? Math.max(0, prefixLength) : 0);
|
|
203
|
+
return { prefix: text.slice(0, start), suffix: text.slice(start, Math.max(start, hashLength)) };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function stringOption(context: ModuleValueContext, key: string, fallback: string): string {
|
|
207
|
+
const value = context.options[key];
|
|
208
|
+
return typeof value === "string" ? sanitizeTerminalText(value) : fallback;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function integerOption(context: ModuleValueContext, key: string, fallback: number): number {
|
|
212
|
+
const value = context.options[key];
|
|
213
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : fallback;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function stringList(context: ModuleValueContext, key: string): readonly string[] {
|
|
217
|
+
const value = context.options[key];
|
|
218
|
+
return Array.isArray(value)
|
|
219
|
+
? value.filter((item): item is string => typeof item === "string").map(sanitizeTerminalText)
|
|
220
|
+
: [];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function statusValue(template: string, count: string | undefined, context: ModuleValueContext): readonly LayoutChunk[] {
|
|
224
|
+
return renderStatusTemplate(template, count === undefined ? {} : { count }, context.palette);
|
|
225
|
+
}
|
package/src/modules/languages.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineModule, type ModuleDefinition } from "./types.js";
|
|
1
|
+
import { defineModule, type ModuleDefinition, type ModuleOptionSchema, type ModuleStyleContext } from "./types.js";
|
|
2
2
|
import { workspaceModuleValues } from "./workspace-helpers.js";
|
|
3
3
|
|
|
4
4
|
const detectionOptions = {
|
|
@@ -14,6 +14,8 @@ function languageModule<const Name extends string>(definition: {
|
|
|
14
14
|
format: string;
|
|
15
15
|
symbol: string;
|
|
16
16
|
style: string;
|
|
17
|
+
options?: Readonly<Record<string, ModuleOptionSchema>>;
|
|
18
|
+
requirementStyle?: boolean;
|
|
17
19
|
}): ModuleDefinition<Name> {
|
|
18
20
|
return defineModule({
|
|
19
21
|
name: definition.name,
|
|
@@ -24,7 +26,20 @@ function languageModule<const Name extends string>(definition: {
|
|
|
24
26
|
style: definition.style,
|
|
25
27
|
disabled: false,
|
|
26
28
|
},
|
|
27
|
-
|
|
29
|
+
...(definition.requirementStyle
|
|
30
|
+
? {
|
|
31
|
+
// Opt in to requirement styling without changing existing output or symbol-only work.
|
|
32
|
+
styleDefaults: { not_capable_style: "none" },
|
|
33
|
+
fallbackStyle: true,
|
|
34
|
+
resolveStyleVariables: ({ runtime, style, styles }: ModuleStyleContext) => ({
|
|
35
|
+
style:
|
|
36
|
+
runtime.workspace?.styleSelectors?.[definition.name] === "not_capable"
|
|
37
|
+
? (styles.not_capable_style ?? style)
|
|
38
|
+
: style,
|
|
39
|
+
}),
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
options: { ...detectionOptions, ...definition.options },
|
|
28
43
|
values: (context) => workspaceModuleValues(definition.name, context),
|
|
29
44
|
});
|
|
30
45
|
}
|
|
@@ -35,6 +50,7 @@ export const nodejsModule = languageModule({
|
|
|
35
50
|
format: "via [$symbol($version )]($style)",
|
|
36
51
|
symbol: " ",
|
|
37
52
|
style: "bold green",
|
|
53
|
+
requirementStyle: true,
|
|
38
54
|
});
|
|
39
55
|
|
|
40
56
|
export const pythonModule = languageModule({
|
|
@@ -43,6 +59,13 @@ export const pythonModule = languageModule({
|
|
|
43
59
|
format: "via [$symbol$pyenv_prefix($version )(\\($virtualenv\\) )]($style)",
|
|
44
60
|
symbol: " ",
|
|
45
61
|
style: "yellow bold",
|
|
62
|
+
options: {
|
|
63
|
+
pyenv_version_name: { kind: "boolean", default: false },
|
|
64
|
+
pyenv_prefix: { kind: "string", default: "pyenv " },
|
|
65
|
+
python_binary: { kind: "command-alternatives", default: [] },
|
|
66
|
+
detect_env_vars: { kind: "string-array", default: [], allowNegative: true },
|
|
67
|
+
generic_venv_names: { kind: "string-array", default: [] },
|
|
68
|
+
},
|
|
46
69
|
});
|
|
47
70
|
|
|
48
71
|
export const rustModule = languageModule({
|
|
@@ -59,6 +82,7 @@ export const golangModule = languageModule({
|
|
|
59
82
|
format: "via [$symbol($version )]($style)",
|
|
60
83
|
symbol: " ",
|
|
61
84
|
style: "bold cyan",
|
|
85
|
+
requirementStyle: true,
|
|
62
86
|
});
|
|
63
87
|
|
|
64
88
|
export const bunModule = languageModule({
|
package/src/modules/package.ts
CHANGED
package/src/modules/render.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
2
|
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
3
3
|
import { activePalette, type ModuleConfig, type StarshipConfig } from "../config.js";
|
|
4
|
-
import { type FormatValue, formatVariables, renderFormat } from "../format/formatter.js";
|
|
4
|
+
import { type FormatValue, formatVariables, parseFormat, renderFormat } from "../format/formatter.js";
|
|
5
5
|
import {
|
|
6
6
|
type ColorPalette,
|
|
7
7
|
isFillChunk,
|
|
@@ -12,8 +12,15 @@ import {
|
|
|
12
12
|
import { sanitizeFormatText } from "../format/terminal-safety.js";
|
|
13
13
|
import type { ThemeColors } from "../format/theme-colors.js";
|
|
14
14
|
import { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
|
|
15
|
+
import { directoryAlternateFormat } from "./directory.js";
|
|
15
16
|
import { resolveStyleRule } from "./style-rules.js";
|
|
16
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
ModuleOptionValue,
|
|
19
|
+
ModuleStyleContext,
|
|
20
|
+
ModuleValueContext,
|
|
21
|
+
RenderedStatusline,
|
|
22
|
+
StarshipRuntimeSnapshot,
|
|
23
|
+
} from "./types.js";
|
|
17
24
|
|
|
18
25
|
export function renderStatusline(
|
|
19
26
|
config: StarshipConfig,
|
|
@@ -32,13 +39,15 @@ export function renderStatusline(
|
|
|
32
39
|
for (const definition of MODULE_DEFINITIONS) {
|
|
33
40
|
const name = definition.name;
|
|
34
41
|
const module = config.modules[name];
|
|
35
|
-
const
|
|
42
|
+
const context = valueContext(config, name, runtime, palette);
|
|
43
|
+
const values = definition.values(context);
|
|
36
44
|
if (!values) continue;
|
|
37
45
|
const styleContext: ModuleStyleContext = {
|
|
38
46
|
runtime,
|
|
39
47
|
style: module.style,
|
|
40
48
|
styles: module.styles,
|
|
41
49
|
display: module.display,
|
|
50
|
+
options: context.options,
|
|
42
51
|
};
|
|
43
52
|
const baseStyleVariables = definition.resolveStyleVariables
|
|
44
53
|
? definition.resolveStyleVariables(styleContext)
|
|
@@ -50,10 +59,16 @@ export function renderStatusline(
|
|
|
50
59
|
const styleVariables = ruleStyle === undefined ? baseStyleVariables : { ...baseStyleVariables, style: ruleStyle };
|
|
51
60
|
const contentValues: Record<string, FormatValue> = Object.fromEntries(
|
|
52
61
|
definition.variables.flatMap((variable) =>
|
|
53
|
-
|
|
62
|
+
Object.hasOwn(values, variable) ? [[variable, values[variable]]] : [],
|
|
54
63
|
),
|
|
55
64
|
);
|
|
56
|
-
const
|
|
65
|
+
const alternate = definition.resolveFormat?.(context, values);
|
|
66
|
+
const rendered = renderModule(
|
|
67
|
+
alternate === undefined ? module : { ...module, formatAst: parseFormat(alternate) },
|
|
68
|
+
contentValues,
|
|
69
|
+
styleVariables,
|
|
70
|
+
palette,
|
|
71
|
+
);
|
|
57
72
|
modules[name] = rendered;
|
|
58
73
|
layoutModules[name] =
|
|
59
74
|
definition.layout === "fill" && !module.disabled ? [{ type: "fill", pattern: rendered }] : rendered;
|
|
@@ -84,17 +99,10 @@ function valueContext(
|
|
|
84
99
|
runtime: runtimeForDisplay(name, runtime),
|
|
85
100
|
palette,
|
|
86
101
|
symbol: sanitizeFormatText(config.modules[name].symbol),
|
|
102
|
+
styles: config.modules[name].styles,
|
|
103
|
+
requestedVariables: formatVariables(config.modules[name].formatAst),
|
|
87
104
|
options: Object.fromEntries(
|
|
88
|
-
Object.entries(config.modules[name].options).map(([key, value]) => [
|
|
89
|
-
key,
|
|
90
|
-
typeof value === "string"
|
|
91
|
-
? sanitizeTerminalText(value)
|
|
92
|
-
: Array.isArray(value)
|
|
93
|
-
? value.map(sanitizeTerminalText)
|
|
94
|
-
: value && typeof value === "object"
|
|
95
|
-
? sanitizeFields(value)
|
|
96
|
-
: value,
|
|
97
|
-
]),
|
|
105
|
+
Object.entries(config.modules[name].options).map(([key, value]) => [key, sanitizeOption(value)]),
|
|
98
106
|
),
|
|
99
107
|
extensionStatus: {
|
|
100
108
|
...config.extensionStatus,
|
|
@@ -106,6 +114,17 @@ function valueContext(
|
|
|
106
114
|
};
|
|
107
115
|
}
|
|
108
116
|
|
|
117
|
+
function sanitizeOption(value: ModuleOptionValue): ModuleOptionValue {
|
|
118
|
+
if (typeof value === "string") return sanitizeTerminalText(value);
|
|
119
|
+
if (Array.isArray(value)) return value.map((item) => sanitizeOption(item as ModuleOptionValue)) as ModuleOptionValue;
|
|
120
|
+
if (value && typeof value === "object") {
|
|
121
|
+
return Object.fromEntries(
|
|
122
|
+
Object.entries(value).map(([key, item]) => [key, sanitizeOption(item)]),
|
|
123
|
+
) as ModuleOptionValue;
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
|
|
109
128
|
// Shallow presentation copies retain keys used for aliases and status policies.
|
|
110
129
|
function sanitizeFields<T extends object>(value: T): T {
|
|
111
130
|
return Object.fromEntries(
|
|
@@ -176,7 +195,14 @@ export function reachableModuleRequirements(config: StarshipConfig): ReadonlyMap
|
|
|
176
195
|
for (const definition of MODULE_DEFINITIONS) {
|
|
177
196
|
if (config.modules[definition.name].disabled) continue;
|
|
178
197
|
if (!includeAll && !rootVariables.has(definition.name)) continue;
|
|
179
|
-
|
|
198
|
+
const variables = formatVariables(config.modules[definition.name].formatAst);
|
|
199
|
+
if (definition.name === "directory") {
|
|
200
|
+
const alternate = directoryAlternateFormat(config.modules.directory.options, config.modules.directory.styles);
|
|
201
|
+
if (alternate) {
|
|
202
|
+
for (const variable of formatVariables(parseFormat(alternate))) variables.add(variable);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
requirements.set(definition.name, variables);
|
|
180
206
|
}
|
|
181
207
|
return requirements;
|
|
182
208
|
}
|