@nbtca/prompt 1.5.23 → 1.6.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/dist/prompt.js ADDED
@@ -0,0 +1,52 @@
1
+ import { resolveIconMode } from './config/preferences.js';
2
+ import { promptClass, promptLine, serializePromptClass } from './features/prompt-line.js';
3
+ import { peekSchedule } from './features/schedule-view.js';
4
+ import { fmt, t } from './i18n/index.js';
5
+ const SHELL_SETUP = {
6
+ fish: 'function fish_right_prompt; nbtca prompt; end',
7
+ zsh: "setopt prompt_subst\nRPROMPT='$(nbtca prompt)'",
8
+ bash: 'PS1=\'$(c=$(nbtca prompt); [ -n "$c" ] && printf "%s " "$c")\'"$PS1"',
9
+ tmux: "set -g status-interval 30\nset -g status-right '#(nbtca prompt) %H:%M'",
10
+ };
11
+ function unicodeWanted(plain) {
12
+ if (plain)
13
+ return false;
14
+ const mode = resolveIconMode();
15
+ if (mode !== 'auto')
16
+ return mode === 'unicode';
17
+ const locale = `${process.env['LC_ALL'] ?? ''} ${process.env['LANG'] ?? ''}`.toLowerCase();
18
+ return /utf-?8/.test(locale);
19
+ }
20
+ function fail(message) {
21
+ process.stderr.write(message + '\n');
22
+ return 1;
23
+ }
24
+ /** Runs on every shell prompt, so it reads only the local cache and never loads the full CLI. */
25
+ export function runPromptCommand(argv) {
26
+ const cli = t().cli;
27
+ const flags = argv.filter((arg) => arg.startsWith('--'));
28
+ const extra = argv.find((arg) => !arg.startsWith('--'));
29
+ if (extra !== undefined)
30
+ return fail(fmt(cli.unexpectedArguments, { command: 'prompt' }));
31
+ const unknown = flags.find((flag) => flag !== '--json' && flag !== '--plain' && !flag.startsWith('--shell='));
32
+ if (unknown !== undefined)
33
+ return fail(fmt(cli.invalidFlag, { flag: unknown }));
34
+ const shellFlag = flags.find((flag) => flag.startsWith('--shell='));
35
+ if (shellFlag !== undefined) {
36
+ const setup = SHELL_SETUP[shellFlag.slice('--shell='.length)];
37
+ if (setup === undefined)
38
+ return fail(fmt(cli.invalidFlag, { flag: shellFlag }));
39
+ process.stdout.write(setup + '\n');
40
+ return 0;
41
+ }
42
+ const schedule = peekSchedule();
43
+ const value = schedule ? promptClass(schedule) : undefined;
44
+ if (flags.includes('--json')) {
45
+ process.stdout.write(JSON.stringify(serializePromptClass(value)) + '\n');
46
+ return 0;
47
+ }
48
+ const line = promptLine(value, unicodeWanted(flags.includes('--plain')));
49
+ if (line)
50
+ process.stdout.write(line + '\n');
51
+ return 0;
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbtca/prompt",
3
- "version": "1.5.23",
3
+ "version": "1.6.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -32,7 +32,7 @@
32
32
  "test:cli": "npm run build && bash scripts/test-cli.sh",
33
33
  "precheck:package": "npm run build",
34
34
  "check:package": "node scripts/check-package.mjs",
35
- "check": "npm run format:check && npm run lint && npm run typecheck && npm test && npm run check:package && npm audit --audit-level=moderate",
35
+ "check": "npm run format:check && npm run lint && npm run typecheck && npm test && npm run check:package && npm audit --omit=dev --audit-level=moderate",
36
36
  "prepublishOnly": "npm run check"
37
37
  },
38
38
  "keywords": [
@@ -1,11 +0,0 @@
1
- _.-''''''-._
2
- .-' '-.
3
- .' .-. .-. '.
4
- / (@) (@) \
5
- | '-' '-' |
6
- | |
7
- | \ / |
8
- \ '. .' /
9
- '. '-........-' .'
10
- '-._ _.-'
11
- ''-......-''
@@ -1,3 +0,0 @@
1
- |\ | __ _____ __ /\
2
- | \ | |__) | / /__\
3
- | \| |__) | \__ / \