forked from Blendman974/faceclaw
Terminal app: Tap host to launch a shell (alternative to app context menu)
This commit is contained in:
1 parent
b0a98f5942
commit
668e454fbb
2 files changed
+49
-12
No files matched your search
@@ -2,7 +2,8 @@
|
|||||||
* Terminal app, hosted in its own worker thread. Window model:
|
* Terminal app, hosted in its own worker thread. Window model:
|
||||||
* - "terminal:hub": the window opened from the launcher; shows the list of
|
* - "terminal:hub": the window opened from the launcher; shows the list of
|
||||||
* live g2mirror sessions across every connected host (grouped by host when
|
* live g2mirror sessions across every connected host (grouped by host when
|
||||||
* more than one is connected), and hosts the Manage Connections section
|
* more than one is connected; selecting a host's heading launches a shell
|
||||||
|
* there), and hosts the Manage Connections section
|
||||||
* where g2mirror:// connections are added, removed, and toggled.
|
* where g2mirror:// connections are added, removed, and toggled.
|
||||||
* - "terminal:view:N": opened by selecting a session in the hub; each has
|
* - "terminal:view:N": opened by selecting a session in the hub; each has
|
||||||
* its own websocket connection (the protocol allows one attached session
|
* its own websocket connection (the protocol allows one attached session
|
||||||
@@ -1047,10 +1048,7 @@ function windowMenuItems(window: TerminalWindow): MenuItem[] {
|
|||||||
label,
|
label,
|
||||||
onSelect: (ctx) => {
|
onSelect: (ctx) => {
|
||||||
ctx.stack.pop();
|
ctx.stack.pop();
|
||||||
launchAndOpenView(control, preset).catch((error) => {
|
launchFromUi(control, preset);
|
||||||
// The hub status line also shows the server's error message.
|
|
||||||
console.warn(`terminal launch ${preset} failed: ${error}`);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1180,7 +1178,10 @@ function applyHistoryReply(window: ViewWindow, reply: { start: number; oldest: n
|
|||||||
|
|
||||||
type HubItem = {
|
type HubItem = {
|
||||||
label: string;
|
label: string;
|
||||||
/** Group heading (host name): drawn differently and skipped by selection. */
|
/**
|
||||||
|
* Group heading (host name): drawn unindented and dimmer. Selectable only
|
||||||
|
* when it has an onSelect (launch a shell on that host).
|
||||||
|
*/
|
||||||
heading?: boolean;
|
heading?: boolean;
|
||||||
/** Session with recent output: an animated indicator marks the row. */
|
/** Session with recent output: an animated indicator marks the row. */
|
||||||
active?: boolean;
|
active?: boolean;
|
||||||
@@ -1210,7 +1211,7 @@ function hubMenu(window: HubWindow): Menu<HubItem> {
|
|||||||
function drawHubRow({ image, item, x, y, width, selected }: MenuDrawArgs<HubItem>): void {
|
function drawHubRow({ image, item, x, y, width, selected }: MenuDrawArgs<HubItem>): void {
|
||||||
const font = chromeFont();
|
const font = chromeFont();
|
||||||
if (item.heading) {
|
if (item.heading) {
|
||||||
image.drawText(font, x, y + HUB_ROW_TEXT_INSET, item.label, 140);
|
image.drawText(font, x, y + HUB_ROW_TEXT_INSET, item.label, selected ? 255 : 140);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Activity gutter, open-window number column, then the label, truncated
|
// Activity gutter, open-window number column, then the label, truncated
|
||||||
@@ -1282,9 +1283,14 @@ function hubSessionItems(window: HubWindow): HubItem[] {
|
|||||||
];
|
];
|
||||||
const connected = connectedControls();
|
const connected = connectedControls();
|
||||||
const multiHost = connected.length > 1;
|
const multiHost = connected.length > 1;
|
||||||
|
const canLaunch = launchPresetNames().length > 0;
|
||||||
for (const control of connected) {
|
for (const control of connected) {
|
||||||
if (multiHost) {
|
if (multiHost) {
|
||||||
items.push({ label: connectionDisplayName(control.config), heading: true });
|
items.push({
|
||||||
|
label: connectionDisplayName(control.config),
|
||||||
|
heading: true,
|
||||||
|
onSelect: canLaunch ? () => launchOnHost(window, control) : undefined,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const sessions = orderedSessions(window, control);
|
const sessions = orderedSessions(window, control);
|
||||||
for (const session of sessions) {
|
for (const session of sessions) {
|
||||||
@@ -1568,6 +1574,37 @@ function launchPresetNames(): string[] {
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A host heading in the hub was selected: launch a shell there. With a single
|
||||||
|
* launch preset it starts right away; with several, a submenu titled with the
|
||||||
|
* host's name picks which.
|
||||||
|
*/
|
||||||
|
function launchOnHost(window: HubWindow, control: ControlConnection): void {
|
||||||
|
const presets = launchPresetNames();
|
||||||
|
if (presets.length === 1) {
|
||||||
|
launchFromUi(control, presets[0]!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
windowMenu(window).open(
|
||||||
|
presets.map((preset) => ({
|
||||||
|
label: `Launch ${preset}`,
|
||||||
|
onSelect: (ctx) => {
|
||||||
|
ctx.stack.pop();
|
||||||
|
launchFromUi(control, preset);
|
||||||
|
},
|
||||||
|
})),
|
||||||
|
connectionDisplayName(control.config),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Launch started from a menu or list row; failures only get logged. */
|
||||||
|
function launchFromUi(control: ControlConnection, preset: string): void {
|
||||||
|
launchAndOpenView(control, preset).catch((error) => {
|
||||||
|
// The hub status line also shows the server's error message.
|
||||||
|
console.warn(`terminal launch ${preset} failed: ${error}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Launch a preset on a host and open a view window on the new session. */
|
/** Launch a preset on a host and open a view window on the new session. */
|
||||||
async function launchAndOpenView(control: ControlConnection, preset: string): Promise<string> {
|
async function launchAndOpenView(control: ControlConnection, preset: string): Promise<string> {
|
||||||
if (!control.client) throw new Error("Not connected to the g2mirror server.");
|
if (!control.client) throw new Error("Not connected to the g2mirror server.");
|
||||||
|
|||||||
@@ -92,10 +92,10 @@ export class WindowMenu {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Open the menu, or the shell's system menu when this window has no
|
* Open the menu, or the shell's system menu when this window has no
|
||||||
* entries. `items` overrides the window's own entries for an app that
|
* entries. `items` (and optionally `title`) override the window's own for
|
||||||
* reuses this host for another list (a per-row action menu).
|
* an app that reuses this host for another list (a per-row action menu).
|
||||||
*/
|
*/
|
||||||
open(items: MenuItem[] = this.options.items()): void {
|
open(items: MenuItem[] = this.options.items(), title: string = this.options.title()): void {
|
||||||
if (this.stack) return;
|
if (this.stack) return;
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
this.options.post({ type: "open-system-menu", windowId: this.options.windowId });
|
this.options.post({ type: "open-system-menu", windowId: this.options.windowId });
|
||||||
@@ -106,7 +106,7 @@ export class WindowMenu {
|
|||||||
handleInput: () => {},
|
handleInput: () => {},
|
||||||
};
|
};
|
||||||
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
const stack = new LayerStack(base, { ...noopLayerActions }, this.options.size, this.options.isFocused);
|
||||||
stack.push(new WindowMenuLayer(this.options.title(), items));
|
stack.push(new WindowMenuLayer(title, items));
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user