archivo del paquete→ .shtukbase/packages/tui/actions/open.ts
actions/open.ts
24 líneas, 1.1 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // shtuk run tui open [address]: opens the terminal front on this project (and on a page, when an address is given).
- // Without a terminal it says so in one line and exits 2 instead of hanging.
- import { spawnSync } from 'node:child_process';
- import { needBin, reachNode, splitArgs } from '../lib/tui.ts';
- import { address } from './shot.ts';
- const root = process.cwd();
- const { free, ownNode } = splitArgs(process.argv.slice(2));
- const addr = address(free[0]);
- if (!process.stdin.isTTY || !process.stdout.isTTY) {
- console.log(`tui open: a terminal is needed (input or output is not a terminal now); one screen without a terminal: shtuk run tui shot screen${addr ? ' ' + addr : ''}`);
- process.exit(2);
- }
- const bin = needBin(root);
- const node = await reachNode(bin, root, { ownNode });
- if (typeof node === 'string') {
- console.log(`tui: ${node}`);
- process.exit(2);
- }
- const args = [...bin.prefix, ...(bin.prefix.length ? [] : ['browse']), '--space', root];
- if (addr) args.push(addr);
- const r = spawnSync(bin.path, args, { cwd: root, stdio: 'inherit', env: { ...process.env, ...node.env } });
- node.stop();
- process.exit(r.status ?? 1);