@ethanfly/sshx 0.0.0-stage → 1.0.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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +308 -2
  3. package/bin/sshx.js +22 -0
  4. package/dist/cli/connect.d.ts +26 -0
  5. package/dist/cli/connect.d.ts.map +1 -0
  6. package/dist/cli/connect.js +183 -0
  7. package/dist/cli/connect.js.map +1 -0
  8. package/dist/cli/exec.d.ts +8 -0
  9. package/dist/cli/exec.d.ts.map +1 -0
  10. package/dist/cli/exec.js +53 -0
  11. package/dist/cli/exec.js.map +1 -0
  12. package/dist/cli/host.d.ts +35 -0
  13. package/dist/cli/host.d.ts.map +1 -0
  14. package/dist/cli/host.js +312 -0
  15. package/dist/cli/host.js.map +1 -0
  16. package/dist/cli/index.d.ts +3 -0
  17. package/dist/cli/index.d.ts.map +1 -0
  18. package/dist/cli/index.js +306 -0
  19. package/dist/cli/index.js.map +1 -0
  20. package/dist/cli/keygen.d.ts +9 -0
  21. package/dist/cli/keygen.d.ts.map +1 -0
  22. package/dist/cli/keygen.js +38 -0
  23. package/dist/cli/keygen.js.map +1 -0
  24. package/dist/cli/sftp.d.ts +9 -0
  25. package/dist/cli/sftp.d.ts.map +1 -0
  26. package/dist/cli/sftp.js +105 -0
  27. package/dist/cli/sftp.js.map +1 -0
  28. package/dist/cli/tunnel.d.ts +8 -0
  29. package/dist/cli/tunnel.d.ts.map +1 -0
  30. package/dist/cli/tunnel.js +79 -0
  31. package/dist/cli/tunnel.js.map +1 -0
  32. package/dist/cli/utils.d.ts +40 -0
  33. package/dist/cli/utils.d.ts.map +1 -0
  34. package/dist/cli/utils.js +115 -0
  35. package/dist/cli/utils.js.map +1 -0
  36. package/dist/core/client.d.ts +49 -0
  37. package/dist/core/client.d.ts.map +1 -0
  38. package/dist/core/client.js +269 -0
  39. package/dist/core/client.js.map +1 -0
  40. package/dist/core/config.d.ts +101 -0
  41. package/dist/core/config.d.ts.map +1 -0
  42. package/dist/core/config.js +617 -0
  43. package/dist/core/config.js.map +1 -0
  44. package/dist/core/exec.d.ts +25 -0
  45. package/dist/core/exec.d.ts.map +1 -0
  46. package/dist/core/exec.js +88 -0
  47. package/dist/core/exec.js.map +1 -0
  48. package/dist/core/keygen.d.ts +45 -0
  49. package/dist/core/keygen.d.ts.map +1 -0
  50. package/dist/core/keygen.js +233 -0
  51. package/dist/core/keygen.js.map +1 -0
  52. package/dist/core/known-hosts.d.ts +30 -0
  53. package/dist/core/known-hosts.d.ts.map +1 -0
  54. package/dist/core/known-hosts.js +201 -0
  55. package/dist/core/known-hosts.js.map +1 -0
  56. package/dist/core/session.d.ts +44 -0
  57. package/dist/core/session.d.ts.map +1 -0
  58. package/dist/core/session.js +160 -0
  59. package/dist/core/session.js.map +1 -0
  60. package/dist/core/sftp.d.ts +80 -0
  61. package/dist/core/sftp.d.ts.map +1 -0
  62. package/dist/core/sftp.js +368 -0
  63. package/dist/core/sftp.js.map +1 -0
  64. package/dist/core/tunnel.d.ts +86 -0
  65. package/dist/core/tunnel.d.ts.map +1 -0
  66. package/dist/core/tunnel.js +405 -0
  67. package/dist/core/tunnel.js.map +1 -0
  68. package/dist/index.d.ts +9 -0
  69. package/dist/index.d.ts.map +1 -0
  70. package/dist/index.js +9 -0
  71. package/dist/index.js.map +1 -0
  72. package/dist/skill/mcp-server.d.ts +4 -0
  73. package/dist/skill/mcp-server.d.ts.map +1 -0
  74. package/dist/skill/mcp-server.js +284 -0
  75. package/dist/skill/mcp-server.js.map +1 -0
  76. package/dist/skill/runner.d.ts +2 -0
  77. package/dist/skill/runner.d.ts.map +1 -0
  78. package/dist/skill/runner.js +97 -0
  79. package/dist/skill/runner.js.map +1 -0
  80. package/dist/skill/tools.d.ts +106 -0
  81. package/dist/skill/tools.d.ts.map +1 -0
  82. package/dist/skill/tools.js +218 -0
  83. package/dist/skill/tools.js.map +1 -0
  84. package/dist/tui/app.d.ts +29 -0
  85. package/dist/tui/app.d.ts.map +1 -0
  86. package/dist/tui/app.js +334 -0
  87. package/dist/tui/app.js.map +1 -0
  88. package/dist/tui/form.d.ts +20 -0
  89. package/dist/tui/form.d.ts.map +1 -0
  90. package/dist/tui/form.js +132 -0
  91. package/dist/tui/form.js.map +1 -0
  92. package/dist/tui/index.d.ts +4 -0
  93. package/dist/tui/index.d.ts.map +1 -0
  94. package/dist/tui/index.js +6 -0
  95. package/dist/tui/index.js.map +1 -0
  96. package/dist/tui/screen.d.ts +24 -0
  97. package/dist/tui/screen.d.ts.map +1 -0
  98. package/dist/tui/screen.js +134 -0
  99. package/dist/tui/screen.js.map +1 -0
  100. package/dist/tui/screens/hosts.d.ts +40 -0
  101. package/dist/tui/screens/hosts.d.ts.map +1 -0
  102. package/dist/tui/screens/hosts.js +272 -0
  103. package/dist/tui/screens/hosts.js.map +1 -0
  104. package/dist/tui/theme.d.ts +15 -0
  105. package/dist/tui/theme.d.ts.map +1 -0
  106. package/dist/tui/theme.js +57 -0
  107. package/dist/tui/theme.js.map +1 -0
  108. package/package.json +51 -4
@@ -0,0 +1,132 @@
1
+ import { stripAnsi, padClip, stringWidth } from './screen.js';
2
+ import { colors } from '../cli/utils.js';
3
+ /**
4
+ * Full-screen form used by the TUI for add/edit host and key generation.
5
+ * Returns when the user submits (Ctrl+S / Ctrl+Enter) or cancels (Esc).
6
+ */
7
+ export async function runForm(screen, theme, title, fields, footerHint) {
8
+ let index = 0;
9
+ let cursor = fields[0]?.value.length || 0;
10
+ const render = () => {
11
+ screen.clear();
12
+ const w = Math.min(screen.cols - 2, 78);
13
+ const h = Math.min(screen.rows - 2, fields.length + 6);
14
+ const x = Math.max(1, Math.floor((screen.cols - w) / 2));
15
+ const y = Math.max(1, Math.floor((screen.rows - h) / 2));
16
+ screen.drawBox(x, y, w, h, title, theme.border);
17
+ fields.forEach((field, i) => {
18
+ const row = y + 2 + i;
19
+ const active = i === index;
20
+ const label = padClip(field.label, 16);
21
+ const shown = field.secret ? '*'.repeat(field.value.length) : field.value;
22
+ const marker = active ? `${theme.accent}▸${colors.reset}` : ' ';
23
+ screen.writeAt(x + 2, row, `${marker} ${theme.muted}${label}${colors.reset} ${shown}`);
24
+ if (active) {
25
+ const cursorVisualWidth = field.secret ? field.value.length : stringWidth(field.value.slice(0, cursor));
26
+ const col = x + 2 + 2 + 16 + 1 + cursorVisualWidth;
27
+ screen.writeAt(Math.min(col, screen.cols), row, `${theme.accent}▍${colors.reset}`);
28
+ screen.showCursor();
29
+ }
30
+ });
31
+ const hintRow = y + h - 2;
32
+ screen.writeAt(x + 2, hintRow, `${theme.muted}${footerHint}${colors.reset}`);
33
+ const activeHint = fields[index]?.hint;
34
+ if (activeHint) {
35
+ screen.writeAt(x + 2, y + h - 1 > screen.rows ? screen.rows : Math.min(screen.rows, hintRow + 1), '');
36
+ }
37
+ screen.flush();
38
+ };
39
+ render();
40
+ return new Promise((resolve) => {
41
+ const onKey = (str, key) => {
42
+ const field = fields[index];
43
+ if (!field)
44
+ return;
45
+ if (key.ctrl && key.name === 'c') {
46
+ cleanup();
47
+ resolve({ cancelled: true, values: {} });
48
+ return;
49
+ }
50
+ if (key.name === 'escape') {
51
+ cleanup();
52
+ resolve({ cancelled: true, values: {} });
53
+ return;
54
+ }
55
+ if (key.ctrl && (key.name === 's' || key.name === 'return')) {
56
+ cleanup();
57
+ resolve({ cancelled: false, values: collect() });
58
+ return;
59
+ }
60
+ if (key.name === 'tab' || (key.name === 'down' && !key.shift) || (key.ctrl && key.name === 'n')) {
61
+ index = (index + 1) % fields.length;
62
+ cursor = fields[index].value.length;
63
+ render();
64
+ return;
65
+ }
66
+ if (key.name === 'up' || (key.shift && key.name === 'tab') || (key.ctrl && key.name === 'p')) {
67
+ index = (index - 1 + fields.length) % fields.length;
68
+ cursor = fields[index].value.length;
69
+ render();
70
+ return;
71
+ }
72
+ if (key.name === 'return') {
73
+ index = Math.min(fields.length - 1, index + 1);
74
+ cursor = fields[index].value.length;
75
+ render();
76
+ return;
77
+ }
78
+ if (key.name === 'backspace') {
79
+ if (cursor > 0) {
80
+ field.value = field.value.slice(0, cursor - 1) + field.value.slice(cursor);
81
+ cursor--;
82
+ }
83
+ render();
84
+ return;
85
+ }
86
+ if (key.name === 'delete') {
87
+ field.value = field.value.slice(0, cursor) + field.value.slice(cursor + 1);
88
+ render();
89
+ return;
90
+ }
91
+ if (key.name === 'left') {
92
+ cursor = Math.max(0, cursor - 1);
93
+ render();
94
+ return;
95
+ }
96
+ if (key.name === 'right') {
97
+ cursor = Math.min(field.value.length, cursor + 1);
98
+ render();
99
+ return;
100
+ }
101
+ if (key.name === 'home') {
102
+ cursor = 0;
103
+ render();
104
+ return;
105
+ }
106
+ if (key.name === 'end') {
107
+ cursor = field.value.length;
108
+ render();
109
+ return;
110
+ }
111
+ if (str && str.length === 1 && !key.ctrl && !key.meta && str >= ' ' && str !== '\x1b') {
112
+ field.value = field.value.slice(0, cursor) + str + field.value.slice(cursor);
113
+ cursor++;
114
+ render();
115
+ }
116
+ };
117
+ const cleanup = () => {
118
+ process.stdin.removeListener('keypress', onKey);
119
+ };
120
+ process.stdin.on('keypress', onKey);
121
+ });
122
+ function collect() {
123
+ const values = {};
124
+ for (const field of fields)
125
+ values[field.key] = field.value;
126
+ return values;
127
+ }
128
+ }
129
+ export function clipVisible(text, width) {
130
+ return padClip(stripAnsi(text), width);
131
+ }
132
+ //# sourceMappingURL=form.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.js","sourceRoot":"","sources":["../../src/tui/form.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE5E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAezC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,MAAoB,EACpB,KAAe,EACf,KAAa,EACb,MAAmB,EACnB,UAAkB;IAElB,IAAI,KAAK,GAAG,CAAC,CAAC;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,CAAC,IAAI,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;gBACtF,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC7E,MAAM,EAAE,CAAC;gBACT,MAAM,EAAE,CAAC;YACX,CAAC;QACH,CAAC,CAAC;QAEF,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAClD,CAAC,CAAC;QAEF,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,OAAO;QACd,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,MAAM;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;QAC5D,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,KAAa;IACrD,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { TuiOptions } from './app.js';
2
+ export type { TuiOptions } from './app.js';
3
+ export declare function startTUI(options?: TuiOptions): Promise<void>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,UAAU,EAAE,MAAM,UAAU,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,wBAAsB,QAAQ,CAAC,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAGtE"}
@@ -0,0 +1,6 @@
1
+ import { TuiApp } from './app.js';
2
+ export async function startTUI(options = {}) {
3
+ const app = new TuiApp(options);
4
+ await app.start();
5
+ }
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAC;AAI9C,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,OAAO,GAAe,EAAE;IACrD,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,24 @@
1
+ export interface TerminalDimensions {
2
+ cols: number;
3
+ rows: number;
4
+ }
5
+ export declare class ScreenBuffer {
6
+ private buffer;
7
+ cols: number;
8
+ rows: number;
9
+ constructor();
10
+ updateDimensions(): TerminalDimensions;
11
+ enterAltScreen(): void;
12
+ exitAltScreen(): void;
13
+ clear(): void;
14
+ showCursor(): void;
15
+ moveTo(col: number, row: number): string;
16
+ writeAt(col: number, row: number, text: string): void;
17
+ drawBox(x: number, y: number, w: number, h: number, title?: string, borderColor?: string): void;
18
+ flush(): void;
19
+ }
20
+ export declare function stripAnsi(str: string): string;
21
+ export declare function charWidth(code: number): number;
22
+ export declare function stringWidth(str: string): number;
23
+ export declare function padClip(text: string, width: number): string;
24
+ //# sourceMappingURL=screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../../src/tui/screen.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgB;IACvB,IAAI,EAAE,MAAM,CAAM;IAClB,IAAI,EAAE,MAAM,CAAM;IAEzB,cAEC;IAEM,gBAAgB,IAAI,kBAAkB,CAI5C;IAEM,cAAc,IAAI,IAAI,CAE5B;IAEM,aAAa,IAAI,IAAI,CAE3B;IAEM,KAAK,IAAI,IAAI,CAEnB;IAEM,UAAU,IAAI,IAAI,CAExB;IAEM,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9C;IAEM,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAG3D;IAEM,OAAO,CACZ,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,CAAC,EAAE,MAAM,EACd,WAAW,GAAE,MAAoB,GAChC,IAAI,CAqBN;IAEM,KAAK,IAAI,IAAI,CAGnB;CACF;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAmB9C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO/C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA8C3D"}
@@ -0,0 +1,134 @@
1
+ import { colors } from '../cli/utils.js';
2
+ export class ScreenBuffer {
3
+ buffer = [];
4
+ cols = 80;
5
+ rows = 24;
6
+ constructor() {
7
+ this.updateDimensions();
8
+ }
9
+ updateDimensions() {
10
+ this.cols = process.stdout.columns || 80;
11
+ this.rows = process.stdout.rows || 24;
12
+ return { cols: this.cols, rows: this.rows };
13
+ }
14
+ enterAltScreen() {
15
+ process.stdout.write('\x1b[?1049h\x1b[0m\x1b[?25l\x1b[?1l\x1b>\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l');
16
+ }
17
+ exitAltScreen() {
18
+ process.stdout.write('\x1b[?25h\x1b[0m\x1b[?1049l');
19
+ }
20
+ clear() {
21
+ this.buffer = ['\x1b[H\x1b[2J'];
22
+ }
23
+ showCursor() {
24
+ this.buffer.push('\x1b[?25h');
25
+ }
26
+ moveTo(col, row) {
27
+ return `\x1b[${row};${col}H`;
28
+ }
29
+ writeAt(col, row, text) {
30
+ if (row < 1 || row > this.rows || col < 1 || col > this.cols)
31
+ return;
32
+ this.buffer.push(`${this.moveTo(col, row)}${text}`);
33
+ }
34
+ drawBox(x, y, w, h, title, borderColor = colors.gray) {
35
+ const maxX = Math.min(this.cols, x + w - 1);
36
+ const maxY = Math.min(this.rows, y + h - 1);
37
+ const innerW = maxX - x - 1;
38
+ if (innerW < 1 || maxY - y < 1)
39
+ return;
40
+ let top = '┌' + '─'.repeat(innerW) + '┐';
41
+ const titleWidth = title ? stringWidth(title) : 0;
42
+ if (title && innerW > titleWidth + 4) {
43
+ top = `┌─ ${colors.bold}${title}${colors.reset}${borderColor} ` + '─'.repeat(innerW - titleWidth - 4) + '┐';
44
+ }
45
+ this.writeAt(x, y, `${borderColor}${top}${colors.reset}`);
46
+ for (let r = y + 1; r < maxY; r++) {
47
+ this.writeAt(x, r, `${borderColor}│${colors.reset}`);
48
+ this.writeAt(maxX, r, `${borderColor}│${colors.reset}`);
49
+ }
50
+ const bottom = '└' + '─'.repeat(innerW) + '┘';
51
+ this.writeAt(x, maxY, `${borderColor}${bottom}${colors.reset}`);
52
+ }
53
+ flush() {
54
+ process.stdout.write(this.buffer.join('') + '\x1b[0m');
55
+ this.buffer = [];
56
+ }
57
+ }
58
+ export function stripAnsi(str) {
59
+ return str.replace(/\x1B\[[0-?]*[ -/]*[@-~]/g, '');
60
+ }
61
+ export function charWidth(code) {
62
+ if (code < 0x20 || (code >= 0x7f && code < 0xa0))
63
+ return 0;
64
+ // Combining marks
65
+ if (code >= 0x0300 && code <= 0x036f)
66
+ return 0;
67
+ // CJK and fullwidth ranges
68
+ if ((code >= 0x1100 && code <= 0x115f) || // Hangul Jamo
69
+ (code >= 0x2e80 && code <= 0x9fff) || // CJK Radicals, Ideographs
70
+ (code >= 0xac00 && code <= 0xd7a3) || // Hangul Syllables
71
+ (code >= 0xf900 && code <= 0xfaff) || // CJK Compatibility
72
+ (code >= 0xfe10 && code <= 0xfe19) || // Vertical forms
73
+ (code >= 0xfe30 && code <= 0xfe6f) || // CJK Compatibility Forms
74
+ (code >= 0xff00 && code <= 0xff60) || // Fullwidth Forms
75
+ (code >= 0xffe0 && code <= 0xffe6) || // Fullwidth punctuation & currency
76
+ (code >= 0x20000 && code <= 0x323af) // CJK Extension B-G
77
+ ) {
78
+ return 2;
79
+ }
80
+ return 1;
81
+ }
82
+ export function stringWidth(str) {
83
+ const plain = stripAnsi(str);
84
+ let width = 0;
85
+ for (const char of plain) {
86
+ width += charWidth(char.codePointAt(0) || 0);
87
+ }
88
+ return width;
89
+ }
90
+ export function padClip(text, width) {
91
+ const targetWidth = Math.max(0, width);
92
+ let currentWidth = 0;
93
+ let result = '';
94
+ let i = 0;
95
+ while (i < text.length) {
96
+ // Retain ANSI escape sequences without consuming display width
97
+ if (text[i] === '\x1b' && text[i + 1] === '[') {
98
+ let j = i + 2;
99
+ while (j < text.length && !/[a-zA-Z]/.test(text[j]))
100
+ j++;
101
+ if (j < text.length) {
102
+ result += text.slice(i, j + 1);
103
+ i = j + 1;
104
+ continue;
105
+ }
106
+ }
107
+ const code = text.codePointAt(i) || 0;
108
+ const char = String.fromCodePoint(code);
109
+ i += char.length;
110
+ const w = charWidth(code);
111
+ if (currentWidth + w > targetWidth) {
112
+ // Need to truncate. Reserve 1 cell for '…'
113
+ while (result.length > 0 && currentWidth + 1 > targetWidth) {
114
+ let lastCharLen = 1;
115
+ if (result.length >= 2) {
116
+ const high = result.charCodeAt(result.length - 2);
117
+ if (high >= 0xd800 && high <= 0xdbff)
118
+ lastCharLen = 2;
119
+ }
120
+ const lastCode = result.codePointAt(result.length - lastCharLen) || 0;
121
+ currentWidth -= charWidth(lastCode);
122
+ result = result.slice(0, result.length - lastCharLen);
123
+ }
124
+ return targetWidth >= 1 ? result + '…' : result;
125
+ }
126
+ result += char;
127
+ currentWidth += w;
128
+ }
129
+ if (currentWidth < targetWidth) {
130
+ result += ' '.repeat(targetWidth - currentWidth);
131
+ }
132
+ return result;
133
+ }
134
+ //# sourceMappingURL=screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screen.js","sourceRoot":"","sources":["../../src/tui/screen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOzC,MAAM,OAAO,YAAY;IACf,MAAM,GAAa,EAAE,CAAC;IACvB,IAAI,GAAW,EAAE,CAAC;IAClB,IAAI,GAAW,EAAE,CAAC;IAEzB;QACE,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAEM,gBAAgB;QACrB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACtC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IAC9C,CAAC;IAEM,cAAc;QACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sFAAsF,CAAC,CAAC;IAC/G,CAAC;IAEM,aAAa;QAClB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACtD,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,GAAG,CAAC,eAAe,CAAC,CAAC;IAClC,CAAC;IAEM,UAAU;QACf,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,GAAW,EA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E,CAAC;oBACvB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;oBAClD,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM;wBAAE,WAAW,GAAG,CAAC,CAAC;gBACxD,CAAC;gBACD,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;gBACtE,YAAY,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;gBACpC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC;YACxD,CAAC;YACD,OAAO,WAAW,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;QAClD,CAAC;QAED,MAAM,IAAI,IAAI,CAAC;QACf,YAAY,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,IAAI,YAAY,GAAG,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,GAAG,YAAY,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { HostProfile } from '../../core/config.js';
2
+ import { ScreenBuffer } from '../screen.js';
3
+ import { TuiTheme } from '../theme.js';
4
+ export type HostSortMode = 'name' | 'none' | 'fancy';
5
+ export declare class HostsScreen {
6
+ selectedIndex: number;
7
+ scrollOffset: number;
8
+ filterQuery: string;
9
+ statusMessage: string;
10
+ sortMode: HostSortMode;
11
+ private hosts;
12
+ private latencyMap;
13
+ constructor(options?: {
14
+ search?: string;
15
+ sort?: HostSortMode;
16
+ });
17
+ refreshHosts(): void;
18
+ getFilteredHosts(): HostProfile[];
19
+ getSelectedHost(): HostProfile | undefined;
20
+ move(delta: number, visibleRows: number): void;
21
+ jump(index: number, visibleRows: number): void;
22
+ private ensureVisible;
23
+ appendFilter(ch: string): void;
24
+ backspaceFilter(): void;
25
+ clearFilter(): void;
26
+ render(screen: ScreenBuffer, theme: TuiTheme): void;
27
+ testSelectedLatency(): Promise<void>;
28
+ }
29
+ export interface TableLayout {
30
+ name: number;
31
+ dest: number;
32
+ auth: number;
33
+ tags: number;
34
+ notes?: number;
35
+ last: number;
36
+ gap: number;
37
+ totalWidth: number;
38
+ }
39
+ export declare function computeTableLayout(screenCols: number, hosts: HostProfile[]): TableLayout;
40
+ //# sourceMappingURL=hosts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosts.d.ts","sourceRoot":"","sources":["../../../src/tui/screens/hosts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAwB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAErD,qBAAa,WAAW;IACf,aAAa,EAAE,MAAM,CAAK;IAC1B,YAAY,EAAE,MAAM,CAAK;IACzB,WAAW,EAAE,MAAM,CAAM;IACzB,aAAa,EAAE,MAAM,CAAM;IAC3B,QAAQ,EAAE,YAAY,CAAU;IACvC,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,UAAU,CAAkC;IAEpD,YAAY,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,YAAY,CAAA;KAAO,EAIjE;IAEM,YAAY,IAAI,IAAI,CAY1B;IAEM,gBAAgB,IAAI,WAAW,EAAE,CA4BvC;IAEM,eAAe,IAAI,WAAW,GAAG,SAAS,CAEhD;IAEM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAIpD;IAEM,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAIpD;IAED,OAAO,CAAC,aAAa;IAQd,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAIpC;IAEM,eAAe,IAAI,IAAI,CAI7B;IAEM,WAAW,IAAI,IAAI,CAIzB;IAEM,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAwFzD;IAEY,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWhD;CACF;AAYD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,WAAW,CAuExF"}
@@ -0,0 +1,272 @@
1
+ import { defaultConfigManager } from '../../core/config.js';
2
+ import { SSHConnection } from '../../core/client.js';
3
+ import { padClip, stringWidth } from '../screen.js';
4
+ import { colors } from '../../cli/utils.js';
5
+ export class HostsScreen {
6
+ selectedIndex = 0;
7
+ scrollOffset = 0;
8
+ filterQuery = '';
9
+ statusMessage = '';
10
+ sortMode = 'name';
11
+ hosts = [];
12
+ latencyMap = new Map();
13
+ constructor(options = {}) {
14
+ this.filterQuery = options.search || '';
15
+ this.sortMode = options.sort || 'name';
16
+ this.refreshHosts();
17
+ }
18
+ refreshHosts() {
19
+ const selected = this.getSelectedHost();
20
+ this.hosts = defaultConfigManager.getHosts();
21
+ const list = this.getFilteredHosts();
22
+ if (selected) {
23
+ const idx = list.findIndex(h => h.id === selected.id);
24
+ this.selectedIndex = idx >= 0 ? idx : 0;
25
+ }
26
+ if (this.selectedIndex >= list.length) {
27
+ this.selectedIndex = Math.max(0, list.length - 1);
28
+ }
29
+ this.ensureVisible(Math.max(1, 10));
30
+ }
31
+ getFilteredHosts() {
32
+ const terms = this.filterQuery.trim().toLowerCase().split(/\s+/).filter(Boolean);
33
+ let list = this.hosts.filter(h => {
34
+ if (terms.length === 0)
35
+ return true;
36
+ const haystack = [
37
+ h.name,
38
+ h.host,
39
+ h.username,
40
+ String(h.port),
41
+ h.notes || '',
42
+ ...(h.tags || [])
43
+ ].join(' ').toLowerCase();
44
+ return terms.every(term => haystack.includes(term));
45
+ });
46
+ if (this.sortMode === 'name') {
47
+ list = [...list].sort((a, b) => a.name.localeCompare(b.name));
48
+ }
49
+ else if (this.sortMode === 'fancy') {
50
+ list = [...list].sort((a, b) => {
51
+ const fav = Number(!!b.favorite) - Number(!!a.favorite);
52
+ if (fav !== 0)
53
+ return fav;
54
+ const at = a.lastConnected ? Date.parse(a.lastConnected) : 0;
55
+ const bt = b.lastConnected ? Date.parse(b.lastConnected) : 0;
56
+ if (bt !== at)
57
+ return bt - at;
58
+ return a.name.localeCompare(b.name);
59
+ });
60
+ }
61
+ return list;
62
+ }
63
+ getSelectedHost() {
64
+ return this.getFilteredHosts()[this.selectedIndex];
65
+ }
66
+ move(delta, visibleRows) {
67
+ const max = Math.max(0, this.getFilteredHosts().length - 1);
68
+ this.selectedIndex = Math.min(max, Math.max(0, this.selectedIndex + delta));
69
+ this.ensureVisible(visibleRows);
70
+ }
71
+ jump(index, visibleRows) {
72
+ const max = Math.max(0, this.getFilteredHosts().length - 1);
73
+ this.selectedIndex = Math.min(max, Math.max(0, index));
74
+ this.ensureVisible(visibleRows);
75
+ }
76
+ ensureVisible(visibleRows) {
77
+ if (this.selectedIndex < this.scrollOffset) {
78
+ this.scrollOffset = this.selectedIndex;
79
+ }
80
+ else if (this.selectedIndex >= this.scrollOffset + visibleRows) {
81
+ this.scrollOffset = this.selectedIndex - visibleRows + 1;
82
+ }
83
+ }
84
+ appendFilter(ch) {
85
+ this.filterQuery += ch;
86
+ this.selectedIndex = 0;
87
+ this.scrollOffset = 0;
88
+ }
89
+ backspaceFilter() {
90
+ this.filterQuery = this.filterQuery.slice(0, -1);
91
+ this.selectedIndex = 0;
92
+ this.scrollOffset = 0;
93
+ }
94
+ clearFilter() {
95
+ this.filterQuery = '';
96
+ this.selectedIndex = 0;
97
+ this.scrollOffset = 0;
98
+ }
99
+ render(screen, theme) {
100
+ const list = this.getFilteredHosts();
101
+ const headerRow = 3;
102
+ const listTop = 4;
103
+ const footerRow = screen.rows;
104
+ const visibleRows = Math.max(1, footerRow - listTop - 1);
105
+ this.ensureVisible(visibleRows);
106
+ const query = this.filterQuery;
107
+ const searchLabel = query.length > 0
108
+ ? `${theme.accent}search:${colors.reset} ${query}${theme.accent}▍${colors.reset}`
109
+ : `${theme.muted}type to search · space = AND${colors.reset}`;
110
+ screen.writeAt(2, 1, `${theme.title}sshx${colors.reset} ${theme.muted}hosts${colors.reset} ${searchLabel}`);
111
+ const count = `${list.length}/${this.hosts.length}`;
112
+ const right = `${theme.muted}${this.sortMode} ${count}${colors.reset}`;
113
+ screen.writeAt(Math.max(1, screen.cols - count.length - this.sortMode.length - 4), 1, right);
114
+ const layout = computeTableLayout(screen.cols, this.hosts.length > 0 ? this.hosts : list);
115
+ const sep = ' '.repeat(layout.gap);
116
+ const headerParts = [
117
+ padClip('NAME', layout.name),
118
+ padClip('DESTINATION', layout.dest),
119
+ padClip('AUTH', layout.auth)
120
+ ];
121
+ if (layout.tags > 0) {
122
+ headerParts.push(padClip('TAGS', layout.tags));
123
+ }
124
+ if (layout.notes !== undefined) {
125
+ headerParts.push(padClip('NOTES', layout.notes));
126
+ }
127
+ headerParts.push(padClip('LAST', layout.last));
128
+ const header = `${theme.muted}${headerParts.join(sep)}${colors.reset}`;
129
+ screen.writeAt(2, headerRow, header);
130
+ if (list.length === 0) {
131
+ const empty = this.hosts.length === 0
132
+ ? "No hosts yet. Press 'a' to add one, 'i' to import ~/.ssh/config."
133
+ : `No hosts match "${query}".`;
134
+ screen.writeAt(2, listTop + 1, `${theme.muted}${empty}${colors.reset}`);
135
+ }
136
+ else {
137
+ const slice = list.slice(this.scrollOffset, this.scrollOffset + visibleRows);
138
+ slice.forEach((host, i) => {
139
+ const absolute = this.scrollOffset + i;
140
+ const selected = absolute === this.selectedIndex;
141
+ const latency = this.latencyMap.get(host.id);
142
+ const dest = `${host.username}@${host.host}:${host.port}`;
143
+ const auth = authLabel(host);
144
+ const tags = (host.favorite ? '★ ' : '') + (host.tags || []).join(',');
145
+ const last = latency !== undefined
146
+ ? `${latency}ms`
147
+ : host.lastConnected
148
+ ? new Date(host.lastConnected).toLocaleDateString()
149
+ : '-';
150
+ const lineParts = [
151
+ padClip(host.name, layout.name),
152
+ padClip(dest, layout.dest),
153
+ padClip(auth, layout.auth)
154
+ ];
155
+ if (layout.tags > 0) {
156
+ lineParts.push(padClip(tags, layout.tags));
157
+ }
158
+ if (layout.notes !== undefined) {
159
+ const noteText = host.notes || (host.proxyJump ? `via ${host.proxyJump}` : '');
160
+ lineParts.push(padClip(noteText, layout.notes));
161
+ }
162
+ lineParts.push(padClip(last, layout.last));
163
+ const line = lineParts.join(sep);
164
+ const row = listTop + i;
165
+ if (selected) {
166
+ const selectedWidth = Math.max(10, screen.cols - 1);
167
+ screen.writeAt(1, row, `${theme.accentBg}${theme.selectedFg}${padClip(' ' + line, selectedWidth)}${colors.reset}`);
168
+ }
169
+ else {
170
+ screen.writeAt(2, row, line);
171
+ }
172
+ });
173
+ }
174
+ const statusText = this.statusMessage
175
+ ? this.statusMessage
176
+ : '↑↓/jk move enter connect a add e edit d delete t ping i import ctrl-r reload esc quit';
177
+ const statusColor = this.statusMessage ? theme.warn : theme.muted;
178
+ const footerWidth = Math.max(10, screen.cols - 2);
179
+ screen.writeAt(2, footerRow, `${statusColor}${padClip(statusText, footerWidth)}${colors.reset}`);
180
+ }
181
+ async testSelectedLatency() {
182
+ const selected = this.getSelectedHost();
183
+ if (!selected)
184
+ return;
185
+ this.statusMessage = `ping ${selected.name}...`;
186
+ const res = await SSHConnection.testLatency(selected);
187
+ if (res.success) {
188
+ this.latencyMap.set(selected.id, res.latencyMs);
189
+ this.statusMessage = `${selected.name} ${res.latencyMs}ms`;
190
+ }
191
+ else {
192
+ this.statusMessage = `${selected.name} failed: ${res.error}`;
193
+ }
194
+ }
195
+ }
196
+ function authLabel(host) {
197
+ if (host.authType === 'password')
198
+ return host.password ? 'password*' : 'password';
199
+ if (host.authType === 'agent')
200
+ return 'agent';
201
+ if (host.privateKeyPath) {
202
+ const base = host.privateKeyPath.split('/').pop() || 'key';
203
+ return `key:${base}`;
204
+ }
205
+ return host.authType || 'key';
206
+ }
207
+ export function computeTableLayout(screenCols, hosts) {
208
+ const usable = Math.max(30, screenCols - 4);
209
+ let maxName = 4; // 'NAME'
210
+ let maxDest = 11; // 'DESTINATION'
211
+ let maxAuth = 4; // 'AUTH'
212
+ let maxTags = 4; // 'TAGS'
213
+ let maxNotes = 5; // 'NOTES'
214
+ let hasNotes = false;
215
+ for (const h of hosts) {
216
+ const nw = stringWidth(h.name);
217
+ if (nw > maxName)
218
+ maxName = nw;
219
+ const dw = stringWidth(`${h.username}@${h.host}:${h.port}`);
220
+ if (dw > maxDest)
221
+ maxDest = dw;
222
+ const aw = stringWidth(authLabel(h));
223
+ if (aw > maxAuth)
224
+ maxAuth = aw;
225
+ const tw = stringWidth((h.favorite ? '★ ' : '') + (h.tags || []).join(','));
226
+ if (tw > maxTags)
227
+ maxTags = tw;
228
+ const noteText = h.notes || (h.proxyJump ? `via ${h.proxyJump}` : '');
229
+ if (noteText && noteText.trim()) {
230
+ hasNotes = true;
231
+ const noteW = stringWidth(noteText.trim());
232
+ if (noteW > maxNotes)
233
+ maxNotes = noteW;
234
+ }
235
+ }
236
+ // Base sizing based on content with breathing room
237
+ let name = Math.max(14, Math.min(26, maxName + 1));
238
+ let dest = Math.max(20, Math.min(32, maxDest + 1));
239
+ let auth = Math.max(12, Math.min(22, maxAuth + 1));
240
+ let tags = Math.max(10, Math.min(28, maxTags + 1));
241
+ let last = 12;
242
+ let gap = usable >= 70 ? 2 : 1;
243
+ // Check if wide screen can fit NOTES column
244
+ const baseWithoutNotes = name + dest + auth + tags + last + 4 * gap;
245
+ let notes = undefined;
246
+ if (hasNotes && usable >= 110 && usable >= baseWithoutNotes + 14 + gap) {
247
+ const availableForNotes = usable - baseWithoutNotes - gap;
248
+ notes = Math.max(12, Math.min(Math.min(34, maxNotes + 1), availableForNotes));
249
+ }
250
+ let totalWidth = name + dest + auth + tags + (notes !== undefined ? notes + gap : 0) + last + 4 * gap;
251
+ // On tight screens, gracefully compress or drop columns
252
+ if (totalWidth > usable) {
253
+ gap = 1;
254
+ totalWidth = name + dest + auth + tags + (notes !== undefined ? notes + gap : 0) + last + 4 * gap;
255
+ if (totalWidth > usable && notes !== undefined) {
256
+ notes = undefined;
257
+ totalWidth = name + dest + auth + tags + last + 4 * gap;
258
+ }
259
+ if (totalWidth > usable && usable < 65) {
260
+ tags = 0;
261
+ totalWidth = name + dest + auth + last + 3 * gap;
262
+ }
263
+ if (totalWidth > usable) {
264
+ const excess = totalWidth - usable;
265
+ dest = Math.max(14, dest - Math.ceil(excess * 0.6));
266
+ name = Math.max(10, name - Math.floor(excess * 0.4));
267
+ totalWidth = name + dest + auth + (tags > 0 ? tags + gap : 0) + last + (tags > 0 ? 4 : 3) * gap;
268
+ }
269
+ }
270
+ return { name, dest, auth, tags, notes, last, gap, totalWidth };
271
+ }
272
+ //# sourceMappingURL=hosts.js.map