Skip to content
Merged
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
35 changes: 28 additions & 7 deletions bin/berth-herdr-app
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ worker_tab() { # <opener> <space>
# labels yet, so a refusal is tried again for a while.
window_wait_seconds=5

window_open() {
command -v herdr-app >/dev/null && herdr-app status >/dev/null 2>&1
}

window() { # <command> <arguments>...
local out deadline=$((SECONDS + window_wait_seconds))
command -v herdr-app >/dev/null && herdr-app status >/dev/null 2>&1 || return 0
window_open || return 0
until out=$(herdr-app "do" "$@" 2>&1); do
if [ "$SECONDS" -ge "$deadline" ]; then
echo "berth (herdr-app): the window refused $1: $out" >&2
Expand All @@ -154,16 +158,33 @@ window() { # <command> <arguments>...
done
}

# Names whatever an independent berth's place gives it: the space and its
# first tab for one opened apart, and the tab for one opened in a tab. The
# window takes a command with no id to mean what it shows, so a berth that
# the window does not show names nothing.
# pane.rename takes a pane, which only the window's listing ties to a
# terminal.
name_pane() { # <terminal id> <label>
local pane deadline=$((SECONDS + window_wait_seconds))
window_open || return 0
until pane=$(herdr-app ls 2>/dev/null | jq -er --arg terminal "$1" '
first(.spaces[].tabs[].terminals[] | select(.terminal == $terminal) | .pane)'); do
if [ "$SECONDS" -ge "$deadline" ]; then
echo "berth (herdr-app): the window shows no pane for $1 to name" >&2
return 0
fi
sleep 0.2
done
window pane.rename --pane "$pane" --name "$2"
}

# Names a berth's pane, and whatever an independent berth's place gives it:
# the space and its first tab for one opened apart, and the tab for one opened
# in a tab. The window takes a command with no id to mean what it shows, so a
# berth that the window does not show names nothing.
name_place() { # <terminal> <label>
local space tab
jq -e '.labels["berth.relationship"] == "independent"' <<<"$1" >/dev/null || return 0
space=$(jq -r '.labels["herdr.space"] // empty' <<<"$1")
tab=$(jq -r '.labels["herdr.tab"] // empty' <<<"$1")
[ -n "$space" ] && [ -n "$tab" ] || return 0
name_pane "$(jq -r .address <<<"$1")" "$2"
jq -e '.labels["berth.relationship"] == "independent"' <<<"$1" >/dev/null || return 0
case $(jq -r '.labels["berth.place"]' <<<"$1") in
apart) window space.rename --id "$space" --name "$2" ;&
tab) window tab.rename --id "$tab" --name "$2" ;;
Expand Down Expand Up @@ -232,7 +253,7 @@ name() {
id=$(berth_id "$1")
terminal=$(existing_terminal "$id" "it cannot be named")
hc_call label "$id" "berth.label=$2" >/dev/null
[ -z "$(jq -r '.labels["herdr.space"] // empty' <<<"$terminal")" ] || name_place "$terminal" "$2"
name_place "$terminal" "$2"
}

serve() {
Expand Down
2 changes: 1 addition & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ The herdr desktop app runs its terminals in its own backend, herdr-core, and nev
- **The shell after the command.** hc runs a berth's command as the terminal's program, and the terminal finishes when the command exits. So the adapter runs the command under a shell, which becomes the shell that `SHELL` names in herdr-core's environment once the command exits. An agent that leaves for its shell then leaves its berth open, and herdr-core clears its agent state once the shell is back in the foreground. The command takes its `BERTH_ID` from herdr-core's own `HC_TERMINAL_ID`, because hc gives a terminal its id only once it exists.
- **Text waits for Enter.** hc can paste text and press Enter in one call, but it cannot type text without submitting it. So `send-text` holds the text in the adapter's state, under `berth/herdr-app/<yard>/` in `$XDG_STATE_HOME`, and the next `send-key Enter` submits it with one paste. Text held this way does not show on screen until then. A key other than Enter is refused while text is held, because hc could not type the text in front of it. A later hc that types without submitting closes the gap.
- **Layout.** The window shows a terminal in the space and tab that its `herdr.space` and `herdr.tab` labels name, and makes a new space or tab for an id it does not know. So the adapter places a berth through those labels alone, and placement works while the window is closed. An independent berth that opens apart gets a new space. One opened in a tab gets a new tab in its opener's space. One opened beside its opener, and a tender, join the opener's tab, and the window chooses the split. Workers share a tab in their opener's space, four to a tab, and then open another. The window may be closed, so nothing can measure its panes, and the count stands in for herdr's size floors. A berth whose opener the window does not show stays hidden too.
- **Names and focus.** Only the window can name a space or a tab, or move focus, so the adapter asks it through `herdr-app` when one is open. A berth's label names its space and tab as it does under herdr, and a new workers' tab is called `workers`. With the window closed, Herdr's own names stand, and `--focus` does nothing. A pane takes no name, because the app before 0.1.17 cannot name one.
- **Names and focus.** Only the window can name a pane, a space or a tab, or move focus, so the adapter asks it through `herdr-app` when one is open. A berth's label names its pane, and its space and tab, as it does under herdr, and a new workers' tab is called `workers`. The window names a pane by the pane's id, so the adapter finds the pane that shows a berth's terminal in `herdr-app ls`. With the window closed, Herdr's own names stand, and `--focus` does nothing. Naming a pane needs the app at 0.1.17 or later.
- **Lines of work.** A line of work is a label: an independent berth that opens apart starts one, and every other berth joins its opener's. `open` looks within it for a labelled tender, and closing a berth closes what it opened.
- **Package parameter.** herdr-core's package is a parameter, as herdr's is for its adapter.

Expand Down