rucan 0.1.2 → 0.1.3
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 +2 -0
- package/agents/darwin-arm64/rucan-agent +0 -0
- package/agents/darwin-x64/rucan-agent +0 -0
- package/agents/linux-arm64/rucan-agent +0 -0
- package/agents/linux-x64/rucan-agent +0 -0
- package/agents/manifest.json +5 -5
- package/dist/release/restart.js +45 -0
- package/dist/release/updates.js +8 -6
- package/dist/terminal/chrome.js +103 -0
- package/dist/terminal/input.js +4 -0
- package/dist/terminal/interactive.js +113 -83
- package/dist/terminal/palette.js +67 -0
- package/dist/terminal/screen.js +10 -61
- package/dist/terminal/sidebar-actions.js +18 -0
- package/dist/terminal/ssh-shell.js +29 -0
- package/dist/terminal/view.js +18 -12
- package/dist/terminal/workspace-screen.js +92 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,8 @@ workspaces:
|
|
|
30
30
|
|
|
31
31
|
The numbered workspace list contains running sessions. When the selected session exits, Rucan opens the next running session. If the list is empty, use Ctrl+G, then N to open a new workspace.
|
|
32
32
|
|
|
33
|
+
Press Alt+Space to search Rucan commands, or choose Space in the workspace menu. Use the sidebar buttons to open a new workspace or start an interactive SSH connection. The SSH button accepts an IP address, an OpenSSH alias, or `user@host` and runs OpenSSH on the current workspace host. OpenSSH verifies host keys and handles authentication in the terminal tab.
|
|
34
|
+
|
|
33
35
|
Inside a managed shell, run `rucan` to see session commands. Use `npx rucan@latest` if you run Rucan through npm without a global installation.
|
|
34
36
|
|
|
35
37
|
`pnpm dev config` validates the configuration and prints its path. The npm package installs the `rucan` command. After the first release:
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/agents/manifest.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.3",
|
|
3
3
|
"platforms": {
|
|
4
|
-
"linux-x64": "
|
|
5
|
-
"linux-arm64": "
|
|
6
|
-
"darwin-x64": "
|
|
7
|
-
"darwin-arm64": "
|
|
4
|
+
"linux-x64": "d93b044e6f537f96272692e885e9aef05fae6fd1b910453b1b0aebf940fdd09d",
|
|
5
|
+
"linux-arm64": "396da36d4c9723e8675ff5254324ee2fcb808224bab48cb2009a5e437347e768",
|
|
6
|
+
"darwin-x64": "46dce9a3c1c8458f980deb71fcb1b4b58634d0113ac843e86011e6a0b09a2235",
|
|
7
|
+
"darwin-arm64": "b14f9d445ec5dbd91f4f74100eb196dec0134adc7ea07885c245231309db4255"
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { realpath } from "node:fs/promises";
|
|
3
|
+
import { basename, dirname } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { installUpdate, registry } from "./updates.js";
|
|
6
|
+
import { compareVersions, stableVersion, version } from "./version.js";
|
|
7
|
+
export async function restartAfterUpdate(target, host, session) {
|
|
8
|
+
if (!stableVersion(target) || compareVersions(target, version) <= 0)
|
|
9
|
+
throw new Error("Expected a newer stable version");
|
|
10
|
+
const folder = await realpath(fileURLToPath(new URL("../../", import.meta.url)));
|
|
11
|
+
const modules = dirname(folder);
|
|
12
|
+
const fromNpx = basename(modules) === "node_modules" &&
|
|
13
|
+
basename(dirname(dirname(modules))) === "_npx";
|
|
14
|
+
const open = host ? ["remote", "open", host] : [];
|
|
15
|
+
let command = process.execPath;
|
|
16
|
+
let args;
|
|
17
|
+
if (fromNpx) {
|
|
18
|
+
command = "npm";
|
|
19
|
+
args = [
|
|
20
|
+
"exec",
|
|
21
|
+
"--yes",
|
|
22
|
+
"--prefer-online",
|
|
23
|
+
"--ignore-scripts",
|
|
24
|
+
`--registry=${registry}`,
|
|
25
|
+
`--package=rucan@${target}`,
|
|
26
|
+
"--",
|
|
27
|
+
"rucan",
|
|
28
|
+
...open,
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
args = [await installUpdate(target), ...open];
|
|
33
|
+
}
|
|
34
|
+
const env = { ...process.env, RUCAN_RESUME_SESSION: session };
|
|
35
|
+
await new Promise((resolve, reject) => {
|
|
36
|
+
const child = spawn(command, args, { env, stdio: "inherit" });
|
|
37
|
+
child.once("error", reject);
|
|
38
|
+
child.once("exit", (code, signal) => {
|
|
39
|
+
if (code === 0)
|
|
40
|
+
resolve();
|
|
41
|
+
else
|
|
42
|
+
reject(new Error(`Updated Rucan exited with ${signal ?? code}`));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
package/dist/release/updates.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isAbsolute, join } from "node:path";
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { promisify } from "node:util";
|
|
8
8
|
import { compareVersions, stableVersion, version } from "./version.js";
|
|
9
|
-
const registry = "https://registry.npmjs.org";
|
|
9
|
+
export const registry = "https://registry.npmjs.org";
|
|
10
10
|
const ttl = 6 * 60 * 60 * 1000;
|
|
11
11
|
function directory() {
|
|
12
12
|
const configured = process.env.XDG_CACHE_HOME;
|
|
@@ -105,9 +105,9 @@ async function installMethod() {
|
|
|
105
105
|
maxBuffer: 16384,
|
|
106
106
|
timeout: 2000,
|
|
107
107
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
? manager
|
|
108
|
+
const root = stdout.trim();
|
|
109
|
+
return (await realpath(join(root, "rucan"))) === packageDirectory
|
|
110
|
+
? { manager, root }
|
|
111
111
|
: undefined;
|
|
112
112
|
}
|
|
113
113
|
catch {
|
|
@@ -122,15 +122,16 @@ export async function installUpdate(target) {
|
|
|
122
122
|
const method = await installMethod();
|
|
123
123
|
if (!method)
|
|
124
124
|
throw new Error("This installation is managed externally. Install the update using the original installation method.");
|
|
125
|
+
const { manager, root } = method;
|
|
125
126
|
const args = [
|
|
126
|
-
|
|
127
|
+
manager === "pnpm" ? "add" : "install",
|
|
127
128
|
"--global",
|
|
128
129
|
"--ignore-scripts",
|
|
129
130
|
`--registry=${registry}`,
|
|
130
131
|
`rucan@${target}`,
|
|
131
132
|
];
|
|
132
133
|
await new Promise((resolve, reject) => {
|
|
133
|
-
const child = spawn(
|
|
134
|
+
const child = spawn(manager, args, { stdio: "inherit" });
|
|
134
135
|
child.once("error", reject);
|
|
135
136
|
child.once("exit", (code) => {
|
|
136
137
|
if (code === 0)
|
|
@@ -139,4 +140,5 @@ export async function installUpdate(target) {
|
|
|
139
140
|
reject(new Error(`Update exited with status ${code}`));
|
|
140
141
|
});
|
|
141
142
|
});
|
|
143
|
+
return join(root, "rucan", "dist", "main.js");
|
|
142
144
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import stringWidth from "string-width";
|
|
2
|
+
import { version } from "../release/version.js";
|
|
3
|
+
export const reset = "\x1b[0m";
|
|
4
|
+
const bar = "\x1b[38;5;252;48;5;235m";
|
|
5
|
+
const brand = "\x1b[1;38;5;17;48;5;87m";
|
|
6
|
+
const tab = "\x1b[1;38;5;231;48;5;61m";
|
|
7
|
+
const sidebar = "\x1b[38;5;250;48;5;234m";
|
|
8
|
+
const section = "\x1b[1;38;5;117;48;5;234m";
|
|
9
|
+
const edge = "\x1b[38;5;67;48;5;234m";
|
|
10
|
+
const good = "\x1b[38;5;120;48;5;235m";
|
|
11
|
+
const warning = "\x1b[38;5;221;48;5;235m";
|
|
12
|
+
const action = "\x1b[1;38;5;153m";
|
|
13
|
+
const button = "\x1b[1;38;5;117;48;5;236m";
|
|
14
|
+
const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
15
|
+
export function fit(text, width) {
|
|
16
|
+
if (width <= 0)
|
|
17
|
+
return "";
|
|
18
|
+
const safe = text.replace(/[\p{Cc}\p{Bidi_Control}]/gu, "");
|
|
19
|
+
if (stringWidth(safe) <= width)
|
|
20
|
+
return safe;
|
|
21
|
+
let result = "";
|
|
22
|
+
let used = 0;
|
|
23
|
+
for (const { segment } of segmenter.segment(safe)) {
|
|
24
|
+
used += stringWidth(segment);
|
|
25
|
+
if (used > width)
|
|
26
|
+
break;
|
|
27
|
+
result += segment;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function fill(text, width) {
|
|
32
|
+
return text + " ".repeat(Math.max(0, width - stringWidth(text)));
|
|
33
|
+
}
|
|
34
|
+
export function renderHeader(header, width) {
|
|
35
|
+
if (typeof header === "string")
|
|
36
|
+
return tab + fill(fit(` ${header}`, width), width) + reset;
|
|
37
|
+
const logo = fit(` rucan v${version} `, width);
|
|
38
|
+
const remaining = width - stringWidth(logo);
|
|
39
|
+
if (remaining < 3)
|
|
40
|
+
return brand + fill(logo, width) + reset;
|
|
41
|
+
const label = fit(` ▰ ${header.tab} `, Math.min(remaining - 1, Math.max(12, Math.floor(width * 0.45))));
|
|
42
|
+
const statusWidth = remaining - stringWidth(label) - 1;
|
|
43
|
+
const status = fit(` ● ${header.status}`, statusWidth);
|
|
44
|
+
return (brand +
|
|
45
|
+
logo +
|
|
46
|
+
reset +
|
|
47
|
+
bar +
|
|
48
|
+
" " +
|
|
49
|
+
tab +
|
|
50
|
+
label +
|
|
51
|
+
reset +
|
|
52
|
+
(header.healthy ? good : warning) +
|
|
53
|
+
fill(status, statusWidth) +
|
|
54
|
+
reset);
|
|
55
|
+
}
|
|
56
|
+
export function renderSidebar(text, width, heading) {
|
|
57
|
+
if (width <= 0)
|
|
58
|
+
return "";
|
|
59
|
+
const label = fit(text, width - 1);
|
|
60
|
+
const style = heading || label === "EXPLORER"
|
|
61
|
+
? section
|
|
62
|
+
: label.startsWith("+ ") || label.startsWith("↗ ")
|
|
63
|
+
? button
|
|
64
|
+
: label.startsWith("›")
|
|
65
|
+
? tab
|
|
66
|
+
: sidebar;
|
|
67
|
+
return style + fill(label, width - 1) + reset + edge + "│" + reset;
|
|
68
|
+
}
|
|
69
|
+
export function renderPaletteLine(text, width, row) {
|
|
70
|
+
const cardWidth = Math.min(54, width - 2);
|
|
71
|
+
if (cardWidth < 4)
|
|
72
|
+
return "";
|
|
73
|
+
const style = row === 0 ? tab : row === 1 ? button : text.startsWith("›") ? tab : bar;
|
|
74
|
+
return (" ".repeat(Math.floor((width - cardWidth) / 2)) +
|
|
75
|
+
style +
|
|
76
|
+
fill(fit(` ${text}`, cardWidth), cardWidth) +
|
|
77
|
+
reset);
|
|
78
|
+
}
|
|
79
|
+
export function renderPanelLine(text, width, row) {
|
|
80
|
+
const label = fit(text, width - 2);
|
|
81
|
+
if (!label)
|
|
82
|
+
return "";
|
|
83
|
+
return row === 0 && width >= 5
|
|
84
|
+
? ` ${action}◆ ${fit(label, width - 4)}${reset}`
|
|
85
|
+
: ` ${label}`;
|
|
86
|
+
}
|
|
87
|
+
export function renderFooter(footer, width) {
|
|
88
|
+
const badge = fit(` v${version} `, width);
|
|
89
|
+
const bodyWidth = width - stringWidth(badge);
|
|
90
|
+
const [first = "", ...rest] = footer.split(" · ");
|
|
91
|
+
const lead = fit(` ${first} `, bodyWidth);
|
|
92
|
+
const remaining = bodyWidth - stringWidth(lead);
|
|
93
|
+
const hints = rest.length ? fit(` ${rest.join(" · ")}`, remaining) : "";
|
|
94
|
+
return (tab +
|
|
95
|
+
lead +
|
|
96
|
+
reset +
|
|
97
|
+
bar +
|
|
98
|
+
fill(hints, remaining) +
|
|
99
|
+
reset +
|
|
100
|
+
brand +
|
|
101
|
+
badge +
|
|
102
|
+
reset);
|
|
103
|
+
}
|
package/dist/terminal/input.js
CHANGED
|
@@ -52,6 +52,10 @@ export class InputRouter {
|
|
|
52
52
|
if (byte === this.#prefix && !this.#paste) {
|
|
53
53
|
event = { type: "prefix" };
|
|
54
54
|
}
|
|
55
|
+
else if (byte === 0x1b && input[index + 1] === 0x20 && !this.#paste) {
|
|
56
|
+
event = { type: "palette" };
|
|
57
|
+
length = 2;
|
|
58
|
+
}
|
|
55
59
|
else if (byte === 0x1b) {
|
|
56
60
|
const remainder = input.subarray(index);
|
|
57
61
|
const marker = this.#paste ? pasteEnd : pasteStart;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import { availableUpdate,
|
|
3
|
-
import {
|
|
2
|
+
import { availableUpdate, skipUpdate } from "../release/updates.js";
|
|
3
|
+
import { restartAfterUpdate } from "../release/restart.js";
|
|
4
4
|
import { Explorer } from "../explorer/explorer.js";
|
|
5
5
|
import { setTimeout as delay } from "node:timers/promises";
|
|
6
6
|
import { connectRemoteAgent } from "../agent/ssh.js";
|
|
7
7
|
import { connectLocalAgent } from "../agent/local.js";
|
|
8
8
|
import { mountRawInput } from "./raw-input.js";
|
|
9
|
-
import {
|
|
9
|
+
import { CommandPalette } from "./palette.js";
|
|
10
|
+
import { sidebarActionAt } from "./sidebar-actions.js";
|
|
11
|
+
import { openSshShell } from "./ssh-shell.js";
|
|
12
|
+
import { workspaceScreen } from "./workspace-screen.js";
|
|
10
13
|
import { listTmux, openTmux } from "./tmux.js";
|
|
11
14
|
import { TerminalWatch } from "./watch.js";
|
|
12
15
|
import { watchWorkspaceList } from "./workspace-refresh.js";
|
|
13
16
|
import { terminalMouse } from "./mouse.js";
|
|
14
17
|
import { geometry, Screen } from "./screen.js";
|
|
15
18
|
import { decodeSnapshot } from "./snapshot.js";
|
|
16
|
-
import { createWorkspace, decodeWorkspace, listWorkspaces, reconcileWorkspaces,
|
|
19
|
+
import { createWorkspace, decodeWorkspace, listWorkspaces, reconcileWorkspaces, } from "./workspaces.js";
|
|
17
20
|
export async function runInteractive(config, requested, host) {
|
|
18
21
|
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
19
22
|
throw new Error("The workspace UI requires a terminal.");
|
|
@@ -34,7 +37,7 @@ export async function runInteractive(config, requested, host) {
|
|
|
34
37
|
}
|
|
35
38
|
target = undefined;
|
|
36
39
|
if (next?.type === "update")
|
|
37
|
-
await
|
|
40
|
+
await restartAfterUpdate(next.version, alias, next.session);
|
|
38
41
|
if (next?.type === "host") {
|
|
39
42
|
currentHost = next.host;
|
|
40
43
|
prepared = next.client;
|
|
@@ -72,6 +75,8 @@ class InteractiveWorkspace {
|
|
|
72
75
|
#name = "";
|
|
73
76
|
#command = "";
|
|
74
77
|
#commandError = false;
|
|
78
|
+
#palette;
|
|
79
|
+
#sshTarget = "";
|
|
75
80
|
#tmux = [];
|
|
76
81
|
#tmuxIndex = 0;
|
|
77
82
|
#workspaces = [];
|
|
@@ -95,7 +100,8 @@ class InteractiveWorkspace {
|
|
|
95
100
|
this.#workspaces = (await listWorkspaces(this.#client)).filter(({ running }) => running);
|
|
96
101
|
const target = requested
|
|
97
102
|
? this.#workspaces.find(({ id, name }) => id === requested || name === requested)
|
|
98
|
-
: this.#workspaces.find(({
|
|
103
|
+
: (this.#workspaces.find(({ id }) => id === process.env.RUCAN_RESUME_SESSION) ?? this.#workspaces[0]);
|
|
104
|
+
delete process.env.RUCAN_RESUME_SESSION;
|
|
99
105
|
if (requested && !target)
|
|
100
106
|
throw new Error(`Unknown session ${requested}`);
|
|
101
107
|
const onResize = () => {
|
|
@@ -278,6 +284,14 @@ class InteractiveWorkspace {
|
|
|
278
284
|
}
|
|
279
285
|
}
|
|
280
286
|
async #input(event) {
|
|
287
|
+
if (event.type === "palette") {
|
|
288
|
+
if (this.#mode === "terminal" || this.#mode === "menu")
|
|
289
|
+
this.#openPalette();
|
|
290
|
+
else if (this.#mode === "palette")
|
|
291
|
+
this.#mode = "terminal";
|
|
292
|
+
this.#draw();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
281
295
|
if (event.type === "prefix") {
|
|
282
296
|
if (this.#mode === "explorer")
|
|
283
297
|
this.#explorer.leave();
|
|
@@ -294,8 +308,15 @@ class InteractiveWorkspace {
|
|
|
294
308
|
event.row >= 3 &&
|
|
295
309
|
!event.release &&
|
|
296
310
|
event.button === 0) {
|
|
311
|
+
const action = sidebarActionAt(event.row, this.#layout.rows - 2);
|
|
297
312
|
const workspace = this.#workspaces[event.row - 3];
|
|
298
|
-
if (
|
|
313
|
+
if (action) {
|
|
314
|
+
await this.#menu(action);
|
|
315
|
+
this.#draw();
|
|
316
|
+
}
|
|
317
|
+
else if (workspace &&
|
|
318
|
+
event.col === 4 &&
|
|
319
|
+
workspace.ownership === "managed")
|
|
299
320
|
await this.#pin(workspace);
|
|
300
321
|
else if (workspace)
|
|
301
322
|
await this.#select(workspace);
|
|
@@ -318,7 +339,21 @@ class InteractiveWorkspace {
|
|
|
318
339
|
return;
|
|
319
340
|
}
|
|
320
341
|
const key = event.bytes.toString("utf8");
|
|
321
|
-
if (this.#mode === "
|
|
342
|
+
if (this.#mode === "palette") {
|
|
343
|
+
if (key === "\x1b")
|
|
344
|
+
this.#mode = "terminal";
|
|
345
|
+
else {
|
|
346
|
+
const action = this.#palette?.input(key);
|
|
347
|
+
if (action) {
|
|
348
|
+
this.#mode = "menu";
|
|
349
|
+
await this.#menu(action);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
else if (this.#mode === "ssh") {
|
|
354
|
+
await this.#readSshTarget(key);
|
|
355
|
+
}
|
|
356
|
+
else if (this.#mode === "explorer") {
|
|
322
357
|
if (key === "\x1b") {
|
|
323
358
|
this.#explorer.leave();
|
|
324
359
|
this.#mode = "menu";
|
|
@@ -389,7 +424,11 @@ class InteractiveWorkspace {
|
|
|
389
424
|
else if (this.#mode === "update") {
|
|
390
425
|
if (key === "1") {
|
|
391
426
|
if (this.#update) {
|
|
392
|
-
this.#result = {
|
|
427
|
+
this.#result = {
|
|
428
|
+
type: "update",
|
|
429
|
+
version: this.#update,
|
|
430
|
+
session: this.#selected?.id,
|
|
431
|
+
};
|
|
393
432
|
this.#stop();
|
|
394
433
|
}
|
|
395
434
|
}
|
|
@@ -523,6 +562,9 @@ class InteractiveWorkspace {
|
|
|
523
562
|
if (key === "\x1b") {
|
|
524
563
|
this.#mode = "terminal";
|
|
525
564
|
}
|
|
565
|
+
else if (key === " ") {
|
|
566
|
+
this.#openPalette();
|
|
567
|
+
}
|
|
526
568
|
else if (key.startsWith("/")) {
|
|
527
569
|
this.#command = "";
|
|
528
570
|
this.#commandError = false;
|
|
@@ -543,8 +585,8 @@ class InteractiveWorkspace {
|
|
|
543
585
|
await this.#scroll(this.#layout.terminalRows);
|
|
544
586
|
this.#mode = "history";
|
|
545
587
|
}
|
|
546
|
-
else if (key === "u"
|
|
547
|
-
this.#
|
|
588
|
+
else if (key === "u") {
|
|
589
|
+
await this.#checkForUpdate();
|
|
548
590
|
}
|
|
549
591
|
else if (key === "t") {
|
|
550
592
|
const inventory = await listTmux(this.#client);
|
|
@@ -563,6 +605,10 @@ class InteractiveWorkspace {
|
|
|
563
605
|
this.#newIndex = 0;
|
|
564
606
|
this.#mode = "create";
|
|
565
607
|
}
|
|
608
|
+
else if (key === "c") {
|
|
609
|
+
this.#sshTarget = "";
|
|
610
|
+
this.#mode = "ssh";
|
|
611
|
+
}
|
|
566
612
|
else if (key === "h") {
|
|
567
613
|
this.#hosts = [
|
|
568
614
|
undefined,
|
|
@@ -590,6 +636,36 @@ class InteractiveWorkspace {
|
|
|
590
636
|
}
|
|
591
637
|
}
|
|
592
638
|
}
|
|
639
|
+
#openPalette() {
|
|
640
|
+
this.#palette = new CommandPalette(Boolean(this.#selected), this.#update);
|
|
641
|
+
this.#mode = "palette";
|
|
642
|
+
}
|
|
643
|
+
async #checkForUpdate() {
|
|
644
|
+
if (!this.#update) {
|
|
645
|
+
this.#status = "Checking for updates…";
|
|
646
|
+
this.#draw();
|
|
647
|
+
this.#update = await availableUpdate(true);
|
|
648
|
+
}
|
|
649
|
+
if (this.#stopped)
|
|
650
|
+
return;
|
|
651
|
+
this.#status = this.#update ? "" : "No newer stable release found";
|
|
652
|
+
if (this.#update)
|
|
653
|
+
this.#mode = "update";
|
|
654
|
+
}
|
|
655
|
+
async #readSshTarget(key) {
|
|
656
|
+
if (key === "\x1b")
|
|
657
|
+
this.#mode = "menu";
|
|
658
|
+
else if (key === "\x7f")
|
|
659
|
+
this.#sshTarget = this.#sshTarget.slice(0, -1);
|
|
660
|
+
else if (key === "\r") {
|
|
661
|
+
const workspace = await openSshShell(this.#client, this.#config, this.#layout, this.#sshTarget);
|
|
662
|
+
this.#workspaces.push(workspace);
|
|
663
|
+
this.#mode = "terminal";
|
|
664
|
+
await this.#select(workspace);
|
|
665
|
+
}
|
|
666
|
+
else if (/^[a-zA-Z0-9_.:@-]+$/u.test(key))
|
|
667
|
+
this.#sshTarget = (this.#sshTarget + key).slice(0, 128);
|
|
668
|
+
}
|
|
593
669
|
async #readCommand(input) {
|
|
594
670
|
if (input === "\x1b") {
|
|
595
671
|
this.#mode = "menu";
|
|
@@ -635,78 +711,32 @@ class InteractiveWorkspace {
|
|
|
635
711
|
#draw() {
|
|
636
712
|
if (this.#stopped)
|
|
637
713
|
return;
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
:
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
: undefined;
|
|
646
|
-
if (this.#mode === "update" && this.#update) {
|
|
647
|
-
this.#screen.draw({
|
|
648
|
-
layout: this.#layout,
|
|
649
|
-
header: `Update available: v${version} → v${this.#update}`,
|
|
650
|
-
footer,
|
|
651
|
-
sidebarLines: [],
|
|
652
|
-
snapshot: undefined,
|
|
653
|
-
showCursor: false,
|
|
654
|
-
});
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
const running = this.#snapshot?.state === "running";
|
|
658
|
-
this.#screen.draw({
|
|
714
|
+
const rows = this.#layout.rows - 2;
|
|
715
|
+
this.#screen.draw(workspaceScreen({
|
|
716
|
+
config: this.#config,
|
|
717
|
+
mode: this.#mode,
|
|
718
|
+
host: this.#host,
|
|
719
|
+
status: this.#status,
|
|
720
|
+
update: this.#update,
|
|
659
721
|
layout: this.#layout,
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
(this.#mode === "tmux"
|
|
680
|
-
? selectionLines("TMUX SESSIONS", this.#tmux.map((entry) => entry.name), this.#tmuxIndex, this.#layout.rows - 2)
|
|
681
|
-
: undefined) ??
|
|
682
|
-
explorer?.sidebar ??
|
|
683
|
-
workspaceLabels(this.#config, this.#workspaces, selected?.id),
|
|
684
|
-
...(explorer
|
|
685
|
-
? { contentLines: explorer.content }
|
|
686
|
-
: this.#mode === "menu"
|
|
687
|
-
? { contentLines: menuFor(this.#update) }
|
|
688
|
-
: this.#mode === "exit"
|
|
689
|
-
? { contentLines: exitLines(this.#host) }
|
|
690
|
-
: this.#mode === "command"
|
|
691
|
-
? {
|
|
692
|
-
contentLines: [
|
|
693
|
-
`Command /${this.#command}▏`,
|
|
694
|
-
"",
|
|
695
|
-
this.#commandError
|
|
696
|
-
? "Unknown command. Try /exit."
|
|
697
|
-
: "/exit Quit Rucan",
|
|
698
|
-
],
|
|
699
|
-
}
|
|
700
|
-
: {}),
|
|
701
|
-
snapshot: explorer ||
|
|
702
|
-
this.#mode === "menu" ||
|
|
703
|
-
this.#mode === "exit" ||
|
|
704
|
-
this.#mode === "command"
|
|
705
|
-
? undefined
|
|
706
|
-
: this.#mode === "history"
|
|
707
|
-
? this.#history
|
|
708
|
-
: this.#snapshot,
|
|
709
|
-
showCursor: this.#mode === "terminal" && this.#controlsInput,
|
|
710
|
-
});
|
|
722
|
+
selected: this.#selected,
|
|
723
|
+
workspaces: this.#workspaces,
|
|
724
|
+
snapshot: this.#snapshot,
|
|
725
|
+
history: this.#history,
|
|
726
|
+
controlsInput: this.#controlsInput,
|
|
727
|
+
explorer: this.#mode === "explorer" ? this.#explorer.layout(rows) : undefined,
|
|
728
|
+
newEntries: this.#newEntries,
|
|
729
|
+
newIndex: this.#newIndex,
|
|
730
|
+
hosts: this.#hosts,
|
|
731
|
+
hostIndex: this.#hostIndex,
|
|
732
|
+
tmux: this.#tmux,
|
|
733
|
+
tmuxIndex: this.#tmuxIndex,
|
|
734
|
+
name: this.#name,
|
|
735
|
+
offset: this.#offset,
|
|
736
|
+
command: this.#command,
|
|
737
|
+
commandError: this.#commandError,
|
|
738
|
+
sshTarget: this.#sshTarget,
|
|
739
|
+
paletteLines: this.#mode === "palette" ? this.#palette?.lines(rows) : undefined,
|
|
740
|
+
}));
|
|
711
741
|
}
|
|
712
742
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const actions = [
|
|
2
|
+
{ key: "n", label: "New workspace" },
|
|
3
|
+
{ key: "c", label: "SSH connect" },
|
|
4
|
+
{ key: "e", label: "Browse files" },
|
|
5
|
+
{ key: "h", label: "Switch host" },
|
|
6
|
+
{ key: "t", label: "Manage tmux sessions" },
|
|
7
|
+
{ key: "p", label: "Pin workspace", requiresSession: true },
|
|
8
|
+
{ key: "s", label: "View terminal history", requiresSession: true },
|
|
9
|
+
{ key: "r", label: "Rename workspace", requiresSession: true },
|
|
10
|
+
{ key: "d", label: "Close UI and keep sessions" },
|
|
11
|
+
{ key: "q", label: "Quit Rucan" },
|
|
12
|
+
];
|
|
13
|
+
export class CommandPalette {
|
|
14
|
+
hasSession;
|
|
15
|
+
update;
|
|
16
|
+
#query = "";
|
|
17
|
+
#index = 0;
|
|
18
|
+
constructor(hasSession, update) {
|
|
19
|
+
this.hasSession = hasSession;
|
|
20
|
+
this.update = update;
|
|
21
|
+
}
|
|
22
|
+
#matches() {
|
|
23
|
+
const available = [
|
|
24
|
+
...actions,
|
|
25
|
+
{
|
|
26
|
+
key: "u",
|
|
27
|
+
label: this.update
|
|
28
|
+
? `Review update to v${this.update}`
|
|
29
|
+
: "Check for updates",
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
const terms = this.#query.trim().toLowerCase().split(/\s+/u);
|
|
33
|
+
return available.filter(({ label, requiresSession }) => (!requiresSession || this.hasSession) &&
|
|
34
|
+
terms.every((term) => label.toLowerCase().includes(term)));
|
|
35
|
+
}
|
|
36
|
+
input(key) {
|
|
37
|
+
if (key === "\r")
|
|
38
|
+
return this.#matches()[this.#index]?.key;
|
|
39
|
+
if (key === "\x1b[A" || key === "\x1b[B") {
|
|
40
|
+
const step = key === "\x1b[A" ? -1 : 1;
|
|
41
|
+
this.#index = Math.max(0, Math.min(this.#index + step, this.#matches().length - 1));
|
|
42
|
+
}
|
|
43
|
+
else if (key === "\x7f") {
|
|
44
|
+
this.#query = [...this.#query].slice(0, -1).join("");
|
|
45
|
+
this.#index = 0;
|
|
46
|
+
}
|
|
47
|
+
else if (/^\P{Cc}+$/u.test(key)) {
|
|
48
|
+
this.#query = [...(this.#query + key)].slice(0, 64).join("");
|
|
49
|
+
this.#index = 0;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
lines(rows) {
|
|
54
|
+
const matches = this.#matches();
|
|
55
|
+
const visible = Math.max(1, Math.min(7, rows - 2));
|
|
56
|
+
const first = Math.max(0, this.#index - visible + 1);
|
|
57
|
+
return [
|
|
58
|
+
"◆ Rucan commands",
|
|
59
|
+
`⌕ ${this.#query || "Search actions"}▏`,
|
|
60
|
+
...(matches.length
|
|
61
|
+
? matches
|
|
62
|
+
.slice(first, first + visible)
|
|
63
|
+
.map(({ label }, index) => index + first === this.#index ? `› ${label}` : ` ${label}`)
|
|
64
|
+
: [" No matching actions"]),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
}
|
package/dist/terminal/screen.js
CHANGED
|
@@ -1,35 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { version } from "../release/version.js";
|
|
3
|
-
const reset = "\x1b[0m";
|
|
4
|
-
const chrome = "\x1b[1;36m";
|
|
5
|
-
const brand = "\x1b[1;30;106m";
|
|
6
|
-
const activeTab = "\x1b[1;97;44m";
|
|
7
|
-
const connected = "\x1b[32m";
|
|
8
|
-
const attention = "\x1b[33m";
|
|
9
|
-
const divider = "\x1b[2m";
|
|
1
|
+
import { fit, renderFooter, renderHeader, renderPaletteLine, renderPanelLine, renderSidebar, reset, } from "./chrome.js";
|
|
10
2
|
const hideCursor = "\x1b[?25l";
|
|
11
3
|
const move = (row, col) => `\x1b[${row};${col}H`;
|
|
12
|
-
const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
|
|
13
4
|
export function geometry(rows, cols) {
|
|
14
5
|
const sidebar = cols >= 48 ? Math.max(16, Math.floor(cols * 0.25)) : 0;
|
|
15
6
|
const terminalCols = Math.max(1, Math.min(500, cols - sidebar));
|
|
16
7
|
const terminalRows = Math.max(1, Math.min(200, rows - 2, Math.floor(12000 / terminalCols)));
|
|
17
8
|
return { rows, cols, sidebar, terminalRows, terminalCols };
|
|
18
9
|
}
|
|
19
|
-
function fit(text, width) {
|
|
20
|
-
const safe = text.replace(/[\p{Cc}\p{Bidi_Control}]/gu, "");
|
|
21
|
-
if (stringWidth(safe) <= width)
|
|
22
|
-
return safe;
|
|
23
|
-
let result = "";
|
|
24
|
-
let used = 0;
|
|
25
|
-
for (const { segment } of segmenter.segment(safe)) {
|
|
26
|
-
used += stringWidth(segment);
|
|
27
|
-
if (used > width)
|
|
28
|
-
break;
|
|
29
|
-
result += segment;
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
10
|
function sgr([flags, fg, bg]) {
|
|
34
11
|
const attributes = [0];
|
|
35
12
|
const styles = [1, 2, 3, 4, 7];
|
|
@@ -50,26 +27,6 @@ function sgr([flags, fg, bg]) {
|
|
|
50
27
|
}
|
|
51
28
|
return `\x1b[${attributes.join(";")}m`;
|
|
52
29
|
}
|
|
53
|
-
function renderHeader(header, width) {
|
|
54
|
-
if (typeof header === "string")
|
|
55
|
-
return chrome + fit(header, width) + reset;
|
|
56
|
-
const logo = fit(` rucan v${version} `, width);
|
|
57
|
-
const remaining = width - stringWidth(logo);
|
|
58
|
-
if (remaining < 3)
|
|
59
|
-
return brand + logo + reset;
|
|
60
|
-
const tab = fit(` ${header.tab} `, Math.min(remaining - 1, Math.max(12, Math.floor(width * 0.45))));
|
|
61
|
-
const status = fit(` ● ${header.status}`, remaining - stringWidth(tab) - 1);
|
|
62
|
-
return (brand +
|
|
63
|
-
logo +
|
|
64
|
-
reset +
|
|
65
|
-
" " +
|
|
66
|
-
activeTab +
|
|
67
|
-
tab +
|
|
68
|
-
reset +
|
|
69
|
-
(header.healthy ? connected : attention) +
|
|
70
|
-
status +
|
|
71
|
-
reset);
|
|
72
|
-
}
|
|
73
30
|
/** Own every write to the outer terminal while the interactive UI is mounted. */
|
|
74
31
|
export class Screen {
|
|
75
32
|
#output;
|
|
@@ -98,25 +55,17 @@ export class Screen {
|
|
|
98
55
|
const model = this.#latest;
|
|
99
56
|
if (!model)
|
|
100
57
|
return;
|
|
101
|
-
const { layout, header, footer, sidebarLines, snapshot, showCursor, contentLines, } = model;
|
|
58
|
+
const { layout, header, footer, sidebarLines, snapshot, showCursor, contentLines, paletteLines, } = model;
|
|
102
59
|
const lines = [renderHeader(header, layout.cols)];
|
|
60
|
+
const paletteTop = Math.max(0, Math.floor((layout.rows - 2 - (paletteLines?.length ?? 0)) / 3));
|
|
103
61
|
for (let row = 0; row < layout.rows - 2; row++) {
|
|
104
|
-
|
|
105
|
-
let line = layout.sidebar > 0
|
|
106
|
-
? (row === 0 || sidebar.startsWith("›")
|
|
107
|
-
? chrome + sidebar + reset
|
|
108
|
-
: sidebar) +
|
|
109
|
-
" ".repeat(Math.max(0, layout.sidebar - 1 - stringWidth(sidebar))) +
|
|
110
|
-
divider +
|
|
111
|
-
"│" +
|
|
112
|
-
reset
|
|
113
|
-
: "";
|
|
62
|
+
let line = renderSidebar(sidebarLines[row] ?? "", layout.sidebar, row === 0);
|
|
114
63
|
let col = layout.sidebar;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
64
|
+
const paletteLine = paletteLines?.[row - paletteTop];
|
|
65
|
+
if (paletteLine)
|
|
66
|
+
line += renderPaletteLine(paletteLine, layout.cols - col, row - paletteTop);
|
|
67
|
+
else if (contentLines)
|
|
68
|
+
line += renderPanelLine(contentLines[row] ?? "", layout.cols - col, row);
|
|
120
69
|
for (const [width, text, style] of snapshot?.grid.lines[row] ?? []) {
|
|
121
70
|
if (col >= layout.cols)
|
|
122
71
|
break;
|
|
@@ -128,7 +77,7 @@ export class Screen {
|
|
|
128
77
|
}
|
|
129
78
|
lines.push(line + reset);
|
|
130
79
|
}
|
|
131
|
-
lines.push(
|
|
80
|
+
lines.push(renderFooter(footer, layout.cols));
|
|
132
81
|
let output = hideCursor;
|
|
133
82
|
if (this.#paintedLayout &&
|
|
134
83
|
(this.#paintedLayout.rows !== layout.rows ||
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const sidebarActions = [
|
|
2
|
+
{ key: "n", label: "+ New workspace" },
|
|
3
|
+
{ key: "c", label: "↗ SSH connect" },
|
|
4
|
+
];
|
|
5
|
+
export function workspaceSidebar(lines, rows) {
|
|
6
|
+
if (rows < sidebarActions.length + 1)
|
|
7
|
+
return [...lines];
|
|
8
|
+
const listRows = rows - sidebarActions.length;
|
|
9
|
+
return [
|
|
10
|
+
...Array.from({ length: listRows }, (_, index) => lines[index] ?? ""),
|
|
11
|
+
...sidebarActions.map(({ label }) => label),
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
export function sidebarActionAt(row, rows) {
|
|
15
|
+
if (rows < sidebarActions.length + 1)
|
|
16
|
+
return undefined;
|
|
17
|
+
return sidebarActions[row - (rows - sidebarActions.length + 2)]?.key;
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isIP } from "node:net";
|
|
2
|
+
import { decodeWorkspace } from "./workspaces.js";
|
|
3
|
+
export function validSshDestination(target) {
|
|
4
|
+
if (target.length === 0 || target.length > 255)
|
|
5
|
+
return false;
|
|
6
|
+
const parts = target.split("@");
|
|
7
|
+
if (parts.length > 2)
|
|
8
|
+
return false;
|
|
9
|
+
if (parts.length === 2 &&
|
|
10
|
+
!/^[a-zA-Z0-9_][a-zA-Z0-9_.-]*$/u.test(parts[0] ?? ""))
|
|
11
|
+
return false;
|
|
12
|
+
const host = parts.at(-1) ?? "";
|
|
13
|
+
return isIP(host) === 6 || /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/u.test(host);
|
|
14
|
+
}
|
|
15
|
+
export async function openSshShell(client, config, layout, target) {
|
|
16
|
+
if (!validSshDestination(target))
|
|
17
|
+
throw new Error("Enter an SSH host or user@host.");
|
|
18
|
+
return decodeWorkspace(await client.request({
|
|
19
|
+
type: "create",
|
|
20
|
+
name: target,
|
|
21
|
+
cwd: "~",
|
|
22
|
+
command: "ssh",
|
|
23
|
+
args: ["-o", "StrictHostKeyChecking=ask", "--", target],
|
|
24
|
+
rows: layout.terminalRows,
|
|
25
|
+
cols: layout.terminalCols,
|
|
26
|
+
persistent: config.defaults.persistence === "persistent",
|
|
27
|
+
scrollback: config.terminal.scrollback_lines,
|
|
28
|
+
}));
|
|
29
|
+
}
|
package/dist/terminal/view.js
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
export function footerFor(mode, prefix, name, scrollback) {
|
|
2
2
|
switch (mode) {
|
|
3
3
|
case "create":
|
|
4
|
-
return "↑↓ Choose workspace · Enter Open
|
|
4
|
+
return "Esc Menu · ↑↓ Choose workspace · Enter Open";
|
|
5
5
|
case "hosts":
|
|
6
|
-
return "↑↓ Select host · Enter Connect
|
|
6
|
+
return "Esc Menu · ↑↓ Select host · Enter Connect";
|
|
7
7
|
case "rename":
|
|
8
|
-
return `
|
|
8
|
+
return `Esc Menu · Enter Save · Name ${name}`;
|
|
9
9
|
case "history":
|
|
10
|
-
return `
|
|
10
|
+
return `Esc Menu · ↑↓ Scroll · History ${scrollback} lines back`;
|
|
11
11
|
case "update":
|
|
12
|
-
return "1 Update now · 2 Continue · 3 Skip this version";
|
|
12
|
+
return "Esc Terminal · 1 Update now · 2 Continue · 3 Skip this version";
|
|
13
13
|
case "tmux":
|
|
14
|
-
return "↑↓ Select · Enter Attach · N
|
|
14
|
+
return "Esc Menu · ↑↓ Select · Enter Attach · N New tmux session";
|
|
15
15
|
case "explorer":
|
|
16
|
-
return "↑↓ Select · Enter Expand/Preview · R Refresh · O Editor
|
|
16
|
+
return "Esc Menu · ↑↓ Select · Enter Expand/Preview · R Refresh · O Editor";
|
|
17
17
|
case "command":
|
|
18
|
-
return "Enter Run command
|
|
18
|
+
return "Esc Menu · Enter Run command";
|
|
19
19
|
case "exit":
|
|
20
|
-
return "Enter Keep all
|
|
20
|
+
return "Esc Menu · Enter Keep all";
|
|
21
21
|
case "menu":
|
|
22
|
-
return "
|
|
22
|
+
return "Esc Terminal · Q Quit · ↑↓ / 1–9 Switch";
|
|
23
|
+
case "palette":
|
|
24
|
+
return "Esc Terminal · ↑↓ Select · Enter Run";
|
|
25
|
+
case "ssh":
|
|
26
|
+
return "Esc Menu · Enter Connect";
|
|
23
27
|
case "terminal":
|
|
24
|
-
return `${prefix} Menu (F12) ·
|
|
28
|
+
return `${prefix} Menu (F12) · Alt+Space Search · exit Close shell`;
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
export function menuFor(update) {
|
|
28
32
|
return [
|
|
29
33
|
"Workspace actions",
|
|
34
|
+
"Space Search actions",
|
|
30
35
|
"",
|
|
31
36
|
"/exit or Q Quit Rucan",
|
|
32
37
|
"D Close UI and keep sessions",
|
|
33
38
|
"",
|
|
34
39
|
"N New workspace",
|
|
40
|
+
"C SSH connect",
|
|
35
41
|
"P Pin",
|
|
36
42
|
"H Hosts",
|
|
37
43
|
"E Files",
|
|
38
44
|
"T Tmux",
|
|
39
45
|
"S History",
|
|
40
46
|
"R Rename",
|
|
41
|
-
|
|
47
|
+
update ? `U Update to v${update}` : "U Check for updates",
|
|
42
48
|
];
|
|
43
49
|
}
|
|
44
50
|
export function selectionLines(title, entries, index, available) {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { version } from "../release/version.js";
|
|
2
|
+
import { workspaceSidebar } from "./sidebar-actions.js";
|
|
3
|
+
import { exitLines, footerFor, menuFor, selectionLines, } from "./view.js";
|
|
4
|
+
import { workspaceLabels } from "./workspaces.js";
|
|
5
|
+
export function workspaceScreen(state) {
|
|
6
|
+
const selected = state.selected;
|
|
7
|
+
const title = selected
|
|
8
|
+
? `${selected.name}${selected.persistent ? " ◆" : ""}`
|
|
9
|
+
: "No session";
|
|
10
|
+
const footer = footerFor(state.mode, state.config.terminal.prefix_key, state.name, state.offset);
|
|
11
|
+
const explorer = state.mode === "explorer" ? state.explorer : undefined;
|
|
12
|
+
if (state.mode === "update" && state.update) {
|
|
13
|
+
return {
|
|
14
|
+
layout: state.layout,
|
|
15
|
+
header: `Update available: v${version} → v${state.update}`,
|
|
16
|
+
footer,
|
|
17
|
+
sidebarLines: [],
|
|
18
|
+
snapshot: undefined,
|
|
19
|
+
showCursor: false,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const selection = (state.mode === "create"
|
|
23
|
+
? selectionLines("OPEN WORKSPACE", ["Default shell", ...state.newEntries.map(({ name }) => name)], state.newIndex, state.layout.rows - 2)
|
|
24
|
+
: undefined) ??
|
|
25
|
+
(state.mode === "hosts"
|
|
26
|
+
? selectionLines("HOSTS", state.hosts.map((host) => host ?? "Local"), state.hostIndex, state.layout.rows - 2)
|
|
27
|
+
: undefined) ??
|
|
28
|
+
(state.mode === "tmux"
|
|
29
|
+
? selectionLines("TMUX SESSIONS", state.tmux.map((entry) => entry.name), state.tmuxIndex, state.layout.rows - 2)
|
|
30
|
+
: undefined);
|
|
31
|
+
const running = state.snapshot?.state === "running";
|
|
32
|
+
return {
|
|
33
|
+
layout: state.layout,
|
|
34
|
+
header: {
|
|
35
|
+
tab: title,
|
|
36
|
+
status: state.status ||
|
|
37
|
+
(running
|
|
38
|
+
? state.host
|
|
39
|
+
? `${state.host} connected`
|
|
40
|
+
: "Local agent connected"
|
|
41
|
+
: "No active workspace"),
|
|
42
|
+
healthy: running && !state.status,
|
|
43
|
+
},
|
|
44
|
+
footer: state.update && state.mode !== "exit"
|
|
45
|
+
? `${footer} · U Review v${state.update}`
|
|
46
|
+
: footer,
|
|
47
|
+
sidebarLines: selection ??
|
|
48
|
+
explorer?.sidebar ??
|
|
49
|
+
workspaceSidebar(workspaceLabels(state.config, state.workspaces, selected?.id), state.layout.rows - 2),
|
|
50
|
+
...(selection && state.layout.sidebar === 0
|
|
51
|
+
? { contentLines: selection }
|
|
52
|
+
: explorer
|
|
53
|
+
? { contentLines: explorer.content }
|
|
54
|
+
: state.mode === "menu"
|
|
55
|
+
? { contentLines: menuFor(state.update) }
|
|
56
|
+
: state.mode === "exit"
|
|
57
|
+
? { contentLines: exitLines(state.host) }
|
|
58
|
+
: state.mode === "command"
|
|
59
|
+
? {
|
|
60
|
+
contentLines: [
|
|
61
|
+
`Command /${state.command}▏`,
|
|
62
|
+
"",
|
|
63
|
+
state.commandError
|
|
64
|
+
? "Unknown command. Try /exit."
|
|
65
|
+
: "/exit Quit Rucan",
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
: state.mode === "ssh"
|
|
69
|
+
? {
|
|
70
|
+
contentLines: [
|
|
71
|
+
"SSH connect",
|
|
72
|
+
`Host ${state.sshTarget}▏`,
|
|
73
|
+
"Enter an IP, SSH alias, or user@host.",
|
|
74
|
+
],
|
|
75
|
+
}
|
|
76
|
+
: state.mode === "palette" && state.paletteLines
|
|
77
|
+
? { paletteLines: state.paletteLines }
|
|
78
|
+
: {}),
|
|
79
|
+
snapshot: (selection && state.layout.sidebar === 0) ||
|
|
80
|
+
explorer ||
|
|
81
|
+
state.mode === "menu" ||
|
|
82
|
+
state.mode === "palette" ||
|
|
83
|
+
state.mode === "ssh" ||
|
|
84
|
+
state.mode === "exit" ||
|
|
85
|
+
state.mode === "command"
|
|
86
|
+
? undefined
|
|
87
|
+
: state.mode === "history"
|
|
88
|
+
? state.history
|
|
89
|
+
: state.snapshot,
|
|
90
|
+
showCursor: state.mode === "terminal" && state.controlsInput,
|
|
91
|
+
};
|
|
92
|
+
}
|