plazbot-cli 0.3.1 → 0.3.2

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.
@@ -1,17 +1,71 @@
1
1
  // @ts-ignore - marked-terminal no provee tipos
2
2
  import TerminalRenderer from 'marked-terminal';
3
3
  import { marked } from 'marked';
4
+ import chalk from 'chalk';
5
+ // @ts-ignore - cli-highlight no provee tipos completos
6
+ import { highlight, supportsLanguage } from 'cli-highlight';
4
7
  let configured = false;
8
+ const LANG_ALIASES = {
9
+ sh: 'bash',
10
+ shell: 'bash',
11
+ zsh: 'bash',
12
+ curl: 'bash',
13
+ jsx: 'javascript',
14
+ ts: 'typescript',
15
+ tsx: 'typescript',
16
+ yml: 'yaml',
17
+ html: 'xml',
18
+ text: 'plaintext',
19
+ txt: 'plaintext',
20
+ };
21
+ function resolveLang(raw) {
22
+ const k = (raw ?? '').toLowerCase().trim();
23
+ const aliased = LANG_ALIASES[k] ?? k;
24
+ if (!aliased)
25
+ return 'plaintext';
26
+ try {
27
+ return supportsLanguage(aliased) ? aliased : 'plaintext';
28
+ }
29
+ catch {
30
+ return 'plaintext';
31
+ }
32
+ }
33
+ function renderCodeBlock(code, rawLang) {
34
+ const lang = resolveLang(rawLang);
35
+ let body;
36
+ try {
37
+ body = highlight(code, { language: lang, ignoreIllegals: true });
38
+ }
39
+ catch {
40
+ body = code;
41
+ }
42
+ const label = (rawLang ?? '').trim() || lang;
43
+ const width = Math.max(20, Math.min(80, (process.stdout.columns || 80) - 8));
44
+ const headerLabel = ` ${label} `;
45
+ const headerRule = '─'.repeat(Math.max(0, width - headerLabel.length - 4));
46
+ const header = chalk.gray.dim(`──${headerLabel}${headerRule}`);
47
+ const footer = chalk.gray.dim('─'.repeat(width - 2));
48
+ // Indent del cuerpo para diferenciar del prosa
49
+ const indented = body
50
+ .split('\n')
51
+ .map((l) => ' ' + l)
52
+ .join('\n');
53
+ return `\n${header}\n${indented}\n${footer}\n`;
54
+ }
5
55
  function configure() {
6
56
  if (configured)
7
57
  return;
8
- marked.setOptions({
9
- renderer: new TerminalRenderer({
10
- width: Math.max(40, (process.stdout.columns || 80) - 8),
11
- reflowText: true,
12
- tab: 2,
13
- }),
58
+ const renderer = new TerminalRenderer({
59
+ width: Math.max(40, (process.stdout.columns || 80) - 8),
60
+ reflowText: true,
61
+ tab: 2,
62
+ // Inline code mejor diferenciado del texto normal
63
+ codespan: chalk.cyan,
14
64
  });
65
+ // Override del code block para syntax highlight + box delimitado.
66
+ // marked-terminal pasa (code, lang, escaped) al método `code`.
67
+ renderer.code = (code, lang) => renderCodeBlock(code, lang);
68
+ marked.setOptions({ renderer });
15
69
  configured = true;
16
70
  }
17
71
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plazbot-cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "CLI para Plazbot SDK",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",
@@ -39,6 +39,7 @@
39
39
  "axios": "^1.6.0",
40
40
  "boxen": "^7.1.1",
41
41
  "chalk": "^5.3.0",
42
+ "cli-highlight": "^2.1.11",
42
43
  "cli-table3": "^0.6.5",
43
44
  "commander": "^12.0.0",
44
45
  "figures": "^6.1.0",
@@ -1,18 +1,79 @@
1
1
  // @ts-ignore - marked-terminal no provee tipos
2
2
  import TerminalRenderer from 'marked-terminal';
3
3
  import { marked } from 'marked';
4
+ import chalk from 'chalk';
5
+ // @ts-ignore - cli-highlight no provee tipos completos
6
+ import { highlight, supportsLanguage } from 'cli-highlight';
4
7
 
5
8
  let configured = false;
6
9
 
10
+ const LANG_ALIASES: Record<string, string> = {
11
+ sh: 'bash',
12
+ shell: 'bash',
13
+ zsh: 'bash',
14
+ curl: 'bash',
15
+ jsx: 'javascript',
16
+ ts: 'typescript',
17
+ tsx: 'typescript',
18
+ yml: 'yaml',
19
+ html: 'xml',
20
+ text: 'plaintext',
21
+ txt: 'plaintext',
22
+ };
23
+
24
+ function resolveLang(raw: string | undefined): string {
25
+ const k = (raw ?? '').toLowerCase().trim();
26
+ const aliased = LANG_ALIASES[k] ?? k;
27
+ if (!aliased) return 'plaintext';
28
+ try {
29
+ return supportsLanguage(aliased) ? aliased : 'plaintext';
30
+ } catch {
31
+ return 'plaintext';
32
+ }
33
+ }
34
+
35
+ function renderCodeBlock(code: string, rawLang: string | undefined): string {
36
+ const lang = resolveLang(rawLang);
37
+ let body: string;
38
+ try {
39
+ body = highlight(code, { language: lang, ignoreIllegals: true });
40
+ } catch {
41
+ body = code;
42
+ }
43
+
44
+ const label = (rawLang ?? '').trim() || lang;
45
+ const width = Math.max(20, Math.min(80, (process.stdout.columns || 80) - 8));
46
+ const headerLabel = ` ${label} `;
47
+ const headerRule = '─'.repeat(Math.max(0, width - headerLabel.length - 4));
48
+ const header = chalk.gray.dim(`──${headerLabel}${headerRule}`);
49
+ const footer = chalk.gray.dim('─'.repeat(width - 2));
50
+
51
+ // Indent del cuerpo para diferenciar del prosa
52
+ const indented = body
53
+ .split('\n')
54
+ .map((l) => ' ' + l)
55
+ .join('\n');
56
+
57
+ return `\n${header}\n${indented}\n${footer}\n`;
58
+ }
59
+
7
60
  function configure(): void {
8
61
  if (configured) return;
9
- marked.setOptions({
10
- renderer: new TerminalRenderer({
11
- width: Math.max(40, (process.stdout.columns || 80) - 8),
12
- reflowText: true,
13
- tab: 2,
14
- }) as any,
15
- });
62
+
63
+ const renderer = new TerminalRenderer({
64
+ width: Math.max(40, (process.stdout.columns || 80) - 8),
65
+ reflowText: true,
66
+ tab: 2,
67
+ // Inline code mejor diferenciado del texto normal
68
+ codespan: chalk.cyan,
69
+ }) as any;
70
+
71
+ // Override del code block para syntax highlight + box delimitado.
72
+ // marked-terminal pasa (code, lang, escaped) al método `code`.
73
+ renderer.code = (code: string, lang: string | undefined): string =>
74
+ renderCodeBlock(code, lang);
75
+
76
+ marked.setOptions({ renderer });
16
77
  configured = true;
17
78
  }
18
79