Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ curl -fsSL https://tode.sh/install | bash

### Usage
```
Usage: tode [path...] [options]
tode --<command>
Usage: terminal-code [path...] [options]
terminal-code --<command>

tode Open the folder in the current working directory
tode <folder> Open the specified folder
tode <file> Open the specified file
terminal-code Open the folder in the current working directory
terminal-code <folder> Open the specified folder
terminal-code <file> Open the specified file

tode is the same command.


Options:
Expand All @@ -48,6 +50,18 @@ Commands, each as the first argument:
--theme [file] Set editor theme
--enable-transparency Make the editor transparent
--disable-transparency Make the editor opaque again
--enable-local-rendering-over-ssh [--allow-peer <device>]
Renders terminal-code on your own machine when you run
it over ssh, must be enabled on both machines
--disable-local-rendering-over-ssh
Turn local rendering over ssh off on this machine
--setup-ssh [user@host]
Allow the local CLI to communicate to your remote CLI
over ssh, used with local rendering to improve UI
performance over SSH
--local-rendering-doctor
Show any issues preventing local rendering from
working correctly
--serve [path] Start code server and print its url
--skill An agent skill to assist with modifying terminal-code
--upgrade [--check] Upgrade terminal-code to the latest version
Expand All @@ -58,29 +72,40 @@ Commands, each as the first argument:

### How does it work?

terminal-code combines [terminal-browser](https://github.com/zenbu-labs/terminal-browser) (a browser in the terminal) and [code-server](https://github.com/coder/code-server) (VS Code in the browser) to bring VS Code to the terminal. You should look into these projects for more details!
terminal-code is built on top of [pixelgui](https://pixelgui.com), a library for building graphical applications in the terminal, and [code-server](https://github.com/coder/code-server). You should look into these projects for more details!



### Shortcuts

Your terminal and terminal-code will likely conflict on important shortcuts, meaning sometimes terminal-code will never even receive your key press. To resolve
shortcut conflicts you can run `tode --shortcut-setup`, and you will be placed into an interactive wizard that lets you change terminal or terminal-code shortcuts
shortcut conflicts you can run `terminal-code --shortcut-setup`, and you will be placed into an interactive wizard that lets you change terminal or terminal-code shortcuts
so they no longer conflict



### SSH

The recommended way to use terminal-code over ssh is running `tode --ssh <ssh arguments>` on your local machine.
The recommended way to use terminal-code over ssh is running `terminal-code --ssh <ssh arguments>` on your local machine.

The alternative is running `tode` directly on the machine you are shh'd into. This will work, but
The alternative is running `terminal-code` directly on the machine you are shh'd into. This will work, but
requires:
- every single frame drawn by vscode to be sent over the network
- all user input to be sent over the network before vscode can react
- misses out some [extra optimizations](https://sw.kovidgoyal.net/kitty/graphics-protocol/#local-client)

`tode --ssh` improves on this by running only the backend of vscode on the remote machine. The frontend is still running locally on your device, so vscode is able to respond to interactions ~instantly. Any network requests will get proxied over the ssh connection.
`terminal-code --ssh` improves on this by running only the backend of vscode on the remote machine. The frontend is still running locally on your device, so vscode is able to respond to interactions ~instantly. Any network requests will get proxied over the ssh connection.

### Local rendering over ssh
terminal-code includes an experimental option which works in some terminal environments that significantly improves UI performance when inside an ssh shell. You can enable this by running `terminal-code --enable-local-rendering-over-ssh` on your remote and local machine

When this mode is enabled, the remote terminal-code will ask your local terminal-code to take over rendering vscode. Normally, image data about vscode needs to transfer over the network when rendering via SSH, so this mode eliminates this large bottleneck to UI performance.

The terminal-code's need to synchronize with each other for this to work, so when enabled they will try to contact each other over a network connection.

First it will try to reach the local machine directly from the remote machine, which will work if the 2 machines are connected over tailscale. If you do not have tailscale setup you can run `terminal-code --setup-ssh <user@server>` on your local terminal-code, which allows terminal-code to open an ssh connection to your server to communicate with your remote terminal-code.

For any terminal multiplexers that wants to support this mode, you need to ensure that the programs kitty graphics commands are passed through to the local terminal un-altered. You can reference [this PR](https://github.com/zenbu-labs/terminal-browser/pull/309) for technical details

### Windows

Expand Down
41 changes: 21 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"bin": {
"terminal-code": "./dist/main.js",
"tode": "./dist/main.js"
},
"scripts": {
Expand All @@ -23,10 +24,10 @@
"vite": "^8.2.1"
},
"dependencies": {
"@zenbu-labs/pixel": "0.3.2",
"@zenbu-labs/pixel": "0.3.3",
"react": "^18.3.1"
},
"allowScripts": {
"@zenbu-labs/pixel@0.3.2": true
"@zenbu-labs/pixel@0.3.3": true
}
}
10 changes: 7 additions & 3 deletions scripts/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ APP="$ROOT/node_modules/@zenbu-labs/pixel/electron/dist/Electron.app/Contents"
HELPER="$APP/Frameworks/Electron Helper.app/Contents/MacOS/Electron Helper"
[ -x "$HELPER" ] || HELPER="$APP/MacOS/pixel"
export ELECTRON_RUN_AS_NODE=1
export TERMINAL_CODE_COMMAND="$(basename "$0")"
exec "$HELPER" "$ROOT/dist/main.js" "$@"
SHIM
;;
Expand All @@ -50,6 +51,7 @@ SHIM
#!/bin/sh
ROOT="${TODE_INSTALL_ROOT:-$HOME/.local/lib/tode}"
export ELECTRON_RUN_AS_NODE=1
export TERMINAL_CODE_COMMAND="$(basename "$0")"
exec "$ROOT/node_modules/@zenbu-labs/pixel/electron/dist/pixel" "$ROOT/dist/main.js" "$@"
SHIM
;;
Expand All @@ -64,9 +66,11 @@ mv "$STAGE" "$APP"
rm -rf "$APP.old"

mkdir -p "$BIN_HOME"
cp "$APP/bin/tode" "$BIN_HOME/tode"
chmod +x "$BIN_HOME/tode"
for NAME in terminal-code tode; do
cp "$APP/bin/tode" "$BIN_HOME/$NAME"
chmod +x "$BIN_HOME/$NAME"
done

echo "installed $VERSION"
echo " app $APP"
echo " bin $BIN_HOME/tode"
echo " bin $BIN_HOME/terminal-code (also $BIN_HOME/tode)"
23 changes: 15 additions & 8 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ case "$(uname -s)-$(uname -m)" in
Linux-x86_64|Linux-amd64) TARGET=linux-x64 ;;
Linux-aarch64|Linux-arm64) TARGET=linux-arm64 ;;
*)
echo "tode does not support $(uname -s) $(uname -m) yet" >&2
echo "terminal-code does not support $(uname -s) $(uname -m) yet" >&2
exit 1
;;
esac

ROW="$(printf '%s\n' "$PLATFORMS" | awk -v t="$TARGET" '$1 == t')"
[ -n "$ROW" ] || { echo "tode $VERSION has no build for $TARGET" >&2; exit 1; }
[ -n "$ROW" ] || { echo "terminal-code $VERSION has no build for $TARGET" >&2; exit 1; }
URL="$(printf '%s\n' "$ROW" | awk '{print $2}')"
SHA256="$(printf '%s\n' "$ROW" | awk '{print $3}')"

Expand All @@ -33,7 +33,7 @@ APP="${TODE_INSTALL_ROOT:-$LIB_HOME/tode}"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT

echo "tode $VERSION ($CHANNEL) for $TARGET"
echo "terminal-code $VERSION ($CHANNEL) for $TARGET"

TARBALL="$TMP/tode.tar.gz"
curl -fL --retry 3 --retry-delay 2 --progress-bar "$URL" -o "$TARBALL"
Expand Down Expand Up @@ -80,8 +80,15 @@ mv "$APP.new" "$APP"
rm -rf "$APP.old"

mkdir -p "$BIN_HOME"
cp "$APP/bin/tode" "$BIN_HOME/tode"
chmod +x "$BIN_HOME/tode"
for NAME in terminal-code tode; do
cp "$APP/bin/tode" "$BIN_HOME/$NAME"
chmod +x "$BIN_HOME/$NAME"
done
if [ "$(uname -s)" = Darwin ]; then
launchctl kickstart -k "gui/$(id -u)/dev.zenbu.terminal-code.local-rendering" >/dev/null 2>&1 || true
else
systemctl --user try-restart terminal-code-local-rendering.service >/dev/null 2>&1 || true
fi

# the vendored electron needs the usual chromium system libraries; say which
# ones are missing rather than failing later with a loader error
Expand All @@ -107,15 +114,15 @@ cat > "$STATE_HOME/tode/install.json" <<EOF
EOF

echo
echo "tode $VERSION -> $APP"
echo "binary $BIN_HOME/tode"
echo "terminal-code $VERSION -> $APP"
echo "binary $BIN_HOME/terminal-code (also $BIN_HOME/tode)"

# no setup questions here — the first open walks import and shortcuts itself

case ":$PATH:" in
*":$BIN_HOME:"*)
echo
echo "run tode to get started"
echo "run terminal-code to get started"
;;
*)
echo
Expand Down
2 changes: 2 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ APP="$ROOT/node_modules/@zenbu-labs/pixel/electron/dist/Electron.app/Contents"
HELPER="$APP/Frameworks/Electron Helper.app/Contents/MacOS/Electron Helper"
[ -x "$HELPER" ] || HELPER="$APP/MacOS/pixel"
export ELECTRON_RUN_AS_NODE=1
export TERMINAL_CODE_COMMAND="$(basename "$0")"
exec "$HELPER" "$ROOT/dist/main.js" "$@"
SHIM
ELECTRON_PIECE="$STAGE/node_modules/@zenbu-labs/pixel/electron/dist/Electron.app"
Expand All @@ -59,6 +60,7 @@ SHIM
#!/bin/sh
ROOT="${TODE_INSTALL_ROOT:-$HOME/.local/lib/tode}"
export ELECTRON_RUN_AS_NODE=1
export TERMINAL_CODE_COMMAND="$(basename "$0")"
exec "$ROOT/node_modules/@zenbu-labs/pixel/electron/dist/pixel" "$ROOT/dist/main.js" "$@"
SHIM
ELECTRON_PIECE="$STAGE/node_modules/@zenbu-labs/pixel/electron/dist/pixel"
Expand Down
5 changes: 3 additions & 2 deletions src/app/control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import path from "node:path";
import { INSTALL_ROOT } from "../runtime/paths";
import { DAEMON_DIR, lines } from "./protocol";
import type { Reply, Request } from "./protocol";
import { COMMAND } from "../runtime/shim";

export const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));

Expand Down Expand Up @@ -53,8 +54,8 @@ export function ask(socket: net.Socket, request: Request, timeoutMs: number): Pr
outcome();
};
const onLine = (reply: Reply) => settle(() => resolve(reply));
const onClose = () => settle(() => reject(new Error("the tode window process closed the connection")));
const timer = setTimeout(() => settle(() => reject(new Error("the tode window process did not answer"))), timeoutMs);
const onClose = () => settle(() => reject(new Error(`the ${COMMAND} window process closed the connection`)));
const timer = setTimeout(() => settle(() => reject(new Error(`the ${COMMAND} window process did not answer`))), timeoutMs);
emitter.once("line", onLine);
socket.once("close", onClose);
socket.write(`${JSON.stringify(request)}\n`);
Expand Down
11 changes: 6 additions & 5 deletions src/app/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import net from "node:net";
import path from "node:path";

import { app, ipcMain } from "@zenbu-labs/pixel/electron";
import { WebView, createRoot } from "@zenbu-labs/pixel";
import { STREAM_ENV, WebView, createRoot, terminalFromEnv } from "@zenbu-labs/pixel";
import type { Root, WebViewHandle } from "@zenbu-labs/pixel";
import { createElement } from "react";

Expand Down Expand Up @@ -118,10 +118,11 @@ function applyTransparency(on: boolean) {
}

function openWindow(request: OpenRequest, onClosed: (code: number) => void): Root {
const streamed = Boolean(request.env[STREAM_ENV]);
const root = createRoot({
name: "tode",
tty: request.tty,
sessionEnv: request.env,
name: "terminal-code",
tty: streamed ? undefined : request.tty,
sessionEnv: streamed ? { ...terminalFromEnv(request.env), ...request.env } : request.env,
onExit(code) {
if (!windows.delete(root)) return;
onClosed(code);
Expand Down Expand Up @@ -211,7 +212,7 @@ function serve() {
connection.on("close", () => root?.stop());
});
server.on("error", (error) => {
process.stderr.write(`tode window: socket error: ${error.message}\n`);
process.stderr.write(`terminal-code window: socket error: ${error.message}\n`);
app.exit(1);
});
server.listen(SOCKET);
Expand Down
Loading
Loading