7 Commits

Author SHA1 Message Date
7367b2f778 panesync toggle <- panesync commit 2026-06-19 15:26:00 +02:00
a6a700b2c0 panesync start + panesync end = panesync toggle 2026-06-19 15:21:59 +02:00
47b2daa782 pane sync start != pane sync select 2026-06-19 15:19:12 +02:00
8bd8170270 pane sync 2026-06-19 15:15:44 +02:00
64263ee3fb standalone flag 2026-06-19 14:32:52 +02:00
f621366b0c rename action 2026-06-19 14:27:57 +02:00
77fb5e7e11 add worktree shortcut 2026-06-19 14:24:35 +02:00
6 changed files with 245 additions and 7 deletions

View File

@@ -78,6 +78,9 @@ After that, a bare `jprototerm` connects to the daemon and opens a window in the
directory. If no daemon is running, `jprototerm` falls back to a standalone in-process window
(today's behavior), so it always works.
For development testing, use `jprototerm --standalone` to skip the daemon even when one is
running.
To start the daemon automatically with your graphical session, enable the bundled **user**
service (it's a user service, not a system one, because X11 needs a display — which only
exists after you log in):
@@ -146,6 +149,9 @@ enabled = true
[scrollback]
editor_command = "vi {file}"
[worktree]
relative_worktree_path = "./.worktrees"
[env.override]
ZELLIJ_SESSION_NAME = ""
@@ -163,6 +169,10 @@ previous_tab = "ALT+SHIFT+H"
next_tab = "ALT+SHIFT+L"
open_font_selector = "ALT+T"
open_scrollback = "ALT+S"
create_worktree = "ALT+W"
pane_sync_toggle = "ALT+Y"
pane_sync_select = "SPACE"
paste = "CTRL+SHIFT+V"
```
## Defaults
@@ -178,6 +188,12 @@ open_scrollback = "ALT+S"
- `Alt+Shift+h` / `Alt+Shift+l`: previous / next tab
- `Alt+t`: open the font selector
- `Alt+s`: open the active pane scrollback in `$EDITOR`
- `Alt+w`: edit a worktree name, then run `git worktree add <relative_worktree_path>/<name>`
from the previously focused pane's working directory
- `Alt+y`: enter pane-sync selection mode, commit the selection, or stop an active pane sync
- `Space`: toggle the focused pane in the sync set while pane-sync selection mode is active
- Once committed, input typed or pasted into any synced pane is mirrored to the other synced panes
- `Ctrl+Shift+v`: paste
- Font default: `JetBrainsMono Nerd Font`
- Kitty graphics protocol parsing is enabled by default

View File

@@ -19,6 +19,9 @@ enabled = true
[scrollback]
editor_command = "vi {file}"
[worktree]
relative_worktree_path = "./.worktrees"
[env.override]
ZELLIJ_SESSION_NAME = ""
@@ -28,9 +31,16 @@ navigate_down = "ALT+J"
navigate_up = "ALT+K"
navigate_right = "ALT+L"
toggle_floating = "ALT+F"
new_floating = "ALT+SHIFT+F"
new_pane = "ALT+N"
next_floating = "ALT+F12"
promote_floating = "ALT+P"
close_pane = "ALT+X"
new_tab = "ALT+A"
previous_tab = "ALT+SHIFT+H"
next_tab = "ALT+SHIFT+L"
open_font_selector = "ALT+T"
open_scrollback = "ALT+S"
create_worktree = "ALT+W"
pane_sync_toggle = "ALT+Y"
pane_sync_select = "SPACE"
paste = "CTRL+SHIFT+V"

View File

@@ -29,6 +29,7 @@ public record AppConfig(
double windowHeight,
boolean kittyGraphics,
String scrollbackEditorCommand,
String worktreeRelativePath,
String closeSignal,
Map<String, String> envOverride,
Map<String, KeyBinding> keybindings
@@ -48,6 +49,9 @@ public record AppConfig(
"next_tab",
"open_font_selector",
"open_scrollback",
"create_worktree",
"pane_sync_toggle",
"pane_sync_select",
"paste"
);
@@ -72,6 +76,7 @@ public record AppConfig(
doubleValue(document, "window.height", defaults.windowHeight),
booleanValue(document, "kitty_graphics.enabled", defaults.kittyGraphics),
stringValue(document, "scrollback.editor_command", defaults.scrollbackEditorCommand),
stringValue(document, "worktree.relative_worktree_path", defaults.worktreeRelativePath),
closeSignalValue(document, defaults.closeSignal),
envOverride(document, defaults.envOverride),
keybindings(document, defaults)
@@ -94,6 +99,7 @@ public record AppConfig(
760.0,
true,
defaultScrollbackEditorCommand(),
"./.worktrees",
"SIGTERM",
Map.of(),
Map.ofEntries(
@@ -111,6 +117,9 @@ public record AppConfig(
Map.entry("next_tab", KeyBinding.parse("ALT+SHIFT+L")),
Map.entry("open_font_selector", KeyBinding.parse("ALT+T")),
Map.entry("open_scrollback", KeyBinding.parse("ALT+S")),
Map.entry("create_worktree", KeyBinding.parse("ALT+W")),
Map.entry("pane_sync_toggle", KeyBinding.parse("ALT+Y")),
Map.entry("pane_sync_select", KeyBinding.parse("SPACE")),
Map.entry("paste", KeyBinding.parse("CTRL+SHIFT+V"))
)
);
@@ -128,6 +137,7 @@ public record AppConfig(
windowHeight,
kittyGraphics,
scrollbackEditorCommand,
worktreeRelativePath,
closeSignal,
envOverride,
keybindings
@@ -230,6 +240,8 @@ public record AppConfig(
builder.append("enabled = ").append(kittyGraphics).append("\n\n");
builder.append("[scrollback]\n");
builder.append("editor_command = ").append(quoted(scrollbackEditorCommand)).append("\n\n");
builder.append("[worktree]\n");
builder.append("relative_worktree_path = ").append(quoted(worktreeRelativePath)).append("\n\n");
builder.append("[env.override]\n");
for (Map.Entry<String, String> entry : envOverride.entrySet()) {
builder.append(entry.getKey()).append(" = ").append(quoted(entry.getValue())).append('\n');

View File

@@ -20,6 +20,7 @@ import javafx.scene.text.TextAlignment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -37,6 +38,8 @@ public final class Compositor {
// Canvas background shown wherever no pane covers (gaps). Painted on a full recomposite.
private static final Color GAP_BACKGROUND = Color.rgb(16, 16, 18);
private static final Color TAB_TEXT = Color.rgb(225, 229, 235);
private static final Color PANE_SYNC_SELECT_BORDER = Color.rgb(255, 183, 77);
private static final Color PANE_SYNC_COMMITTED_BORDER = Color.rgb(105, 214, 128);
// Thin tab strip shown at the top when more than one tab is open.
private static final double TAB_BAR_HEIGHT = 22.0;
@@ -62,6 +65,9 @@ public final class Compositor {
private final Map<TerminalPane, Long> hiddenSince = new HashMap<>();
// Panes whose backbuffer is currently released, so we don't release again every frame.
private final Set<TerminalPane> released = new HashSet<>();
private final Set<TerminalPane> paneSyncSelection = new LinkedHashSet<>();
private final Set<TerminalPane> paneSyncPanes = new LinkedHashSet<>();
private boolean paneSyncSelectMode;
// layoutVersion at the last sweep: lets an idle, all-released steady state skip the scan.
private long lastSweepLayoutVersion = Long.MIN_VALUE;
// Cheap per-frame dirty signal: skip the whole render when none of these changed.
@@ -134,6 +140,54 @@ public final class Compositor {
}
}
public boolean isPaneSyncSelecting() {
return paneSyncSelectMode;
}
public void togglePaneSync() {
if (paneSyncSelectMode) {
paneSyncPanes.clear();
paneSyncPanes.addAll(paneSyncSelection);
paneSyncSelectMode = false;
paneSyncSelection.clear();
prunePaneSyncState();
layoutVersion++;
return;
}
if (!paneSyncPanes.isEmpty()) {
paneSyncPanes.clear();
layoutVersion++;
return;
}
if (activePane() == null) {
return;
}
paneSyncSelectMode = true;
paneSyncSelection.clear();
layoutVersion++;
}
public void togglePaneSyncSelection() {
TerminalPane active = activePane();
if (active == null || !paneSyncSelectMode) {
return;
}
if (!paneSyncSelection.add(active)) {
paneSyncSelection.remove(active);
}
layoutVersion++;
}
public List<TerminalPane> paneSyncPeers(TerminalPane source) {
prunePaneSyncState();
if (source == null || !paneSyncPanes.contains(source)) {
return List.of();
}
return paneSyncPanes.stream()
.filter(pane -> pane != source)
.toList();
}
public void toggleFloating() {
mutateCurrentTab(() -> currentTab().toggleFloating());
}
@@ -190,6 +244,7 @@ public final class Compositor {
for (int i = 0; i < tabs.size(); i++) {
Tab tab = tabs.get(i);
if (tab.closePane(pane)) {
removePaneFromSyncState(pane);
if (tab.isEmpty()) {
// Closing a tab's last pane closes the tab. Keep currentTabIndex pointing at the
// same tab (or clamp it when the current/last tab went away).
@@ -238,6 +293,9 @@ public final class Compositor {
tab.close();
}
tabs.clear();
paneSyncSelectMode = false;
paneSyncSelection.clear();
paneSyncPanes.clear();
}
/**
@@ -377,6 +435,7 @@ public final class Compositor {
for (TerminalPane pane : panes) {
paneContentVersion.put(pane, pane.paintFull(gc, isActive(pane)));
}
drawPaneSyncOverlay(gc, panes);
imageOverlay.sync(panes);
}
@@ -396,6 +455,7 @@ public final class Compositor {
paneContentVersion.put(pane, pane.paintIncremental(gc, isActive(pane)));
imageOverlay.updatePane(pane);
}
drawPaneSyncOverlay(gc, panes);
}
private GraphicsContext beginFrame() {
@@ -431,6 +491,63 @@ public final class Compositor {
gc.setFontSmoothingType(FontSmoothingType.LCD);
}
private void drawPaneSyncOverlay(GraphicsContext gc, List<TerminalPane> panes) {
Set<TerminalPane> highlighted = paneSyncSelectMode ? paneSyncSelection : paneSyncPanes;
if (highlighted.isEmpty()) {
return;
}
gc.save();
try {
gc.setLineWidth(4.0);
gc.setStroke(paneSyncSelectMode ? PANE_SYNC_SELECT_BORDER : PANE_SYNC_COMMITTED_BORDER);
for (TerminalPane pane : panes) {
if (!highlighted.contains(pane)) {
continue;
}
gc.save();
double x = Math.round(pane.x()) + 2.0;
double y = Math.round(pane.y()) + 2.0;
double width = Math.max(0.0, pane.width() - 4.0);
double height = Math.max(0.0, pane.height() - 4.0);
TerminalRenderer.clip(gc, Math.round(pane.x()), Math.round(pane.y()), pane.width(), pane.height(), pane.clip());
gc.strokeRect(x, y, width, height);
gc.restore();
}
} finally {
gc.restore();
}
}
private void removePaneFromSyncState(TerminalPane pane) {
boolean changed = paneSyncSelection.remove(pane);
changed |= paneSyncPanes.remove(pane);
if (paneSyncPanes.size() < 2) {
changed |= !paneSyncPanes.isEmpty();
paneSyncPanes.clear();
}
if (changed) {
layoutVersion++;
}
}
private void prunePaneSyncState() {
Set<TerminalPane> live = livePanes();
paneSyncSelection.retainAll(live);
paneSyncPanes.retainAll(live);
if (paneSyncPanes.size() < 2) {
paneSyncPanes.clear();
}
}
private Set<TerminalPane> livePanes() {
Set<TerminalPane> live = new HashSet<>();
for (Tab tab : tabs) {
live.addAll(tab.allPanes());
}
return live;
}
// ---- Input ----------------------------------------------------------------------
private void handleMousePressed(MouseEvent event) {

View File

@@ -4,7 +4,8 @@ package com.gregor.jprototerm;
* Entry point and mode dispatch. A bare invocation is a thin client: it hands the request to a
* running {@link Daemon}, or, if none is reachable, opens a single standalone window in this process
* (today's behavior). {@code --daemon} runs the long-lived server that hosts every window in one
* JVM, so client launches skip cold JVM/JavaFX/GL startup.
* JVM, so client launches skip cold JVM/JavaFX/GL startup. {@code --standalone} skips daemon client
* mode and always opens an in-process window, which is useful while testing development builds.
*/
public final class Main {
private Main() {
@@ -14,15 +15,19 @@ public final class Main {
// Match the renderer order the app was tuned for; honor an explicit override if present.
System.setProperty("prism.order", System.getProperty("prism.order", "es2,sw"));
boolean standalone = false;
for (String arg : args) {
if (arg.equals("--daemon")) {
Daemon.run();
return;
}
if (arg.equals("--standalone")) {
standalone = true;
}
}
String workingDirectory = System.getProperty("user.dir");
if (Daemon.tryClient(workingDirectory)) {
if (!standalone && Daemon.tryClient(workingDirectory)) {
return; // a running daemon opened the window
}
// No daemon reachable: fall back to a standalone window; the JVM exits when it closes.

View File

@@ -71,6 +71,9 @@ final class TerminalWindow {
keyActions.put("next_tab", compositor::nextTab);
keyActions.put("open_font_selector", this::openFontSelector);
keyActions.put("open_scrollback", this::openScrollbackInEditor);
keyActions.put("create_worktree", this::createWorktreeInEditor);
keyActions.put("pane_sync_toggle", compositor::togglePaneSync);
keyActions.put("pane_sync_select", compositor::togglePaneSyncSelection);
keyActions.put("paste", this::pasteFromClipboard);
StackPane root = new StackPane(compositor.canvas(), compositor.imageOverlay());
@@ -130,19 +133,51 @@ final class TerminalWindow {
private void handlePressed(KeyEvent event) {
for (Map.Entry<String, Runnable> action : keyActions.entrySet()) {
if (config.keybindings().get(action.getKey()).matches(event)) {
String actionName = action.getKey();
if (config.keybindings().get(actionName).matches(event)) {
if (actionName.equals("pane_sync_select") && !compositor.isPaneSyncSelecting()) {
continue;
}
if (compositor.isPaneSyncSelecting() && !allowedDuringPaneSyncSelection(actionName)) {
event.consume();
return;
}
action.getValue().run();
event.consume();
return;
}
}
if (compositor.isPaneSyncSelecting()) {
event.consume();
return;
}
String encoded = KeyEncoder.encode(event);
if (encoded != null) {
sendToActivePane(encoded, event);
}
}
private static boolean allowedDuringPaneSyncSelection(String action) {
return switch (action) {
case "navigate_left",
"navigate_down",
"navigate_up",
"navigate_right",
"toggle_floating",
"next_floating",
"previous_tab",
"next_tab",
"pane_sync_toggle",
"pane_sync_select" -> true;
default -> false;
};
}
private void handleTyped(KeyEvent event) {
if (compositor.isPaneSyncSelecting()) {
event.consume();
return;
}
if (event.isAltDown() || event.isControlDown() || event.isMetaDown()) {
return;
}
@@ -159,6 +194,9 @@ final class TerminalWindow {
TerminalPane active = compositor.activePane();
if (active != null) {
active.send(text);
for (TerminalPane peer : compositor.paneSyncPeers(active)) {
peer.send(text);
}
event.consume();
}
}
@@ -167,7 +205,11 @@ final class TerminalWindow {
TerminalPane active = compositor.activePane();
Clipboard clipboard = Clipboard.getSystemClipboard();
if (active != null && clipboard.hasString()) {
active.paste(clipboard.getString());
String text = clipboard.getString();
active.paste(text);
for (TerminalPane peer : compositor.paneSyncPeers(active)) {
peer.paste(text);
}
}
}
@@ -230,13 +272,30 @@ final class TerminalWindow {
// — no shell startup/rc race — and the pane auto-closes when the editor exits. The
// trailing rm removes the file (which holds terminal contents) when the editor exits;
// deleteOnExit would leak files for the JVM's whole lifetime in daemon mode.
compositor.openFloatingPane(scrollbackEditorCommand(file) + "; rm -f " + shellQuote(file.toString()));
compositor.openFloatingPane(editorCommand(file) + "; rm -f " + shellQuote(file.toString()));
} catch (IOException ex) {
System.err.println("Could not open scrollback in editor: " + ex.getMessage());
}
}
private String scrollbackEditorCommand(Path file) {
private void createWorktreeInEditor() {
// The floating pane command inherits the active pane's cwd at creation time, so the git
// worktree command runs from the pane that was focused before this shortcut opened.
TerminalPane active = compositor.activePane();
if (active == null) {
return;
}
try {
Path file = Files.createTempFile("jprototerm-worktree-", ".txt");
Files.writeString(file, "");
compositor.openFloatingPane(worktreeEditorCommand(file));
} catch (IOException ex) {
System.err.println("Could not create worktree from editor input: " + ex.getMessage());
}
}
private String editorCommand(Path file) {
String quotedFile = shellQuote(file.toString());
String command = config.scrollbackEditorCommand();
if (command == null || command.isBlank()) {
@@ -248,6 +307,25 @@ final class TerminalWindow {
return command + " " + quotedFile;
}
private String worktreeEditorCommand(Path file) {
String quotedFile = shellQuote(file.toString());
String relativePath = config.worktreeRelativePath();
if (relativePath == null || relativePath.isBlank()) {
relativePath = "./.worktrees";
}
return editorCommand(file)
+ "; editor_status=$?"
+ "; name=$(cat " + quotedFile + ")"
+ "; if [ \"$editor_status\" -eq 0 ] && [ -n \"$name\" ]; then"
+ " git worktree add " + shellQuote(relativePath) + "/\"$name\""
+ "; git_status=$?"
+ "; else git_status=$editor_status"
+ "; fi"
+ "; rm -f " + quotedFile
+ "; exit \"$git_status\"";
}
private static String shellQuote(String value) {
return "'" + value.replace("'", "'\"'\"'") + "'";
}