Compare commits
13
Commits
main
...
v1.0.0-beta.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03db35dd31
|
||
|
|
249d7168a8
|
||
|
|
95f0d8b8e5
|
||
|
|
fdd24a0388
|
||
|
|
9435f4810d
|
||
|
|
4357c7efa5
|
||
|
|
192910f45a
|
||
|
|
1131fd1c42
|
||
|
|
3007a24b7d
|
||
|
|
b68b8c7903
|
||
|
|
18c4a516e5
|
||
|
|
6f1d304fd7
|
||
|
|
f3d4fe413c
|
No files matched your search
@@ -0,0 +1,120 @@
|
||||
# LLeMbas TTY's own workflow: the one workflow in this repository that is ours. Every other
|
||||
# file in this directory is WezTerm's, kept untouched so that merging upstream stays cheap; on
|
||||
# our repository those are switched off in the Actions settings (llembas/README.md says how).
|
||||
#
|
||||
# On every push to main and dev, on a pull request, and by hand: the hygiene check, the LLeMbas
|
||||
# layer's tests, a release build for Linux x86-64, the config crate's tests, a headless smoke
|
||||
# test of what was built, and the packages (kept as a build artefact).
|
||||
# On a signed tag vX.Y.Z or vX.Y.Z-beta.N: the same, and then the GitHub Release with the
|
||||
# packages, SHA256SUMS and the tag message as its notes.
|
||||
name: llembas-tty
|
||||
on:
|
||||
push:
|
||||
branches: [main, dev]
|
||||
tags: ["v*"]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: llembas-tty-${{ github.ref }}
|
||||
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||
|
||||
jobs:
|
||||
linux:
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 120
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
CARGO_INCREMENTAL: "0"
|
||||
CARGO_TERM_COLOR: always
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
# The whole history: the hygiene check reads what was added since the commit in
|
||||
# UPSTREAM, and the build derives WezTerm's version from the newest commit.
|
||||
fetch-depth: 0
|
||||
# freetype, harfbuzz, libpng and zlib are built from deps/
|
||||
submodules: recursive
|
||||
- name: Nothing private in what this fork adds
|
||||
run: scripts/hygiene.sh
|
||||
- name: The tag names this version
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
git fetch --force origin "refs/tags/$GITHUB_REF_NAME:refs/tags/$GITHUB_REF_NAME"
|
||||
version="$(tr -d '[:space:]' < VERSION)"
|
||||
[ "v$version" = "$GITHUB_REF_NAME" ] || { echo "VERSION says $version, the tag is $GITHUB_REF_NAME" >&2; exit 1; }
|
||||
- name: Tools for the checks
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y lua5.4 luajit zsh shellcheck yamllint desktop-file-utils appstream
|
||||
- name: The LLeMbas layer's tests (Lua 5.4 and LuaJIT)
|
||||
run: scripts/test-lua.sh --all
|
||||
- name: Shell scripts, the workflow, the desktop file
|
||||
run: |
|
||||
shellcheck scripts/*.sh llembas/packaging/*.sh llembas/tests/*.sh llembas/ci/*.sh \
|
||||
llembas/shell/llembas-tty.sh llembas/shell/autocomplete.bash
|
||||
zsh -n llembas/shell/autocomplete.zsh
|
||||
zsh -n llembas/shell/llembas-tty.sh
|
||||
yamllint -d '{extends: default, rules: {line-length: disable, document-start: disable, truthy: disable}}' .github/workflows/llembas-tty.yml
|
||||
desktop-file-validate llembas/packaging/eu.llembas.tty.desktop
|
||||
appstreamcli validate --no-net llembas/packaging/eu.llembas.tty.appdata.xml || true
|
||||
- name: System libraries
|
||||
run: env CI=yes ./get-deps
|
||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
# Upstream's code is not held to "no warnings" here; the action's default would be.
|
||||
rustflags: ""
|
||||
- name: The bundled LLeMbas CLI, verified
|
||||
run: scripts/fetch-cli.sh
|
||||
- name: Build (release)
|
||||
run: cargo build --release --locked -p wezterm -p wezterm-gui -p wezterm-mux-server
|
||||
- name: The binaries carry our names
|
||||
run: |
|
||||
ls -l target/release/llembas-tty target/release/llembas-tty-gui target/release/llembas-tty-mux-server
|
||||
target/release/llembas-tty --version
|
||||
- name: Tests of the configuration crate (where the layer is built in)
|
||||
run: cargo test --release --locked -p config
|
||||
- name: Smoke test, headless
|
||||
run: llembas/tests/smoke.sh target/release
|
||||
- name: Package (.deb and tarball)
|
||||
run: llembas/packaging/package.sh target dist
|
||||
- name: The .deb installs, runs and is removed cleanly
|
||||
run: |
|
||||
sudo apt-get install -y ./dist/llembas-tty_*.deb
|
||||
llembas-tty --version
|
||||
test -x /usr/lib/llembas-tty/lembas
|
||||
llembas/tests/smoke.sh /usr/lib/llembas-tty
|
||||
sudo apt-get remove -y llembas-tty
|
||||
- name: SHA256SUMS
|
||||
run: |
|
||||
cd dist
|
||||
version="$(tr -d '[:space:]' < ../VERSION)"
|
||||
# Written beside the folder first: inside it, the glob would list SHA256SUMS itself.
|
||||
{ echo "# llembas-tty $version"; sha256sum -- *; } > ../SHA256SUMS
|
||||
mv ../SHA256SUMS .
|
||||
cat SHA256SUMS
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: llembas-tty-linux-x86_64
|
||||
path: dist/*
|
||||
retention-days: 14
|
||||
- name: Publish the GitHub Release
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
version="$(tr -d '[:space:]' < VERSION)"
|
||||
git tag -l --format='%(contents)' "$GITHUB_REF_NAME" | sed '/-----BEGIN SSH SIGNATURE-----/,$d' > notes.md
|
||||
# A version is released once: a fix is a new version, never the old one re-released.
|
||||
if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
|
||||
echo "A release for $GITHUB_REF_NAME exists already. Release the fix as a new version." >&2
|
||||
exit 1
|
||||
fi
|
||||
pre=()
|
||||
case "$version" in *-*) pre=(--prerelease) ;; esac
|
||||
gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag "${pre[@]}" \
|
||||
--title "LLeMbas TTY $version" --notes-file notes.md dist/*
|
||||
+43
-2
@@ -3,10 +3,51 @@
|
||||
What changed in each release of LLeMbas TTY. WezTerm's own changes are in
|
||||
`docs/changelog.md`, as upstream keeps them.
|
||||
|
||||
## 1.0.0-beta.1 — unreleased
|
||||
## 1.0.0-beta.1 — 2026-12-02
|
||||
|
||||
### Added
|
||||
|
||||
- Carries LLeMbas CLI 2.0.0-beta.18, the first with what the terminal needs from it (session
|
||||
state for the bar, terminal context, the pane tools, a shell line completed).
|
||||
|
||||
- Forked from WezTerm (`wezterm/wezterm`, `main` at `1026152aa`), with its full
|
||||
history, so that upstream can be merged in; `UPSTREAM` names the upstream
|
||||
commit last merged. Nothing changed in the terminal yet.
|
||||
commit last merged.
|
||||
- **Its own identity**, so that it installs and runs beside WezTerm and shares
|
||||
nothing with it: the commands `llembas-tty`, `llembas-tty-gui` and
|
||||
`llembas-tty-mux-server`; the configuration in
|
||||
`~/.config/llembas-tty/llembas-tty.lua` or `~/.llembas-tty.lua`; its own
|
||||
data, cache and runtime directories; the window class and application id
|
||||
`eu.llembas.tty`; its own desktop entry and icon. WezTerm's configuration
|
||||
files and `WEZTERM_*` variables are neither read nor passed on, and neither
|
||||
program connects to the other's panes.
|
||||
- Panes get `LLEMBAS_TTY` (the version), `LLEMBAS_TTY_PANE` and
|
||||
`LLEMBAS_TTY_EXECUTABLE`; `TERM_PROGRAM` stays `WezTerm`, which programs
|
||||
detect features by. `--version` shows our version and the WezTerm version it
|
||||
is based on.
|
||||
- **The LLeMbas layer**, built into the binary as `require 'llembas'` and
|
||||
applied by a built-in configuration when you have no file of your own:
|
||||
- *Ask the model* (`Ctrl+Shift+A`): a one-line prompt; the question goes to
|
||||
the tab's LLeMbas pane, or to a new one opened beside yours, together with
|
||||
the last commands of your pane and the end of their output.
|
||||
- *Ask about this screen*, *new session here* (`Ctrl+Shift+S`), *resume a
|
||||
session* (`Ctrl+Shift+O`), *toggle side display* (`Ctrl+Shift+D`), *private
|
||||
pane on/off* (`Ctrl+Shift+H`) and *log in*, all in the command palette too.
|
||||
- A session bar with the model, mode, state and context of the LLeMbas pane
|
||||
you are in, and a mark on a tab in which LLeMbas waits for you.
|
||||
- Every key and every part can be changed or turned off in
|
||||
`require('llembas').apply(config, { … })`.
|
||||
- **A plain terminal by default.** Nothing is started, read or sent until you
|
||||
press one of those keys. A private pane, a password prompt and a pane on
|
||||
another machine are never passed on; a full-screen program only when asked.
|
||||
- **Shell integration** for bash and zsh, active only inside LLeMbas TTY:
|
||||
command and output marks (WezTerm's own script), and prompt autocomplete —
|
||||
ghost text in zsh, a key in bash — off unless `autocomplete = true`.
|
||||
- **Packages**: a `.deb` and a tarball for Linux x86-64, built by CI, carrying
|
||||
the LLeMbas CLI pinned in `llembas-cli.version` and verified against its
|
||||
release key.
|
||||
|
||||
### Changed
|
||||
|
||||
- The check for updates is off by default: it asked GitHub about WezTerm's
|
||||
releases, which are not this program's.
|
||||
@@ -2,24 +2,134 @@
|
||||
|
||||
**A terminal that is also an agent.** LLeMbas TTY is a fork of
|
||||
[WezTerm](https://github.com/wezterm/wezterm) with LLeMbas built in. By default
|
||||
it is an ordinary terminal and nothing leaves the machine. When you ask, it
|
||||
can attach a LLeMbas session to a pane:
|
||||
it is an ordinary terminal: nothing is started, nothing of a pane is read and
|
||||
nothing leaves the machine until you press one of the keys below.
|
||||
|
||||
- **Ask the model** from a key, without the line reaching your shell; the
|
||||
answer shows in a side display.
|
||||
- **The model sees what is happening**: the commands you ran, their exit
|
||||
status and the end of their output, and where you are — as you allow it.
|
||||
- **It can act in the terminal**: run a command in your pane, asked first.
|
||||
- **Autocomplete in the prompt**, as ghost text, with its own switch and model.
|
||||
- **Session bars and displays** — files, commands, changes and pictures — and
|
||||
inline images.
|
||||
|
||||
The agent is the [LLeMbas CLI](https://github.com/LLeMbas/LLeMbas-CLI),
|
||||
unchanged; the package installs it, with Neovim and the LLeMbas editor plugin.
|
||||
The agent is the [LLeMbas CLI](https://github.com/LLeMbas/LLeMbas-CLI)
|
||||
(`lembas`), unchanged; the package carries a verified copy beside the terminal.
|
||||
It logs in to your own LLeMbas server and uses that server's models.
|
||||
|
||||
**State:** just forked; nothing above is built yet. Version in `VERSION`,
|
||||
changes in `CHANGELOG.md`. MIT, like WezTerm — see `LICENSE.md`.
|
||||
**State: 1.0.0-beta.1, not released yet.** The terminal's side described here
|
||||
is written and tested without a terminal; the first builds come from CI. The
|
||||
parts that need the LLeMbas CLI need one that knows about terminals
|
||||
(2.0.0-beta.18 or newer); with an older one the terminal says so in words.
|
||||
Version in `VERSION`, changes in `CHANGELOG.md`. MIT, like WezTerm — see
|
||||
`LICENSE.md`.
|
||||
|
||||
## What it adds
|
||||
|
||||
| Key | Command palette (`Ctrl+Shift+P`) | What it does |
|
||||
|---|---|---|
|
||||
| `Ctrl+Shift+A` | LLeMbas: ask the model | A one-line prompt. Your question goes to LLeMbas with the *terminal context* of the pane you were in (below). If the tab has a LLeMbas pane it is asked there; otherwise one opens to the right, in the same directory. |
|
||||
| | LLeMbas: ask about this screen | The same, with what is visible on the screen instead of the last commands — also from a full-screen program. |
|
||||
| `Ctrl+Shift+S` | LLeMbas: new session here | Starts `lembas` beside the pane, in its directory. |
|
||||
| `Ctrl+Shift+O` | LLeMbas: resume a session | A list of your sessions to pick from. |
|
||||
| `Ctrl+Shift+D` | LLeMbas: toggle side display | Shows or hides the session's side display. |
|
||||
| `Ctrl+Shift+H` | LLeMbas: private pane on/off | Marks the pane private: nothing of it is ever passed on. |
|
||||
| | LLeMbas: log in | Runs `lembas login`. |
|
||||
|
||||
- **Session bar.** When the pane you are in runs LLeMbas, the right of the tab
|
||||
bar shows its model, mode, state and how full its context is. A tab in which
|
||||
LLeMbas waits for you is marked with `●`. With no LLeMbas pane, the bar shows
|
||||
nothing of ours.
|
||||
- **Prompt autocomplete**, off by default: in zsh the rest of the line appears
|
||||
dimmed after the cursor (Right arrow or End takes it), in bash a key
|
||||
(`Ctrl+X Ctrl+A`) completes the line. See *Autocomplete* below.
|
||||
- **Its own everything.** LLeMbas TTY installs beside WezTerm and shares
|
||||
nothing with it: its commands are `llembas-tty`, `llembas-tty-gui` and
|
||||
`llembas-tty-mux-server`, its configuration is
|
||||
`~/.config/llembas-tty/llembas-tty.lua` (or `~/.llembas-tty.lua`), and it
|
||||
neither reads WezTerm's files nor talks to a running WezTerm.
|
||||
|
||||
## What is passed on, and when
|
||||
|
||||
Only when you ask (the two *ask* entries), and only this:
|
||||
|
||||
- the last 5 commands of that pane with the end of each one's output (200
|
||||
lines or 16 KiB at most), and the pane's directory and shell. This needs the
|
||||
shell integration (below), which marks where a command and its output begin;
|
||||
- without shell integration: the last screenful instead;
|
||||
- from a full-screen program (an editor, a pager): only the directory, unless
|
||||
you chose *ask about this screen*.
|
||||
|
||||
Never: a pane you marked private, a pane that is asking for a password, a pane
|
||||
that runs on another machine, the scrollback as a whole, or anything at all
|
||||
while you have not asked. The context is written to a file only you can read,
|
||||
in the terminal's runtime directory; LLeMbas deletes it after reading it and
|
||||
the terminal removes any that are left after ten minutes. What LLeMbas then
|
||||
does with it is the CLI's business and follows its permissions.
|
||||
|
||||
The session bar reads what LLeMbas itself tells the terminal about its session.
|
||||
It does not read the pane.
|
||||
|
||||
## Configuration
|
||||
|
||||
With no configuration file, the built-in one applies the layer with its
|
||||
defaults. Your own file — everything WezTerm's configuration can do, see
|
||||
<https://wezterm.org/config/files.html> — opts in with one line:
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm'
|
||||
local config = wezterm.config_builder()
|
||||
|
||||
require('llembas').apply(config, {
|
||||
-- every line is optional; these are the defaults
|
||||
enabled = true, -- false: no layer at all
|
||||
cli = nil, -- path of `lembas`; nil: the bundled one, then PATH
|
||||
session_bar = true,
|
||||
tab_marker = true,
|
||||
palette = true,
|
||||
bar = { fields = { 'model', 'mode', 'state', 'context' } },
|
||||
-- also: 'session', 'title', 'effort', 'tokens', 'spend'
|
||||
keys = { -- false turns a key off
|
||||
ask = { key = 'A', mods = 'CTRL|SHIFT' },
|
||||
new_session = { key = 'S', mods = 'CTRL|SHIFT' },
|
||||
resume = { key = 'O', mods = 'CTRL|SHIFT' },
|
||||
toggle_display = { key = 'D', mods = 'CTRL|SHIFT' },
|
||||
private = { key = 'H', mods = 'CTRL|SHIFT' },
|
||||
},
|
||||
split = { direction = 'Right', size = 0.45 },
|
||||
new_session_in = 'split', -- or 'tab'
|
||||
context = {
|
||||
enabled = true, -- false: questions go alone, nothing of the pane
|
||||
blocks = 5, -- commands passed on (at most 20)
|
||||
output_lines = 200, -- of each command's output, from its end
|
||||
output_bytes = 16384,
|
||||
alt_screen = false, -- true: also the screen of a full-screen program
|
||||
},
|
||||
autocomplete = false,
|
||||
})
|
||||
|
||||
return config
|
||||
```
|
||||
|
||||
To have none of it: leave the line out of your file, pass `{ enabled = false }`,
|
||||
or start with `llembas-tty -n`.
|
||||
|
||||
If your file sets its own right status or tab titles, turn `session_bar` or
|
||||
`tab_marker` off, or call `apply` after your own handlers: the terminal uses
|
||||
the first tab-title handler it was given.
|
||||
|
||||
## Shell integration
|
||||
|
||||
The package installs it for bash through `/etc/profile.d`. For zsh, or after
|
||||
unpacking the tarball, add to `~/.zshrc` or `~/.bashrc`:
|
||||
|
||||
```sh
|
||||
[ -n "$LLEMBAS_TTY" ] && . /usr/share/llembas-tty/shell/llembas-tty.sh
|
||||
```
|
||||
|
||||
It marks commands and their output for the terminal (WezTerm's own
|
||||
integration script, OSC 133 and OSC 7) and does nothing outside LLeMbas TTY.
|
||||
|
||||
### Autocomplete
|
||||
|
||||
Set `autocomplete = true` in the options above; new panes then have
|
||||
`LLEMBAS_TTY_AUTOCOMPLETE=1` and the shell integration turns completion on.
|
||||
The line you are typing is sent to `lembas complete` after a short pause —
|
||||
never an empty line, never a line that starts with a space, never outside
|
||||
LLeMbas TTY. What comes back is put on the line as text; nothing runs until
|
||||
you press Enter. If zsh-autosuggestions is loaded, ours stays off.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>wezterm-gui</string>
|
||||
<!-- LLeMbas TTY: its own names and identifier, here and below -->
|
||||
<string>llembas-tty-gui</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.github.wez.wezterm</string>
|
||||
<string>eu.llembas.tty</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>WezTerm</string>
|
||||
<string>LLeMbas TTY</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
@@ -33,7 +34,7 @@
|
||||
<key>NSSupportsAutomaticGraphicsSwitching</key>
|
||||
<true/>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>WezTerm</string>
|
||||
<string>LLeMbas TTY</string>
|
||||
<key>NSRequiresAquaSystemAppearance</key>
|
||||
<string>NO</string>
|
||||
<key>NSAppleEventsUsageDescription</key>
|
||||
|
||||
+81
-16
@@ -1025,9 +1025,10 @@ impl Config {
|
||||
// multiple. In addition, it spawns a lot of subprocesses,
|
||||
// so we do this bit "by-hand"
|
||||
|
||||
let mut paths = vec![PathPossibility::optional(HOME_DIR.join(".wezterm.lua"))];
|
||||
// LLeMbas TTY: its own file names, never WezTerm's
|
||||
let mut paths = vec![PathPossibility::optional(HOME_DIR.join(".llembas-tty.lua"))];
|
||||
for dir in CONFIG_DIRS.iter() {
|
||||
paths.push(PathPossibility::optional(dir.join("wezterm.lua")))
|
||||
paths.push(PathPossibility::optional(dir.join("llembas-tty.lua")))
|
||||
}
|
||||
|
||||
if cfg!(windows) {
|
||||
@@ -1041,12 +1042,17 @@ impl Config {
|
||||
// dir as the executable that will take precedence.
|
||||
if let Ok(exe_name) = std::env::current_exe() {
|
||||
if let Some(exe_dir) = exe_name.parent() {
|
||||
paths.insert(0, PathPossibility::optional(exe_dir.join("wezterm.lua")));
|
||||
// LLeMbas TTY: its own file name
|
||||
paths.insert(
|
||||
0,
|
||||
PathPossibility::optional(exe_dir.join("llembas-tty.lua")),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(path) = std::env::var_os("WEZTERM_CONFIG_FILE") {
|
||||
log::trace!("Note: WEZTERM_CONFIG_FILE is set in the environment");
|
||||
// LLeMbas TTY: its own variable, WEZTERM_CONFIG_FILE is not honoured
|
||||
if let Some(path) = std::env::var_os("LLEMBAS_TTY_CONFIG_FILE") {
|
||||
log::trace!("Note: LLEMBAS_TTY_CONFIG_FILE is set in the environment");
|
||||
paths.insert(0, PathPossibility::required(path.into()));
|
||||
}
|
||||
|
||||
@@ -1077,8 +1083,23 @@ impl Config {
|
||||
// We didn't find (or were asked to skip) a wezterm.lua file, so
|
||||
// update the environment to make it simpler to understand this
|
||||
// state.
|
||||
std::env::remove_var("WEZTERM_CONFIG_FILE");
|
||||
std::env::remove_var("WEZTERM_CONFIG_DIR");
|
||||
// LLeMbas TTY: its own variables
|
||||
std::env::remove_var("LLEMBAS_TTY_CONFIG_FILE");
|
||||
std::env::remove_var("LLEMBAS_TTY_CONFIG_DIR");
|
||||
|
||||
// LLeMbas TTY: with no configuration file (and not asked to skip one),
|
||||
// the built-in configuration applies the LLeMbas layer.
|
||||
if !CONFIG_SKIP.load(Ordering::Relaxed) {
|
||||
return match Self::try_builtin(overrides) {
|
||||
Err(err) => LoadedConfig {
|
||||
config: Err(err),
|
||||
file_name: None,
|
||||
lua: None,
|
||||
warnings: vec![],
|
||||
},
|
||||
Ok(cfg) => cfg,
|
||||
};
|
||||
}
|
||||
|
||||
match Self::try_default() {
|
||||
Err(err) => LoadedConfig {
|
||||
@@ -1105,6 +1126,44 @@ impl Config {
|
||||
})
|
||||
}
|
||||
|
||||
/// LLeMbas TTY: evaluate the configuration that is built into the binary
|
||||
/// (`llembas/lua/default-config.lua`). The same steps as `try_load`, with
|
||||
/// the script taken from memory rather than from a file.
|
||||
fn try_builtin(overrides: &wezterm_dynamic::Value) -> anyhow::Result<LoadedConfig> {
|
||||
let lua = make_lua_context(Path::new(""))?;
|
||||
|
||||
let (config, warnings) =
|
||||
wezterm_dynamic::Error::capture_warnings(|| -> anyhow::Result<Config> {
|
||||
let cfg: Config;
|
||||
|
||||
let config: mlua::Value = smol::block_on(
|
||||
lua.load(crate::llembas::DEFAULT_CONFIG)
|
||||
.set_name("=llembas-tty/default-config.lua")
|
||||
.eval_async(),
|
||||
)?;
|
||||
let config = Config::apply_overrides_to(&lua, config)?;
|
||||
let config = Config::apply_overrides_obj_to(&lua, config, overrides)?;
|
||||
cfg = Config::from_lua(config, &lua).context(
|
||||
"Error converting lua value returned by the built-in configuration \
|
||||
to Config struct",
|
||||
)?;
|
||||
cfg.check_consistency()?;
|
||||
|
||||
// Compute but discard the key bindings here so that we raise any
|
||||
// problems earlier than we use them.
|
||||
let _ = cfg.key_bindings();
|
||||
Ok(cfg)
|
||||
});
|
||||
let cfg = config?;
|
||||
|
||||
Ok(LoadedConfig {
|
||||
config: Ok(cfg.compute_extra_defaults(None)),
|
||||
file_name: None,
|
||||
lua: Some(lua),
|
||||
warnings,
|
||||
})
|
||||
}
|
||||
|
||||
fn try_load(
|
||||
path_item: &PathPossibility,
|
||||
overrides: &wezterm_dynamic::Value,
|
||||
@@ -1149,9 +1208,10 @@ impl Config {
|
||||
// problems earlier than we use them.
|
||||
let _ = cfg.key_bindings();
|
||||
|
||||
std::env::set_var("WEZTERM_CONFIG_FILE", p);
|
||||
// LLeMbas TTY: its own variables
|
||||
std::env::set_var("LLEMBAS_TTY_CONFIG_FILE", p);
|
||||
if let Some(dir) = p.parent() {
|
||||
std::env::set_var("WEZTERM_CONFIG_DIR", dir);
|
||||
std::env::set_var("LLEMBAS_TTY_CONFIG_DIR", dir);
|
||||
}
|
||||
Ok(cfg)
|
||||
});
|
||||
@@ -1620,11 +1680,15 @@ impl Config {
|
||||
// de-facto standard for identifying the terminal.
|
||||
cmd.env("TERM_PROGRAM", "WezTerm");
|
||||
cmd.env("TERM_PROGRAM_VERSION", crate::wezterm_version());
|
||||
// LLeMbas TTY: how a program knows that it runs in this terminal
|
||||
cmd.env("LLEMBAS_TTY", crate::llembas_tty_version());
|
||||
}
|
||||
}
|
||||
|
||||
fn default_check_for_updates() -> bool {
|
||||
cfg!(not(feature = "distro-defaults"))
|
||||
// LLeMbas TTY: off. Upstream's check asks GitHub about WezTerm's releases,
|
||||
// which are not this program's, and nothing leaves the machine unasked.
|
||||
false
|
||||
}
|
||||
|
||||
fn default_pane_select_fg_color() -> RgbaColor {
|
||||
@@ -1756,28 +1820,29 @@ fn default_font_size() -> f64 {
|
||||
12.0
|
||||
}
|
||||
|
||||
// LLeMbas TTY: its own cache, data and runtime directories, never WezTerm's
|
||||
pub(crate) fn compute_cache_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Some(runtime) = dirs_next::cache_dir() {
|
||||
return Ok(runtime.join("wezterm"));
|
||||
return Ok(runtime.join("llembas-tty"));
|
||||
}
|
||||
|
||||
Ok(crate::HOME_DIR.join(".local/share/wezterm"))
|
||||
Ok(crate::HOME_DIR.join(".local/share/llembas-tty"))
|
||||
}
|
||||
|
||||
pub(crate) fn compute_data_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Some(runtime) = dirs_next::data_dir() {
|
||||
return Ok(runtime.join("wezterm"));
|
||||
return Ok(runtime.join("llembas-tty"));
|
||||
}
|
||||
|
||||
Ok(crate::HOME_DIR.join(".local/share/wezterm"))
|
||||
Ok(crate::HOME_DIR.join(".local/share/llembas-tty"))
|
||||
}
|
||||
|
||||
pub(crate) fn compute_runtime_dir() -> anyhow::Result<PathBuf> {
|
||||
if let Some(runtime) = dirs_next::runtime_dir() {
|
||||
return Ok(runtime.join("wezterm"));
|
||||
return Ok(runtime.join("llembas-tty"));
|
||||
}
|
||||
|
||||
Ok(crate::HOME_DIR.join(".local/share/wezterm"))
|
||||
Ok(crate::HOME_DIR.join(".local/share/llembas-tty"))
|
||||
}
|
||||
|
||||
pub fn pki_dir() -> anyhow::Result<PathBuf> {
|
||||
|
||||
+7
-3
@@ -31,6 +31,8 @@ mod font;
|
||||
mod frontend;
|
||||
pub mod keyassignment;
|
||||
mod keys;
|
||||
// LLeMbas TTY: the built-in Lua layer
|
||||
pub mod llembas;
|
||||
pub mod lua;
|
||||
pub mod meta;
|
||||
mod scheme_data;
|
||||
@@ -383,9 +385,10 @@ pub fn create_user_owned_dirs(p: &Path) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
fn xdg_config_home() -> PathBuf {
|
||||
match std::env::var_os("XDG_CONFIG_HOME").map(|s| PathBuf::from(s).join("wezterm")) {
|
||||
// LLeMbas TTY: its own directory, never WezTerm's
|
||||
match std::env::var_os("XDG_CONFIG_HOME").map(|s| PathBuf::from(s).join("llembas-tty")) {
|
||||
Some(p) => p,
|
||||
None => HOME_DIR.join(".config").join("wezterm"),
|
||||
None => HOME_DIR.join(".config").join("llembas-tty"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +398,8 @@ fn config_dirs() -> Vec<PathBuf> {
|
||||
|
||||
#[cfg(unix)]
|
||||
if let Some(d) = std::env::var_os("XDG_CONFIG_DIRS") {
|
||||
dirs.extend(std::env::split_paths(&d).map(|s| PathBuf::from(s).join("wezterm")));
|
||||
// LLeMbas TTY: its own directory, never WezTerm's
|
||||
dirs.extend(std::env::split_paths(&d).map(|s| PathBuf::from(s).join("llembas-tty")));
|
||||
}
|
||||
|
||||
dirs
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//! LLeMbas TTY: the LLeMbas layer, built into the binary.
|
||||
//!
|
||||
//! The layer is Lua (`llembas/lua/` at the top of the repository). It is
|
||||
//! compiled in as text and offered to every Lua context through
|
||||
//! `package.preload`, so that a configuration file can say
|
||||
//! `require('llembas').apply(config)`. With no configuration file at all,
|
||||
//! `DEFAULT_CONFIG` is evaluated instead (see `Config::try_builtin`).
|
||||
//!
|
||||
//! Nothing here runs the layer: a module is only evaluated when it is
|
||||
//! required.
|
||||
|
||||
use anyhow::Context;
|
||||
use mlua::{Lua, Table};
|
||||
|
||||
/// The configuration used when the person has no configuration file.
|
||||
pub const DEFAULT_CONFIG: &str = include_str!("../../llembas/lua/default-config.lua");
|
||||
|
||||
/// Module name as given to `require`, and its source.
|
||||
const MODULES: &[(&str, &str)] = &[
|
||||
(
|
||||
"llembas",
|
||||
include_str!("../../llembas/lua/llembas/init.lua"),
|
||||
),
|
||||
(
|
||||
"llembas.core",
|
||||
include_str!("../../llembas/lua/llembas/core.lua"),
|
||||
),
|
||||
];
|
||||
|
||||
pub fn register(lua: &Lua) -> anyhow::Result<()> {
|
||||
let package: Table = lua.globals().get("package").context("get _G.package")?;
|
||||
let preload: Table = package.get("preload").context("get package.preload")?;
|
||||
for (name, source) in MODULES {
|
||||
let loader = lua
|
||||
.load(*source)
|
||||
.set_name(format!("=llembas-tty/{}.lua", name))
|
||||
.into_function()
|
||||
.with_context(|| format!("compiling the built-in module {}", name))?;
|
||||
preload
|
||||
.set(*name, loader)
|
||||
.with_context(|| format!("registering the built-in module {}", name))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
+5
-1
@@ -227,7 +227,8 @@ pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
|
||||
array.insert(1, format!("{}/?/init.lua", path.display()));
|
||||
}
|
||||
|
||||
prefix_path(&mut path_array, &crate::HOME_DIR.join(".wezterm"));
|
||||
// LLeMbas TTY: its own directory, never WezTerm's
|
||||
prefix_path(&mut path_array, &crate::HOME_DIR.join(".llembas-tty"));
|
||||
for dir in crate::CONFIG_DIRS.iter() {
|
||||
prefix_path(&mut path_array, dir);
|
||||
}
|
||||
@@ -385,6 +386,9 @@ end
|
||||
func(&lua).context("calling SETUP_FUNCS")?;
|
||||
}
|
||||
|
||||
// LLeMbas TTY: make the built-in layer available as `require 'llembas'`
|
||||
crate::llembas::register(&lua).context("registering the llembas module")?;
|
||||
|
||||
Ok(lua)
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -118,10 +118,11 @@ impl UnixDomain {
|
||||
Some(cmd) => Ok(cmd.iter().map(Into::into).collect()),
|
||||
None => Ok(vec![
|
||||
std::env::current_exe()?
|
||||
// LLeMbas TTY: its own binary names
|
||||
.with_file_name(if cfg!(windows) {
|
||||
"wezterm-mux-server.exe"
|
||||
"llembas-tty-mux-server.exe"
|
||||
} else {
|
||||
"wezterm-mux-server"
|
||||
"llembas-tty-mux-server"
|
||||
})
|
||||
.into_os_string(),
|
||||
OsString::from("--daemonize"),
|
||||
|
||||
@@ -14,6 +14,27 @@ pub fn wezterm_version() -> &'static str {
|
||||
.unwrap_or(&"someone forgot to call assign_version_info")
|
||||
}
|
||||
|
||||
/// LLeMbas TTY: this program's own version, from the `VERSION` file at
|
||||
/// the top of the repository at build time. `wezterm_version` stays
|
||||
/// WezTerm's: programs and scripts compare it to detect features.
|
||||
pub fn llembas_tty_version() -> &'static str {
|
||||
include_str!("../../VERSION").trim()
|
||||
}
|
||||
|
||||
/// LLeMbas TTY: what `--version` shows: our version and the WezTerm
|
||||
/// version that it is based on.
|
||||
pub fn llembas_tty_long_version() -> &'static str {
|
||||
static LONG: OnceLock<String> = OnceLock::new();
|
||||
match VERSION.get() {
|
||||
// Not assigned yet (the gui parses its arguments before it is):
|
||||
// our own version alone.
|
||||
None => llembas_tty_version(),
|
||||
Some(wezterm) => LONG
|
||||
.get_or_init(|| format!("{} (based on WezTerm {})", llembas_tty_version(), wezterm))
|
||||
.as_str(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wezterm_target_triple() -> &'static str {
|
||||
TRIPLE
|
||||
.get()
|
||||
|
||||
@@ -3,11 +3,33 @@ pub use ringlog::setup_logger;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn set_wezterm_executable() {
|
||||
// LLeMbas TTY: its own variable names. A WezTerm that started us must
|
||||
// not be mistaken for us by what runs in our panes, so what it exported
|
||||
// is dropped rather than passed on.
|
||||
for name in [
|
||||
"WEZTERM_EXECUTABLE",
|
||||
"WEZTERM_EXECUTABLE_DIR",
|
||||
"WEZTERM_CONFIG_FILE",
|
||||
"WEZTERM_CONFIG_DIR",
|
||||
"WEZTERM_PANE",
|
||||
"WEZTERM_UNIX_SOCKET",
|
||||
] {
|
||||
std::env::remove_var(name);
|
||||
}
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(dir) = exe.parent() {
|
||||
std::env::set_var("WEZTERM_EXECUTABLE_DIR", dir);
|
||||
std::env::set_var("LLEMBAS_TTY_EXECUTABLE_DIR", dir);
|
||||
}
|
||||
std::env::set_var("WEZTERM_EXECUTABLE", exe);
|
||||
// LLeMbas TTY: always the launcher (the one with the `cli`
|
||||
// subcommand), whichever of our binaries this process is.
|
||||
std::env::set_var(
|
||||
"LLEMBAS_TTY_EXECUTABLE",
|
||||
exe.with_file_name(if cfg!(windows) {
|
||||
"llembas-tty.exe"
|
||||
} else {
|
||||
"llembas-tty"
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,9 +74,10 @@ pub fn fixup_appimage() {
|
||||
|
||||
// Since our AppImage includes multiple utilities, we want to
|
||||
// be able to use them, so add that location to the PATH!
|
||||
// WEZTERM_EXECUTABLE_DIR is set by `set_wezterm_executable`
|
||||
// LLEMBAS_TTY_EXECUTABLE_DIR is set by `set_wezterm_executable`
|
||||
// which is called before `fixup_appimage`
|
||||
if let Some(dir) = std::env::var_os("WEZTERM_EXECUTABLE_DIR") {
|
||||
// LLeMbas TTY: its own variable name
|
||||
if let Some(dir) = std::env::var_os("LLEMBAS_TTY_EXECUTABLE_DIR") {
|
||||
if let Some(path) = std::env::var_os("PATH") {
|
||||
let mut paths = std::env::split_paths(&path).collect::<Vec<_>>();
|
||||
paths.insert(0, PathBuf::from(dir));
|
||||
@@ -86,8 +109,9 @@ pub fn fixup_appimage() {
|
||||
/// However, if we are using the system wezterm to spawn a portable
|
||||
/// AppImage then we want these to not take effect.
|
||||
fn clean_wezterm_config_env() {
|
||||
std::env::remove_var("WEZTERM_CONFIG_FILE");
|
||||
std::env::remove_var("WEZTERM_CONFIG_DIR");
|
||||
// LLeMbas TTY: its own variable names
|
||||
std::env::remove_var("LLEMBAS_TTY_CONFIG_FILE");
|
||||
std::env::remove_var("LLEMBAS_TTY_CONFIG_DIR");
|
||||
}
|
||||
|
||||
if config::HOME_DIR.starts_with(append_extra_file_name_suffix(&appimage, ".home")) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
2.0.0-beta.18
|
||||
@@ -0,0 +1,156 @@
|
||||
# The LLeMbas layer — developer notes
|
||||
|
||||
Everything LLeMbas TTY adds to WezTerm lives in this directory, in `scripts/`
|
||||
and in one workflow file. WezTerm's own files are changed as little as
|
||||
possible, and each changed block carries a `LLeMbas TTY:` comment, so that
|
||||
merging upstream stays cheap (`git grep -n 'LLeMbas TTY:'` lists them all).
|
||||
|
||||
```
|
||||
llembas/
|
||||
lua/default-config.lua the configuration used when a person has none
|
||||
lua/llembas/init.lua the layer: keys, palette, events, panes, files
|
||||
lua/llembas/core.lua every decision, as pure functions (no terminal needed)
|
||||
tests/run.lua tests of both, against tests/fake_wezterm.lua
|
||||
tests/smoke.sh headless test of built binaries (CI)
|
||||
shell/ shell integration: zones, cwd, prompt autocomplete
|
||||
packaging/ desktop file, appdata, icons, package.sh (.deb, tarball)
|
||||
ci/ disable-upstream-workflows.sh
|
||||
scripts/
|
||||
test-lua.sh run tests/run.lua with lua5.4, lua, luajit or nvim -l
|
||||
fetch-cli.sh the pinned LLeMbas CLI (llembas-cli.version), verified
|
||||
hygiene.sh nothing private in what the fork adds
|
||||
.github/workflows/llembas-tty.yml
|
||||
```
|
||||
|
||||
## How the layer gets into the terminal
|
||||
|
||||
`config/src/llembas.rs` compiles the Lua files in as text (`include_str!`)
|
||||
and puts a loader for each into `package.preload` of every Lua context, so
|
||||
`require 'llembas'` works in any configuration file and no file has to be
|
||||
installed. With no configuration file, `Config::try_builtin`
|
||||
(`config/src/config.rs`) evaluates `lua/default-config.lua` instead of using
|
||||
the bare defaults. `--skip-config` (`-n`) still gives the plain terminal with
|
||||
no layer at all.
|
||||
|
||||
A new Lua module must be added to `MODULES` in `config/src/llembas.rs`.
|
||||
|
||||
## Rules the layer keeps
|
||||
|
||||
- **Nothing happens unasked.** `apply()` binds keys, adds palette entries and
|
||||
registers event handlers. It starts no process and reads no pane. The
|
||||
session bar reads only user variables (what a program set with OSC 1337
|
||||
`SetUserVar`), never text.
|
||||
- **Everything from a pane or a model is text.** User variables, command
|
||||
output, titles, session lists and completions go through `core.clean`
|
||||
(control characters removed, invalid UTF-8 replaced) and are capped before
|
||||
they are shown, written or sent. Nothing is evaluated, nothing is passed
|
||||
through a shell: processes are started with an argument list.
|
||||
- **Decisions are in `core.lua`, calls in `init.lua`.** A change to what the
|
||||
layer decides comes with a test in `tests/run.lua`.
|
||||
- **Lua 5.1 and 5.4.** The terminal embeds Lua 5.4; the tests also run under
|
||||
LuaJIT. Write the subset both have (no `goto`, `//`, bitwise operators,
|
||||
`<const>`, `utf8`, `table.unpack` without a fallback).
|
||||
|
||||
## The contract with the LLeMbas CLI
|
||||
|
||||
The agent is the LLeMbas CLI, unchanged in role. The terminal drives it:
|
||||
|
||||
| The terminal | The CLI |
|
||||
|---|---|
|
||||
| reads user variables `lembas_session`, `lembas_title`, `lembas_model`, `lembas_mode`, `lembas_effort`, `lembas_state` (`idle`, `waiting`, `thinking`, `tools`, `writing`, `asking`), `lembas_context` (percent), `lembas_tokens`, `lembas_spend` | sets them with OSC 1337 `SetUserVar` |
|
||||
| starts `lembas --terminal-context <file>` in a new pane, or writes `/terminal-context <file>` + Enter into a running session | reads the file, deletes it |
|
||||
| writes the question as a bracketed paste + Enter, once the session reports `lembas_state=idle` | takes it as a prompt |
|
||||
| exports `LLEMBAS_TTY` (version), `LLEMBAS_TTY_PANE`, `LLEMBAS_TTY_EXECUTABLE` to every pane | its terminal tools run `$LLEMBAS_TTY_EXECUTABLE cli send-text --pane-id N --no-paste` and `cli get-text --pane-id N` |
|
||||
| shell integration pipes the line so far to `lembas complete --shell <zsh\|bash> --cwd <dir> --timeout-ms 2500` | prints only the rest of the line; nothing means no suggestion |
|
||||
| runs `lembas sessions --json` for the resume list (falls back to `/sessions` in a new session) | prints a list of objects with `id`, and `title`, `model`, `root` |
|
||||
|
||||
The context file is JSON, mode 0600, in the terminal's runtime directory,
|
||||
named `context-<unix seconds>-<random>.json`:
|
||||
|
||||
```json
|
||||
{ "version": 1, "pane": 3, "cwd": "/home/me/project", "shell": "zsh",
|
||||
"blocks": [ { "command": "make test", "exit": null, "output": "…tail…" } ],
|
||||
"screen": "…only when the shell marks no commands…" }
|
||||
```
|
||||
|
||||
`exit` is always `null` today: WezTerm's Lua interface does not expose the
|
||||
exit status that OSC 133 `D` carries. Files older than ten minutes are
|
||||
removed the next time one is written.
|
||||
|
||||
Whether a CLI is new enough is decided in exactly one function,
|
||||
`core.cli_supports_terminal`, today by comparing `lembas --version` with
|
||||
`core.MIN_CLI_VERSION`.
|
||||
|
||||
## Checking a change without building
|
||||
|
||||
```
|
||||
scripts/test-lua.sh --all # the layer, with every Lua found
|
||||
scripts/hygiene.sh
|
||||
rustfmt --check --edition 2018 <file> # for a Rust file you touched
|
||||
shellcheck llembas/shell/*.sh llembas/shell/autocomplete.bash; zsh -n llembas/shell/autocomplete.zsh
|
||||
```
|
||||
|
||||
The terminal itself is built by CI only. `llembas/tests/smoke.sh <dir>` runs
|
||||
against built binaries with no display: names, directories, variables, the
|
||||
built-in layer and the `cli` commands the LLeMbas CLI uses.
|
||||
|
||||
## The GitHub repository that builds it
|
||||
|
||||
`.github/workflows/llembas-tty.yml` is the only workflow that is ours.
|
||||
WezTerm's workflow files are left exactly as they are; on our repository
|
||||
they are switched off as a repository setting:
|
||||
|
||||
```
|
||||
llembas/ci/disable-upstream-workflows.sh <owner>/<repository>
|
||||
```
|
||||
|
||||
once, and again after an upstream merge that adds a workflow file. What the
|
||||
repository needs:
|
||||
|
||||
- Actions enabled, with GitHub-hosted `ubuntu-22.04` runners (a build takes
|
||||
the better part of an hour; a private repository pays for the minutes).
|
||||
- The submodules reachable: `deps/freetype/*` and `deps/harfbuzz/harfbuzz`
|
||||
are public GitHub repositories, fetched by `actions/checkout`.
|
||||
- The whole history, tags included: the hygiene check needs the commit named
|
||||
in `UPSTREAM`, and a release needs the signed tag object for its notes.
|
||||
- No secret: the workflow uses only the `GITHUB_TOKEN` it is given, with
|
||||
`contents: write` for the release. The LLeMbas CLI is fetched from its
|
||||
public releases and verified against the release key in `scripts/fetch-cli.sh`.
|
||||
- Workflow permissions that allow `contents: write` (Settings → Actions →
|
||||
General → Workflow permissions), or the release step is refused.
|
||||
|
||||
## Merging upstream
|
||||
|
||||
```
|
||||
git fetch upstream && git merge upstream/main # never a rebase
|
||||
git rev-parse upstream/main > UPSTREAM # the hygiene check's base
|
||||
git grep -n 'LLeMbas TTY:' # every block of ours, to re-check
|
||||
scripts/test-lua.sh --all
|
||||
```
|
||||
|
||||
Conflicts can only be in the blocks that grep lists. If upstream changes how
|
||||
panes get their environment, how configuration files are found, or the Lua
|
||||
API the layer calls (`pane:get_semantic_zones`, `get_text_from_semantic_zone`,
|
||||
`get_user_vars`, `split`, `PromptInputLine`, `InputSelector`,
|
||||
`update-status`, `format-tab-title`, `augment-command-palette`,
|
||||
`user-var-changed`), re-read those blocks and `lua/llembas/init.lua`.
|
||||
|
||||
## Later
|
||||
|
||||
- **Neovim and the editor plugin in the package.** `package.sh` would take a
|
||||
pinned, checksum-verified Neovim release and the LLeMbas IDE plugin into
|
||||
`usr/lib/llembas-tty/nvim/`, with a launcher that sets its own
|
||||
`NVIM_APPNAME` so that a person's own Neovim configuration is not touched;
|
||||
one more `fetch-*.sh` with a pin file, as for the CLI.
|
||||
- **AppImage.** Upstream's `ci/appimage.sh` assembles an AppDir from fixed
|
||||
names (`wezterm`, `org.wezfurlong.wezterm`); ours would be a copy with our
|
||||
names plus the CLI, built from the same tree `package.sh` stages.
|
||||
- **macOS and Windows.** The identity is in place (bundle id, AppUserModelID,
|
||||
binary names); the packaging (`ci/deploy.sh`, the installer script, the
|
||||
`.app` directory's name and icon) still carries WezTerm's names, and the
|
||||
layer writes its context file with `chmod`, which Windows does not have.
|
||||
- **fish.** Ghost text in fish means replacing its own autosuggestion, which
|
||||
it does not offer a hook for; a key binding like bash's
|
||||
(`commandline -i (… | lembas complete --shell fish)`) is the part that fits.
|
||||
- **Ghost text drawn by the terminal** instead of by the shell would work in
|
||||
every shell and over ssh, and needs Rust in the renderer and the key path.
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
# Switch off every GitHub Actions workflow in a repository except ours (llembas-tty.yml).
|
||||
#
|
||||
# llembas/ci/disable-upstream-workflows.sh <owner>/<repository>
|
||||
#
|
||||
# WezTerm's own workflow files stay in .github/workflows untouched, so that merging upstream
|
||||
# never conflicts there. They must not run on our repository (nightly builds, documentation
|
||||
# pages, issue housekeeping), and GitHub keeps "disabled" as a setting of the repository, not
|
||||
# of the file. Run this once after the repository is made, and again after a merge from
|
||||
# upstream that brought a new workflow file. Needs `gh`, signed in with rights on the repository.
|
||||
set -euo pipefail
|
||||
repo="${1:?usage: disable-upstream-workflows.sh <owner>/<repository>}"
|
||||
|
||||
gh workflow list --repo "$repo" --all --json name,path,state --jq '.[] | [.path, .state] | @tsv' |
|
||||
while IFS=$'\t' read -r path state; do
|
||||
case "$path" in
|
||||
.github/workflows/llembas-tty.yml)
|
||||
[ "$state" = active ] || gh workflow enable "$path" --repo "$repo"
|
||||
echo "ours, on: $path"
|
||||
;;
|
||||
*)
|
||||
[ "$state" = active ] && gh workflow disable "$path" --repo "$repo"
|
||||
echo "upstream, off: $path"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
@@ -0,0 +1,8 @@
|
||||
-- LLeMbas TTY: the configuration used when the person has none of their own
|
||||
-- ($XDG_CONFIG_HOME/llembas-tty/llembas-tty.lua or ~/.llembas-tty.lua).
|
||||
-- It is the terminal's defaults with the LLeMbas layer applied. A person's
|
||||
-- own file starts from the same four lines.
|
||||
local wezterm = require 'wezterm'
|
||||
local config = wezterm.config_builder()
|
||||
require('llembas').apply(config)
|
||||
return config
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,655 @@
|
||||
-- LLeMbas TTY: the LLeMbas layer.
|
||||
--
|
||||
-- local wezterm = require 'wezterm'
|
||||
-- local config = wezterm.config_builder()
|
||||
-- require('llembas').apply(config) -- or apply(config, { … })
|
||||
-- return config
|
||||
--
|
||||
-- A plain terminal by default: applying the layer binds keys, adds entries to
|
||||
-- the command palette and registers event handlers, and that is all. No
|
||||
-- process is started, no text of any pane is read and nothing leaves the
|
||||
-- machine until the person presses one of those keys or picks one of those
|
||||
-- entries. The session bar reads only the variables that a program in the
|
||||
-- pane set for the terminal (OSC 1337 SetUserVar), never the pane's text.
|
||||
--
|
||||
-- Everything that decides something is in llembas.core (pure, tested);
|
||||
-- this file is the part that talks to the terminal.
|
||||
|
||||
local wezterm = require 'wezterm'
|
||||
local core = require 'llembas.core'
|
||||
|
||||
local M = {}
|
||||
M.core = core
|
||||
|
||||
local act = wezterm.action
|
||||
local opts = core.defaults()
|
||||
local registered = false
|
||||
|
||||
-- Events of the layer. A key or a palette entry emits one of these.
|
||||
local EV = {
|
||||
ask = 'llembas-ask',
|
||||
ask_screen = 'llembas-ask-screen',
|
||||
ask_line = 'llembas-ask-line',
|
||||
ask_screen_line = 'llembas-ask-screen-line',
|
||||
new_session = 'llembas-new-session',
|
||||
resume = 'llembas-resume',
|
||||
resume_pick = 'llembas-resume-pick',
|
||||
toggle_display = 'llembas-toggle-display',
|
||||
private = 'llembas-private',
|
||||
login = 'llembas-login',
|
||||
dismiss = 'llembas-dismiss',
|
||||
}
|
||||
M.events = EV
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- State that outlives a configuration reload. wezterm.GLOBAL holds only
|
||||
-- strings, numbers, booleans and tables with string keys.
|
||||
|
||||
local function global(section)
|
||||
local name = 'llembas_' .. section
|
||||
if wezterm.GLOBAL[name] == nil then
|
||||
wezterm.GLOBAL[name] = {}
|
||||
end
|
||||
return wezterm.GLOBAL[name]
|
||||
end
|
||||
|
||||
local function pane_key(pane_id)
|
||||
return 'p' .. tostring(pane_id)
|
||||
end
|
||||
|
||||
function M.is_private(pane_id)
|
||||
return global('private')[pane_key(pane_id)] == true
|
||||
end
|
||||
|
||||
local function set_private(pane_id, on)
|
||||
global('private')[pane_key(pane_id)] = on and true or false
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Talking to the person
|
||||
|
||||
local function is_windows()
|
||||
return wezterm.target_triple:find('windows', 1, true) ~= nil
|
||||
end
|
||||
|
||||
-- A message in the terminal itself: an overlay with one line to dismiss it.
|
||||
local function tell(window, pane, message)
|
||||
wezterm.log_warn('LLeMbas: ' .. message:gsub('\r\n', ' '))
|
||||
window:perform_action(
|
||||
act.InputSelector {
|
||||
title = 'LLeMbas',
|
||||
description = message .. '\r\n',
|
||||
choices = { { label = 'OK', id = 'ok' } },
|
||||
action = act.EmitEvent(EV.dismiss),
|
||||
},
|
||||
pane
|
||||
)
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- The LLeMbas CLI
|
||||
|
||||
local function file_exists(path)
|
||||
local f = io.open(path, 'r')
|
||||
if f then
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- The path of the CLI, or nil. Looks at files only; starts nothing.
|
||||
function M.find_cli()
|
||||
local list = core.cli_candidates(opts.cli, wezterm.executable_dir, os.getenv 'PATH', is_windows())
|
||||
for _, candidate in ipairs(list) do
|
||||
if file_exists(candidate) then
|
||||
return candidate
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- The CLI, or nil after telling the person why not.
|
||||
local function need_cli(window, pane)
|
||||
local cli = M.find_cli()
|
||||
if cli then
|
||||
return cli
|
||||
end
|
||||
local told = global('told')
|
||||
if told.cli_missing then
|
||||
tell(window, pane, core.messages.cli_missing_short)
|
||||
else
|
||||
told.cli_missing = true
|
||||
tell(window, pane, core.messages.cli_missing)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Does this CLI know about terminals? Asked once per CLI path, at the first
|
||||
-- thing that needs it (never at startup). The decision itself is
|
||||
-- core.cli_supports_terminal.
|
||||
local function cli_knows_terminals(window, pane, cli)
|
||||
local cache = global('cli_version')
|
||||
local key = 'v:' .. cli
|
||||
local version = cache[key]
|
||||
if version == nil then
|
||||
local ok, stdout = wezterm.run_child_process { cli, '--version' }
|
||||
version = ok and core.one_line(stdout or '', 64) or ''
|
||||
cache[key] = version
|
||||
end
|
||||
local supports = core.cli_supports_terminal(version)
|
||||
if supports == false then
|
||||
tell(window, pane, string.format(core.messages.cli_too_old, version, core.MIN_CLI_VERSION))
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Panes
|
||||
|
||||
local function pane_session(pane)
|
||||
return core.session_from_vars(pane:get_user_vars())
|
||||
end
|
||||
|
||||
local function pane_cwd(pane)
|
||||
local ok, value = pcall(function()
|
||||
return pane:get_current_working_dir()
|
||||
end)
|
||||
if ok then
|
||||
return core.cwd_from(value)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- The LLeMbas pane of the tab that `pane` is in (another pane rather than
|
||||
-- `pane` itself when there are several), or nil.
|
||||
local function session_pane_of_tab(pane)
|
||||
local tab = pane:tab()
|
||||
if not tab then
|
||||
return nil
|
||||
end
|
||||
local by_id = {}
|
||||
local list = {}
|
||||
for _, p in ipairs(tab:panes()) do
|
||||
local id = p:pane_id()
|
||||
by_id[id] = p
|
||||
list[#list + 1] = { pane_id = id, user_vars = p:get_user_vars() }
|
||||
end
|
||||
local id = core.find_session_pane(list, pane:pane_id())
|
||||
return id and by_id[id] or nil
|
||||
end
|
||||
|
||||
local function is_local(pane)
|
||||
local ok, name = pcall(function()
|
||||
return pane:get_domain_name()
|
||||
end)
|
||||
return not ok or name == 'local'
|
||||
end
|
||||
|
||||
-- Start the CLI in a new pane beside `pane`.
|
||||
local function split_with(pane, args)
|
||||
return pane:split {
|
||||
direction = opts.split.direction,
|
||||
size = opts.split.size,
|
||||
args = args,
|
||||
cwd = pane_cwd(pane),
|
||||
}
|
||||
end
|
||||
|
||||
local function spawn_cli(window, pane, args)
|
||||
if opts.new_session_in == 'tab' then
|
||||
window:perform_action(act.SpawnCommandInNewTab { args = args, cwd = pane_cwd(pane) }, pane)
|
||||
return nil
|
||||
end
|
||||
return split_with(pane, args)
|
||||
end
|
||||
|
||||
-- Text for a session that is still starting: it is sent when the pane first
|
||||
-- says that it is idle (user-var-changed, below), and dropped after a minute.
|
||||
local PENDING_SECONDS = 60
|
||||
|
||||
local function send_when_ready(pane, kind, text)
|
||||
local key = pane_key(pane:pane_id())
|
||||
global('pending_kind')[key] = kind
|
||||
global('pending_at')[key] = os.time()
|
||||
global('pending_text')[key] = text
|
||||
end
|
||||
|
||||
local function send_question(pane, question, context_path)
|
||||
pane:send_text(core.ask_bytes(question, context_path))
|
||||
end
|
||||
|
||||
local function deliver_pending(pane)
|
||||
local key = pane_key(pane:pane_id())
|
||||
local texts = global('pending_text')
|
||||
local text = texts[key]
|
||||
if type(text) ~= 'string' or text == '' then
|
||||
return
|
||||
end
|
||||
texts[key] = ''
|
||||
local at = global('pending_at')[key]
|
||||
if type(at) ~= 'number' or os.time() - at > PENDING_SECONDS then
|
||||
return
|
||||
end
|
||||
if global('pending_kind')[key] == 'question' then
|
||||
send_question(pane, text)
|
||||
else
|
||||
pane:send_text(text .. '\r')
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Terminal context
|
||||
|
||||
-- The directory the context files live in: the terminal's own runtime
|
||||
-- directory (where its socket is), which only the person can read.
|
||||
local function runtime_dir()
|
||||
local sock = os.getenv 'LLEMBAS_TTY_UNIX_SOCKET'
|
||||
if sock and sock ~= '' then
|
||||
local dir = sock:match('^(.*)[/\\][^/\\]+$')
|
||||
if dir and dir ~= '' then
|
||||
return dir
|
||||
end
|
||||
end
|
||||
local xdg = os.getenv 'XDG_RUNTIME_DIR'
|
||||
if xdg and xdg ~= '' then
|
||||
return xdg .. '/llembas-tty'
|
||||
end
|
||||
return wezterm.home_dir .. '/.local/share/llembas-tty'
|
||||
end
|
||||
|
||||
local function random_hex()
|
||||
local f = io.open('/dev/urandom', 'rb')
|
||||
if f then
|
||||
local bytes = f:read(16)
|
||||
f:close()
|
||||
if bytes and #bytes == 16 then
|
||||
return core.hex(bytes)
|
||||
end
|
||||
end
|
||||
local parts = {}
|
||||
for i = 1, 4 do
|
||||
parts[i] = string.format('%08x', math.random(0, 0x7fffffff))
|
||||
end
|
||||
return table.concat(parts)
|
||||
end
|
||||
|
||||
local function sweep(dir, now)
|
||||
local ok, entries = pcall(wezterm.read_dir, dir)
|
||||
if not ok or type(entries) ~= 'table' then
|
||||
return
|
||||
end
|
||||
for _, path in ipairs(entries) do
|
||||
if core.is_stale_context_file(path, now) then
|
||||
os.remove(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- What the pane shows, as the table of the context file; or nil and why not.
|
||||
-- explicit_screen: the person asked about the screen itself, so the visible
|
||||
-- screen is taken even from a full-screen program.
|
||||
function M.gather_context(pane, explicit_screen)
|
||||
if not opts.context.enabled then
|
||||
return nil, 'off'
|
||||
end
|
||||
if M.is_private(pane:pane_id()) then
|
||||
return nil, 'private'
|
||||
end
|
||||
local meta = pane:get_metadata() or {}
|
||||
if meta.password_input then
|
||||
return nil, 'password'
|
||||
end
|
||||
|
||||
local limits = opts.context
|
||||
local alt = pane:is_alt_screen_active()
|
||||
local blocks = core.array {}
|
||||
local screen
|
||||
|
||||
-- Asked about the screen: the screen alone. Otherwise the command blocks,
|
||||
-- and the screen only when the shell marks none. A full-screen program
|
||||
-- (the alternate screen) gives nothing unless asked.
|
||||
local want_screen
|
||||
if alt then
|
||||
want_screen = explicit_screen or limits.alt_screen
|
||||
elseif explicit_screen then
|
||||
want_screen = true
|
||||
else
|
||||
blocks = core.blocks_from_zones(pane:get_semantic_zones(), function(zone)
|
||||
return pane:get_text_from_semantic_zone(zone)
|
||||
end, limits)
|
||||
want_screen = #blocks == 0
|
||||
end
|
||||
if want_screen then
|
||||
screen = core.tail(core.clean(pane:get_lines_as_text(), true), limits.screen_lines, limits.output_bytes)
|
||||
end
|
||||
|
||||
local shell
|
||||
local ok, program = pcall(function()
|
||||
return pane:get_foreground_process_name()
|
||||
end)
|
||||
if ok then
|
||||
shell = core.shell_name(program)
|
||||
end
|
||||
|
||||
return core.context {
|
||||
pane = pane:pane_id(),
|
||||
cwd = pane_cwd(pane),
|
||||
shell = shell,
|
||||
blocks = blocks,
|
||||
screen = screen,
|
||||
}
|
||||
end
|
||||
|
||||
-- Write a context to a new file that only the person can read.
|
||||
-- Returns its path, or nil and why not.
|
||||
local function write_context(ctx)
|
||||
local dir = runtime_dir()
|
||||
local now = os.time()
|
||||
sweep(dir, now)
|
||||
local json = core.encode_context(ctx)
|
||||
local sep = is_windows() and '\\' or '/'
|
||||
local path = dir .. sep .. core.context_file_name(now, random_hex())
|
||||
|
||||
-- Made empty first and closed to everybody else before anything is written.
|
||||
local f, err = io.open(path, 'w')
|
||||
if not f then
|
||||
return nil, tostring(err)
|
||||
end
|
||||
f:close()
|
||||
if not is_windows() then
|
||||
local ok = wezterm.run_child_process { 'chmod', '600', path }
|
||||
if not ok then
|
||||
os.remove(path)
|
||||
return nil, 'chmod failed'
|
||||
end
|
||||
end
|
||||
f, err = io.open(path, 'w')
|
||||
if not f then
|
||||
os.remove(path)
|
||||
return nil, tostring(err)
|
||||
end
|
||||
f:write(json)
|
||||
f:close()
|
||||
return path
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Ask the model
|
||||
|
||||
local function ask(window, pane, line, explicit_screen)
|
||||
local question = core.question_text(line or '')
|
||||
if question == '' then
|
||||
return
|
||||
end
|
||||
local cli = need_cli(window, pane)
|
||||
if not cli then
|
||||
return
|
||||
end
|
||||
if not is_local(pane) then
|
||||
tell(window, pane, core.messages.remote)
|
||||
return
|
||||
end
|
||||
if not cli_knows_terminals(window, pane, cli) then
|
||||
return
|
||||
end
|
||||
|
||||
-- Asked from inside the LLeMbas pane: it is simply typed there.
|
||||
if pane_session(pane) then
|
||||
send_question(pane, question)
|
||||
return
|
||||
end
|
||||
|
||||
local path
|
||||
local ctx, why = M.gather_context(pane, explicit_screen)
|
||||
if ctx then
|
||||
local err
|
||||
path, err = write_context(ctx)
|
||||
if not path then
|
||||
tell(window, pane, string.format(core.messages.write_failed, core.one_line(err or '', 120)))
|
||||
end
|
||||
elseif why == 'private' then
|
||||
tell(window, pane, core.messages.private)
|
||||
elseif why == 'password' then
|
||||
tell(window, pane, core.messages.password)
|
||||
end
|
||||
|
||||
local target = session_pane_of_tab(pane)
|
||||
if target then
|
||||
send_question(target, question, path)
|
||||
return
|
||||
end
|
||||
|
||||
local args = { cli }
|
||||
if path then
|
||||
args[#args + 1] = '--terminal-context'
|
||||
args[#args + 1] = path
|
||||
end
|
||||
local new_pane = split_with(pane, args)
|
||||
if new_pane then
|
||||
send_when_ready(new_pane, 'question', question)
|
||||
end
|
||||
end
|
||||
|
||||
local function prompt_for(event, description)
|
||||
return function(window, pane)
|
||||
window:perform_action(
|
||||
act.PromptInputLine {
|
||||
description = description,
|
||||
prompt = 'ask> ',
|
||||
action = act.EmitEvent(event),
|
||||
},
|
||||
pane
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- Sessions
|
||||
|
||||
local function new_session(window, pane)
|
||||
local cli = need_cli(window, pane)
|
||||
if cli then
|
||||
spawn_cli(window, pane, { cli })
|
||||
end
|
||||
end
|
||||
|
||||
local function login(window, pane)
|
||||
local cli = need_cli(window, pane)
|
||||
if cli then
|
||||
split_with(pane, { cli, 'login' })
|
||||
end
|
||||
end
|
||||
|
||||
local function resume(window, pane)
|
||||
local cli = need_cli(window, pane)
|
||||
if not cli then
|
||||
return
|
||||
end
|
||||
local choices
|
||||
local ok, stdout = wezterm.run_child_process { cli, 'sessions', '--json' }
|
||||
if ok and type(stdout) == 'string' then
|
||||
local decode = wezterm.serde and wezterm.serde.json_decode or wezterm.json_parse
|
||||
local parsed, decoded = pcall(decode, stdout)
|
||||
if parsed then
|
||||
choices = core.session_choices(decoded)
|
||||
end
|
||||
end
|
||||
if choices then
|
||||
window:perform_action(
|
||||
act.InputSelector {
|
||||
title = 'LLeMbas: resume a session',
|
||||
choices = choices,
|
||||
fuzzy = true,
|
||||
action = act.EmitEvent(EV.resume_pick),
|
||||
},
|
||||
pane
|
||||
)
|
||||
return
|
||||
end
|
||||
-- A CLI with no list for programs: its own session list, in a new pane.
|
||||
local new_pane = split_with(pane, { cli })
|
||||
if new_pane then
|
||||
send_when_ready(new_pane, 'command', '/sessions')
|
||||
end
|
||||
end
|
||||
|
||||
local function resume_pick(window, pane, id)
|
||||
if not core.is_session_id(id) then
|
||||
return
|
||||
end
|
||||
local cli = need_cli(window, pane)
|
||||
if cli then
|
||||
spawn_cli(window, pane, { cli, '-s', id })
|
||||
end
|
||||
end
|
||||
|
||||
local function toggle_display(window, pane)
|
||||
local target = pane_session(pane) and pane or session_pane_of_tab(pane)
|
||||
if not target then
|
||||
tell(window, pane, core.messages.no_session_pane)
|
||||
return
|
||||
end
|
||||
window:perform_action(act.SendKey { key = 'd', mods = 'ALT' }, target)
|
||||
end
|
||||
|
||||
local function toggle_private(window, pane)
|
||||
local id = pane:pane_id()
|
||||
local on = not M.is_private(id)
|
||||
set_private(id, on)
|
||||
if not opts.session_bar then
|
||||
tell(window, pane, on and core.messages.private_on or core.messages.private_off)
|
||||
end
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- The session bar and the tab mark
|
||||
|
||||
local function update_status(window, pane)
|
||||
local shown = global('bar')
|
||||
local key = 'w' .. tostring(window:window_id())
|
||||
local items = core.bar_items(pane_session(pane), opts.bar.fields, M.is_private(pane:pane_id()))
|
||||
if items then
|
||||
window:set_right_status(wezterm.format(items))
|
||||
shown[key] = true
|
||||
elseif shown[key] then
|
||||
-- only what the layer itself put there is ever cleared
|
||||
window:set_right_status ''
|
||||
shown[key] = false
|
||||
end
|
||||
end
|
||||
|
||||
local function format_tab_title(tab, _, _, config, _, max_width)
|
||||
local show_index, zero_based = true, false
|
||||
pcall(function()
|
||||
show_index = config.show_tab_index_in_tab_bar
|
||||
zero_based = config.tab_and_split_indices_are_zero_based
|
||||
end)
|
||||
return core.tab_title(tab, { max_width = max_width, show_index = show_index, zero_based = zero_based })
|
||||
end
|
||||
|
||||
local PALETTE = {
|
||||
{ 'LLeMbas: ask the model', 'ask', 'md_comment_question_outline' },
|
||||
{ 'LLeMbas: ask about this screen', 'ask_screen', 'md_monitor_eye' },
|
||||
{ 'LLeMbas: new session here', 'new_session', 'md_plus_box_outline' },
|
||||
{ 'LLeMbas: resume a session', 'resume', 'md_history' },
|
||||
{ 'LLeMbas: toggle side display', 'toggle_display', 'md_dock_right' },
|
||||
{ 'LLeMbas: private pane on/off', 'private', 'md_eye_off_outline' },
|
||||
{ 'LLeMbas: log in', 'login', 'md_login' },
|
||||
}
|
||||
|
||||
local function palette()
|
||||
local entries = {}
|
||||
for i, e in ipairs(PALETTE) do
|
||||
entries[i] = { brief = e[1], action = act.EmitEvent(EV[e[2]]), icon = e[3] }
|
||||
end
|
||||
return entries
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
local function register_events()
|
||||
if registered then
|
||||
return
|
||||
end
|
||||
registered = true
|
||||
|
||||
wezterm.on(EV.ask, prompt_for(EV.ask_line, 'Ask LLeMbas. It is given the last commands of this pane and their output.'))
|
||||
wezterm.on(EV.ask_screen, prompt_for(EV.ask_screen_line, 'Ask LLeMbas about what is on this screen.'))
|
||||
wezterm.on(EV.ask_line, function(window, pane, line)
|
||||
ask(window, pane, line, false)
|
||||
end)
|
||||
wezterm.on(EV.ask_screen_line, function(window, pane, line)
|
||||
ask(window, pane, line, true)
|
||||
end)
|
||||
wezterm.on(EV.new_session, new_session)
|
||||
wezterm.on(EV.resume, resume)
|
||||
wezterm.on(EV.resume_pick, resume_pick)
|
||||
wezterm.on(EV.toggle_display, toggle_display)
|
||||
wezterm.on(EV.private, toggle_private)
|
||||
wezterm.on(EV.login, login)
|
||||
wezterm.on(EV.dismiss, function() end)
|
||||
|
||||
wezterm.on('user-var-changed', function(_, pane, name, value)
|
||||
if name == 'lembas_state' and value == 'idle' then
|
||||
deliver_pending(pane)
|
||||
end
|
||||
end)
|
||||
|
||||
if opts.session_bar then
|
||||
wezterm.on('update-status', update_status)
|
||||
end
|
||||
if opts.tab_marker then
|
||||
wezterm.on('format-tab-title', format_tab_title)
|
||||
end
|
||||
if opts.palette then
|
||||
wezterm.on('augment-command-palette', palette)
|
||||
end
|
||||
end
|
||||
|
||||
local KEY_EVENTS = {
|
||||
ask = EV.ask,
|
||||
new_session = EV.new_session,
|
||||
resume = EV.resume,
|
||||
toggle_display = EV.toggle_display,
|
||||
private = EV.private,
|
||||
}
|
||||
|
||||
-- apply(config, options): add the layer to a configuration. Returns config.
|
||||
function M.apply(config, options)
|
||||
local warnings
|
||||
opts, warnings = core.options(options)
|
||||
for _, w in ipairs(warnings) do
|
||||
wezterm.log_warn('llembas: ' .. w)
|
||||
end
|
||||
M.options = opts
|
||||
if not opts.enabled then
|
||||
return config
|
||||
end
|
||||
|
||||
local keys = config.keys or {}
|
||||
for _, name in ipairs { 'ask', 'new_session', 'resume', 'toggle_display', 'private' } do
|
||||
local k = opts.keys[name]
|
||||
if k then
|
||||
keys[#keys + 1] = { key = k.key, mods = k.mods, action = act.EmitEvent(KEY_EVENTS[name]) }
|
||||
end
|
||||
end
|
||||
config.keys = keys
|
||||
|
||||
if opts.autocomplete then
|
||||
-- The shipped shell integration completes the prompt only when it sees this.
|
||||
local env = config.set_environment_variables or {}
|
||||
env.LLEMBAS_TTY_AUTOCOMPLETE = '1'
|
||||
local cli = M.find_cli()
|
||||
if cli then
|
||||
env.LLEMBAS_TTY_CLI = cli
|
||||
end
|
||||
config.set_environment_variables = env
|
||||
end
|
||||
|
||||
register_events()
|
||||
return config
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,3 @@
|
||||
# The verified LLeMbas CLI (scripts/fetch-cli.sh) and the packages built from it.
|
||||
/bin/
|
||||
/dist/
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<component type="desktop-application">
|
||||
<content_rating type="oars-1.0" />
|
||||
<id>eu.llembas.tty</id>
|
||||
<metadata_license>MIT</metadata_license>
|
||||
<project_license>MIT</project_license>
|
||||
<name>LLeMbas TTY</name>
|
||||
<summary>A terminal with LLeMbas built in</summary>
|
||||
<description>
|
||||
<p>
|
||||
LLeMbas TTY is a terminal emulator and multiplexer, a fork of WezTerm,
|
||||
with the LLeMbas agent built in. By default it is an ordinary terminal
|
||||
and nothing leaves the machine.
|
||||
</p>
|
||||
<p>
|
||||
On a key, it asks the model a question together with the last commands
|
||||
of the pane and their output, starts or resumes LLeMbas sessions beside
|
||||
your shell, and shows the session's model, mode and state in a bar.
|
||||
</p>
|
||||
</description>
|
||||
<launchable type="desktop-id">eu.llembas.tty.desktop</launchable>
|
||||
<url type="homepage">https://llembas.eu</url>
|
||||
<provides>
|
||||
<binary>llembas-tty</binary>
|
||||
</provides>
|
||||
</component>
|
||||
@@ -0,0 +1,11 @@
|
||||
[Desktop Entry]
|
||||
Name=LLeMbas TTY
|
||||
Comment=A terminal with LLeMbas built in
|
||||
Keywords=shell;prompt;command;commandline;cmd;terminal;agent;
|
||||
Icon=eu.llembas.tty
|
||||
StartupWMClass=eu.llembas.tty
|
||||
TryExec=llembas-tty
|
||||
Exec=llembas-tty start --cwd .
|
||||
Type=Application
|
||||
Categories=System;TerminalEmulator;Utility;
|
||||
Terminal=false
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="512" height="512" shape-rendering="crispEdges" role="img" aria-label="LLeMbas TTY"><title>LLeMbas TTY</title><rect width="24" height="24" rx="4.5" fill="#0B0D10" shape-rendering="geometricPrecision"/><rect x="12" y="2" width="5" height="1" fill="#0B0D10"/><rect x="10" y="3" width="2" height="1" fill="#0B0D10"/><rect x="12" y="3" width="1" height="1" fill="#B6F2A6"/><rect x="13" y="3" width="4" height="1" fill="#7EE081"/><rect x="17" y="3" width="1" height="1" fill="#0B0D10"/><rect x="8" y="4" width="2" height="1" fill="#0B0D10"/><rect x="10" y="4" width="2" height="1" fill="#B6F2A6"/><rect x="12" y="4" width="2" height="1" fill="#7EE081"/><rect x="14" y="4" width="2" height="1" fill="#D8FFD0"/><rect x="16" y="4" width="1" height="1" fill="#4FAE5A"/><rect x="17" y="4" width="1" height="1" fill="#0B0D10"/><rect x="7" y="5" width="1" height="1" fill="#0B0D10"/><rect x="8" y="5" width="3" height="1" fill="#B6F2A6"/><rect x="11" y="5" width="2" height="1" fill="#7EE081"/><rect x="13" y="5" width="2" height="1" fill="#D8FFD0"/><rect x="15" y="5" width="2" height="1" fill="#4FAE5A"/><rect x="17" y="5" width="1" height="1" fill="#0B0D10"/><rect x="7" y="6" width="1" height="1" fill="#0B0D10"/><rect x="8" y="6" width="2" height="1" fill="#B6F2A6"/><rect x="10" y="6" width="2" height="1" fill="#7EE081"/><rect x="12" y="6" width="2" height="1" fill="#D8FFD0"/><rect x="14" y="6" width="2" height="1" fill="#4FAE5A"/><rect x="16" y="6" width="1" height="1" fill="#0B0D10"/><rect x="6" y="7" width="1" height="1" fill="#0B0D10"/><rect x="7" y="7" width="2" height="1" fill="#B6F2A6"/><rect x="9" y="7" width="2" height="1" fill="#7EE081"/><rect x="11" y="7" width="2" height="1" fill="#D8FFD0"/><rect x="13" y="7" width="3" height="1" fill="#4FAE5A"/><rect x="16" y="7" width="1" height="1" fill="#0B0D10"/><rect x="6" y="8" width="1" height="1" fill="#0B0D10"/><rect x="7" y="8" width="1" height="1" fill="#B6F2A6"/><rect x="8" y="8" width="2" height="1" fill="#7EE081"/><rect x="10" y="8" width="2" height="1" fill="#D8FFD0"/><rect x="12" y="8" width="4" height="1" fill="#4FAE5A"/><rect x="16" y="8" width="1" height="1" fill="#0B0D10"/><rect x="5" y="9" width="1" height="1" fill="#0B0D10"/><rect x="6" y="9" width="1" height="1" fill="#B6F2A6"/><rect x="7" y="9" width="2" height="1" fill="#7EE081"/><rect x="9" y="9" width="2" height="1" fill="#D8FFD0"/><rect x="11" y="9" width="4" height="1" fill="#4FAE5A"/><rect x="15" y="9" width="1" height="1" fill="#0B0D10"/><rect x="5" y="10" width="1" height="1" fill="#0B0D10"/><rect x="6" y="10" width="2" height="1" fill="#7EE081"/><rect x="8" y="10" width="2" height="1" fill="#D8FFD0"/><rect x="10" y="10" width="4" height="1" fill="#4FAE5A"/><rect x="14" y="10" width="1" height="1" fill="#0B0D10"/><rect x="5" y="11" width="1" height="1" fill="#0B0D10"/><rect x="6" y="11" width="1" height="1" fill="#7EE081"/><rect x="7" y="11" width="2" height="1" fill="#D8FFD0"/><rect x="9" y="11" width="4" height="1" fill="#4FAE5A"/><rect x="13" y="11" width="1" height="1" fill="#0B0D10"/><rect x="5" y="12" width="1" height="1" fill="#0B0D10"/><rect x="6" y="12" width="2" height="1" fill="#D8FFD0"/><rect x="8" y="12" width="4" height="1" fill="#4FAE5A"/><rect x="12" y="12" width="1" height="1" fill="#0B0D10"/><rect x="5" y="13" width="1" height="1" fill="#0B0D10"/><rect x="6" y="13" width="1" height="1" fill="#7EE081"/><rect x="7" y="13" width="2" height="1" fill="#4FAE5A"/><rect x="9" y="13" width="3" height="1" fill="#0B0D10"/><rect x="4" y="14" width="1" height="1" fill="#0B0D10"/><rect x="5" y="14" width="1" height="1" fill="#4FAE5A"/><rect x="6" y="14" width="3" height="1" fill="#0B0D10"/><rect x="3" y="15" width="1" height="1" fill="#0B0D10"/><rect x="4" y="15" width="1" height="1" fill="#4FAE5A"/><rect x="5" y="15" width="1" height="1" fill="#0B0D10"/><rect x="2" y="16" width="1" height="1" fill="#0B0D10"/><rect x="3" y="16" width="1" height="1" fill="#4FAE5A"/><rect x="4" y="16" width="1" height="1" fill="#0B0D10"/><rect x="3" y="17" width="1" height="1" fill="#0B0D10"/><rect x="13" y="14" width="9" height="1" fill="#7BD88F"/><rect x="13" y="15" width="1" height="1" fill="#7BD88F"/><rect x="21" y="15" width="1" height="1" fill="#7BD88F"/><rect x="13" y="16" width="1" height="1" fill="#7BD88F"/><rect x="15" y="16" width="1" height="1" fill="#7BD88F"/><rect x="21" y="16" width="1" height="1" fill="#7BD88F"/><rect x="13" y="17" width="1" height="1" fill="#7BD88F"/><rect x="16" y="17" width="1" height="1" fill="#7BD88F"/><rect x="18" y="17" width="2" height="1" fill="#7BD88F"/><rect x="21" y="17" width="1" height="1" fill="#7BD88F"/><rect x="13" y="18" width="1" height="1" fill="#7BD88F"/><rect x="15" y="18" width="1" height="1" fill="#7BD88F"/><rect x="21" y="18" width="1" height="1" fill="#7BD88F"/><rect x="13" y="19" width="1" height="1" fill="#7BD88F"/><rect x="21" y="19" width="1" height="1" fill="#7BD88F"/><rect x="13" y="20" widtLine truncated
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
Executable
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env bash
|
||||
# Package LLeMbas TTY for Linux from a finished build: a .deb and a tarball with the same tree.
|
||||
#
|
||||
# llembas/packaging/package.sh [target-dir] [out-dir] (default: target, llembas/packaging/dist)
|
||||
#
|
||||
# Expects: the three release binaries in <target-dir>/release, and the verified LLeMbas CLI in
|
||||
# llembas/packaging/bin/lembas (scripts/fetch-cli.sh). Builds nothing itself.
|
||||
#
|
||||
# The tree (the tarball has it under llembas-tty-<version>/, the .deb under /):
|
||||
# usr/lib/llembas-tty/ llembas-tty, llembas-tty-gui, llembas-tty-mux-server, lembas
|
||||
# usr/bin/ links to the three terminal binaries (not to lembas: the CLI
|
||||
# a person installed themselves stays the one on PATH)
|
||||
# usr/share/llembas-tty/shell/ shell integration: llembas-tty.sh, wezterm.sh, autocomplete.*
|
||||
# usr/share/llembas-tty/lua/ the LLeMbas layer's source, to read (the binary has it built in)
|
||||
# usr/share/applications, metainfo, icons/hicolor
|
||||
# usr/share/doc/llembas-tty/ licences: ours and WezTerm's (LICENSE.md, licenses/), the
|
||||
# CLI's (LICENSES-lembas.txt), README, CHANGELOG
|
||||
# etc/profile.d/llembas-tty.sh (.deb only)
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/../.."
|
||||
|
||||
TARGET="${1:-target}"
|
||||
OUT="${2:-llembas/packaging/dist}"
|
||||
VERSION="$(tr -d '[:space:]' < VERSION)"
|
||||
ARCH="$(dpkg --print-architecture)"
|
||||
REL="$TARGET/release"
|
||||
CLI=llembas/packaging/bin/lembas
|
||||
|
||||
for b in llembas-tty llembas-tty-gui llembas-tty-mux-server; do
|
||||
[ -x "$REL/$b" ] || { echo "package: $REL/$b is not built" >&2; exit 1; }
|
||||
done
|
||||
[ -x "$CLI" ] || { echo "package: $CLI is missing (run scripts/fetch-cli.sh)" >&2; exit 1; }
|
||||
[ "$("$CLI" --version)" = "$(tr -d '[:space:]' < llembas-cli.version)" ] \
|
||||
|| { echo "package: $CLI is not the version in llembas-cli.version" >&2; exit 1; }
|
||||
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "${work:?}"' EXIT
|
||||
root="$work/root"
|
||||
|
||||
lib="$root/usr/lib/llembas-tty"
|
||||
share="$root/usr/share/llembas-tty"
|
||||
doc="$root/usr/share/doc/llembas-tty"
|
||||
install -d "$lib" "$root/usr/bin" "$share/shell" "$share/lua/llembas" "$doc"
|
||||
|
||||
for b in llembas-tty llembas-tty-gui llembas-tty-mux-server; do
|
||||
install -m755 -s "$REL/$b" "$lib/$b"
|
||||
ln -s "../lib/llembas-tty/$b" "$root/usr/bin/$b"
|
||||
done
|
||||
# Not stripped: the CLI is a compiled bundle that carries its program after the executable.
|
||||
install -m755 "$CLI" "$lib/lembas"
|
||||
|
||||
install -m644 llembas/shell/llembas-tty.sh llembas/shell/autocomplete.bash llembas/shell/autocomplete.zsh "$share/shell/"
|
||||
install -m644 assets/shell-integration/wezterm.sh "$share/shell/wezterm.sh"
|
||||
install -m644 llembas/lua/default-config.lua "$share/lua/default-config.lua"
|
||||
install -m644 llembas/lua/llembas/init.lua llembas/lua/llembas/core.lua "$share/lua/llembas/"
|
||||
|
||||
install -Dm644 llembas/packaging/eu.llembas.tty.desktop "$root/usr/share/applications/eu.llembas.tty.desktop"
|
||||
install -Dm644 llembas/packaging/eu.llembas.tty.appdata.xml "$root/usr/share/metainfo/eu.llembas.tty.appdata.xml"
|
||||
for size in 128 256 512; do
|
||||
install -Dm644 "llembas/packaging/icons/eu.llembas.tty-$size.png" \
|
||||
"$root/usr/share/icons/hicolor/${size}x${size}/apps/eu.llembas.tty.png"
|
||||
done
|
||||
install -Dm644 llembas/packaging/icons/eu.llembas.tty.svg "$root/usr/share/icons/hicolor/scalable/apps/eu.llembas.tty.svg"
|
||||
|
||||
install -m644 LICENSE.md README.md CHANGELOG.md "$doc/"
|
||||
install -d "$doc/licenses"
|
||||
install -m644 licenses/* "$doc/licenses/"
|
||||
"$CLI" --licenses > "$doc/LICENSES-lembas.txt"
|
||||
chmod 644 "$doc/LICENSES-lembas.txt"
|
||||
[ -s "$doc/LICENSES-lembas.txt" ] || { echo "package: the CLI printed no licences" >&2; exit 1; }
|
||||
|
||||
mkdir -p "$OUT"
|
||||
|
||||
# The tarball: the tree as it is, to unpack anywhere (the binaries find each other and the CLI
|
||||
# by their own location; source usr/share/llembas-tty/shell/llembas-tty.sh from the shell's rc).
|
||||
name="llembas-tty-$VERSION-linux-$ARCH"
|
||||
cp -a "$root" "$work/$name"
|
||||
tar -C "$work" --owner=0 --group=0 --numeric-owner -cJf "$OUT/$name.tar.xz" "$name"
|
||||
|
||||
# The .deb. Debian sorts 1.0.0-beta.1 above 1.0.0 (what follows the dash is a revision), so a
|
||||
# beta's package says ~beta, which sorts below its release.
|
||||
debver="${VERSION/-/\~}"
|
||||
install -Dm644 llembas/packaging/profile.sh "$root/etc/profile.d/llembas-tty.sh"
|
||||
install -d "$root/DEBIAN"
|
||||
mkdir -p "$work/shlibs/debian"
|
||||
: > "$work/shlibs/debian/control"
|
||||
depends="$(cd "$work/shlibs" && dpkg-shlibdeps -O -e "$lib/llembas-tty" -e "$lib/llembas-tty-gui" -e "$lib/llembas-tty-mux-server" 2>/dev/null | sed -n 's/^shlibs:Depends=//p')"
|
||||
[ -n "$depends" ] || { echo "package: could not work out the library dependencies" >&2; exit 1; }
|
||||
cat > "$root/DEBIAN/control" <<CONTROL
|
||||
Package: llembas-tty
|
||||
Version: $debver
|
||||
Architecture: $ARCH
|
||||
Maintainer: LLeMbas <houmeres@houmeres.sk>
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Homepage: https://llembas.eu
|
||||
Depends: $depends
|
||||
Description: A terminal with LLeMbas built in
|
||||
LLeMbas TTY is a terminal emulator and multiplexer, a fork of WezTerm,
|
||||
with the LLeMbas agent built in. By default it is an ordinary terminal.
|
||||
It installs beside WezTerm and shares nothing with it.
|
||||
CONTROL
|
||||
echo "/etc/profile.d/llembas-tty.sh" > "$root/DEBIAN/conffiles"
|
||||
dpkg-deb --root-owner-group -b "$root" "$OUT/llembas-tty_${debver}_${ARCH}.deb" >/dev/null
|
||||
base="${VERSION%%-*}"
|
||||
if [ "$VERSION" != "$base" ]; then
|
||||
dpkg --compare-versions "$debver" lt "$base" || { echo "package: $debver does not sort below $base" >&2; exit 1; }
|
||||
fi
|
||||
|
||||
ls -l "$OUT"
|
||||
@@ -0,0 +1,6 @@
|
||||
# shellcheck shell=sh
|
||||
# LLeMbas TTY: installed as /etc/profile.d/llembas-tty.sh. Does nothing outside LLeMbas TTY.
|
||||
if [ -n "${LLEMBAS_TTY-}" ] && [ -r /usr/share/llembas-tty/shell/llembas-tty.sh ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. /usr/share/llembas-tty/shell/llembas-tty.sh
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
# shellcheck shell=bash
|
||||
# LLeMbas TTY: prompt autocomplete for bash, on demand.
|
||||
#
|
||||
# bash cannot draw a suggestion after the cursor, so this is a key: press it
|
||||
# and the rest of the line is asked from LLeMbas and put on the line. Nothing
|
||||
# runs: you still press Enter yourself.
|
||||
#
|
||||
# key: Ctrl+X Ctrl+A (set LLEMBAS_TTY_AUTOCOMPLETE_KEY to a readline key
|
||||
# sequence before this file is sourced to change it)
|
||||
#
|
||||
# Active only inside LLeMbas TTY. Loaded by llembas-tty.sh when autocomplete is
|
||||
# on, or source this file yourself. The line so far goes to
|
||||
# `lembas complete --shell bash` on stdin; nothing is sent for an empty line,
|
||||
# for a line that starts with a space, or when the cursor is not at the end.
|
||||
|
||||
if [ -z "${LLEMBAS_TTY-}" ] || [ -z "${BASH_VERSION-}" ]; then
|
||||
return 0
|
||||
fi
|
||||
case "$-" in
|
||||
*i*) ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
|
||||
__llembas_complete_line() {
|
||||
local line="$READLINE_LINE" rest cli="${LLEMBAS_TTY_CLI:-lembas}"
|
||||
[ -n "$line" ] || return 0
|
||||
case "$line" in
|
||||
' '* | *$'\n'*) return 0 ;;
|
||||
esac
|
||||
[ "$READLINE_POINT" -eq "${#line}" ] || return 0
|
||||
[ "${#line}" -le 2000 ] || return 0
|
||||
command -v "$cli" >/dev/null 2>&1 || return 0
|
||||
rest="$(printf '%s' "$line" | "$cli" complete --shell bash --cwd "$PWD" --timeout-ms 2500 2>/dev/null)" || return 0
|
||||
# What comes back is a model's text: one line, no control characters, not endless.
|
||||
rest="${rest%%$'\n'*}"
|
||||
rest="${rest//[[:cntrl:]]/}"
|
||||
rest="${rest:0:500}"
|
||||
[ -n "$rest" ] || return 0
|
||||
READLINE_LINE="$line$rest"
|
||||
READLINE_POINT="${#READLINE_LINE}"
|
||||
}
|
||||
|
||||
bind -x "\"${LLEMBAS_TTY_AUTOCOMPLETE_KEY:-\\C-x\\C-a}\": __llembas_complete_line"
|
||||
@@ -0,0 +1,154 @@
|
||||
# LLeMbas TTY: prompt autocomplete for zsh, as ghost text.
|
||||
#
|
||||
# While you type, the rest of the line is asked from LLeMbas
|
||||
# (`lembas complete --shell zsh`, the line so far on stdin) and shown dimmed
|
||||
# after the cursor. Right arrow or End takes it; any other key drops it.
|
||||
# Nothing runs: you still press Enter yourself.
|
||||
#
|
||||
# Active only inside LLeMbas TTY. Loaded by llembas-tty.sh when autocomplete is
|
||||
# on (LLEMBAS_TTY_AUTOCOMPLETE=1), or source this file yourself.
|
||||
#
|
||||
# Nothing is sent: for an empty line, for a line that starts with a space, for
|
||||
# a line of several lines, when the cursor is not at the end, or before you
|
||||
# have paused typing (LLEMBAS_TTY_AUTOCOMPLETE_DELAY, hundredths of a second,
|
||||
# default 35). A request still running when you type again is stopped.
|
||||
#
|
||||
# The request runs beside the line editor (a process substitution watched
|
||||
# with `zle -F`), so typing never waits for it.
|
||||
|
||||
[[ -n ${LLEMBAS_TTY-} && -n ${ZSH_VERSION-} && -o interactive ]] || return 0
|
||||
(( ${+__llembas_ac_loaded} )) && return 0
|
||||
typeset -g __llembas_ac_loaded=1
|
||||
|
||||
zmodload zsh/system 2>/dev/null || return 0
|
||||
zmodload zsh/zselect 2>/dev/null || return 0
|
||||
autoload -Uz add-zle-hook-widget add-zsh-hook 2>/dev/null || return 0
|
||||
|
||||
typeset -g __llembas_ac_fd= __llembas_ac_pid= __llembas_ac_for= __llembas_ac_seen=
|
||||
typeset -g __llembas_ac_text= __llembas_ac_hl= __llembas_ac_off=
|
||||
|
||||
__llembas_ac_stop() {
|
||||
if [[ -n $__llembas_ac_fd ]]; then
|
||||
zle -F $__llembas_ac_fd 2>/dev/null
|
||||
exec {__llembas_ac_fd}<&-
|
||||
__llembas_ac_fd=
|
||||
fi
|
||||
if [[ -n $__llembas_ac_pid ]]; then
|
||||
kill -TERM $__llembas_ac_pid 2>/dev/null
|
||||
__llembas_ac_pid=
|
||||
fi
|
||||
}
|
||||
|
||||
__llembas_ac_clear() {
|
||||
if [[ -n $__llembas_ac_text ]]; then
|
||||
POSTDISPLAY=
|
||||
__llembas_ac_text=
|
||||
fi
|
||||
if [[ -n $__llembas_ac_hl ]]; then
|
||||
region_highlight=("${(@)region_highlight:#$__llembas_ac_hl}")
|
||||
__llembas_ac_hl=
|
||||
fi
|
||||
}
|
||||
|
||||
__llembas_ac_request() {
|
||||
__llembas_ac_stop
|
||||
[[ -z $__llembas_ac_off ]] || return 0
|
||||
local line=$BUFFER cli=${LLEMBAS_TTY_CLI:-lembas}
|
||||
[[ -n $line && $line != ' '* && $line != *$'\n'* ]] || return 0
|
||||
(( CURSOR == ${#line} && ${#line} <= 2000 )) || return 0
|
||||
(( ${+commands[$cli]} )) || [[ -x $cli ]] || return 0
|
||||
|
||||
__llembas_ac_for=$line
|
||||
local delay=${LLEMBAS_TTY_AUTOCOMPLETE_DELAY:-35} dir=$PWD
|
||||
exec {__llembas_ac_fd}< <(
|
||||
# our process id first, so that the request can be stopped
|
||||
print -r -- $sysparams[pid]
|
||||
# wait for a pause in the typing; a keystroke stops us here
|
||||
zselect -t $delay
|
||||
exec $cli complete --shell zsh --cwd $dir --timeout-ms 2500 2>/dev/null < <(print -rn -- $line)
|
||||
)
|
||||
# (as zsh-autosuggestions found: without a fork here, Ctrl+C can stop working)
|
||||
command true
|
||||
IFS= read -r -u $__llembas_ac_fd __llembas_ac_pid
|
||||
zle -F $__llembas_ac_fd __llembas_ac_ready
|
||||
}
|
||||
|
||||
__llembas_ac_ready() {
|
||||
local fd=$1 rest=
|
||||
if [[ -z ${2-} || ${2-} == hup ]]; then
|
||||
IFS= read -r -u $fd rest
|
||||
fi
|
||||
zle -F $fd 2>/dev/null
|
||||
exec {fd}<&-
|
||||
__llembas_ac_fd= __llembas_ac_pid=
|
||||
|
||||
# The line editor's variables can only be changed from a widget.
|
||||
zle __llembas_ac_show -- "$rest"
|
||||
}
|
||||
|
||||
__llembas_ac_show() {
|
||||
local rest=${1-}
|
||||
# only for the line it was asked for, still unchanged
|
||||
[[ $BUFFER == $__llembas_ac_for ]] && (( CURSOR == ${#BUFFER} )) || return 0
|
||||
# what came back is a model's text: one line, no control characters, not endless
|
||||
rest=${rest//[[:cntrl:]]/}
|
||||
rest=${rest[1,500]}
|
||||
[[ -n $rest ]] || return 0
|
||||
|
||||
__llembas_ac_text=$rest
|
||||
POSTDISPLAY=$rest
|
||||
__llembas_ac_hl="${#BUFFER} $(( ${#BUFFER} + ${#POSTDISPLAY} )) ${LLEMBAS_TTY_AUTOCOMPLETE_STYLE:-fg=8}"
|
||||
region_highlight+=("$__llembas_ac_hl")
|
||||
zle -R
|
||||
}
|
||||
|
||||
# Before each redraw: when the line changed, the suggestion is for another
|
||||
# line. Drop it and ask again.
|
||||
__llembas_ac_redraw() {
|
||||
[[ $BUFFER == $__llembas_ac_seen ]] && return 0
|
||||
__llembas_ac_seen=$BUFFER
|
||||
__llembas_ac_clear
|
||||
__llembas_ac_request
|
||||
}
|
||||
|
||||
__llembas_ac_finish() {
|
||||
__llembas_ac_stop
|
||||
__llembas_ac_clear
|
||||
__llembas_ac_seen=
|
||||
}
|
||||
|
||||
__llembas_ac_take() {
|
||||
if [[ -n $__llembas_ac_text ]] && (( CURSOR == ${#BUFFER} )); then
|
||||
local text=$__llembas_ac_text
|
||||
__llembas_ac_clear
|
||||
BUFFER+=$text
|
||||
CURSOR=${#BUFFER}
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
__llembas_ac_forward_char() {
|
||||
__llembas_ac_take || zle .forward-char
|
||||
}
|
||||
|
||||
__llembas_ac_end_of_line() {
|
||||
__llembas_ac_take || zle .end-of-line
|
||||
}
|
||||
|
||||
# zsh-autosuggestions draws in the same place. With it loaded, ours stays off
|
||||
# unless asked for by name (LLEMBAS_TTY_AUTOCOMPLETE_FORCE=1).
|
||||
__llembas_ac_check() {
|
||||
add-zsh-hook -d precmd __llembas_ac_check
|
||||
if (( ${+functions[_zsh_autosuggest_start]} )) && [[ ${LLEMBAS_TTY_AUTOCOMPLETE_FORCE-} != 1 ]]; then
|
||||
__llembas_ac_off=1
|
||||
print -u2 -r -- "llembas-tty: prompt autocomplete is off because zsh-autosuggestions is loaded (set LLEMBAS_TTY_AUTOCOMPLETE_FORCE=1 to use both)"
|
||||
fi
|
||||
}
|
||||
|
||||
zle -N __llembas_ac_show
|
||||
zle -N forward-char __llembas_ac_forward_char
|
||||
zle -N end-of-line __llembas_ac_end_of_line
|
||||
add-zle-hook-widget line-pre-redraw __llembas_ac_redraw
|
||||
add-zle-hook-widget line-finish __llembas_ac_finish
|
||||
add-zsh-hook precmd __llembas_ac_check
|
||||
@@ -0,0 +1,59 @@
|
||||
# shellcheck shell=bash
|
||||
# LLeMbas TTY: shell integration for bash and zsh.
|
||||
#
|
||||
# Sourced from /etc/profile.d by the package; or source it from ~/.bashrc or
|
||||
# ~/.zshrc (zsh does not read /etc/profile.d on every system):
|
||||
#
|
||||
# [ -n "$LLEMBAS_TTY" ] && . /usr/share/llembas-tty/shell/llembas-tty.sh
|
||||
#
|
||||
# It does two things, and only inside LLeMbas TTY, only in an interactive shell:
|
||||
#
|
||||
# 1. Semantic zones and the working directory (OSC 133, OSC 7), by WezTerm's
|
||||
# own integration script, shipped beside this file as wezterm.sh. That is
|
||||
# what lets the terminal tell one command and its output from the next.
|
||||
# The WEZTERM_SHELL_SKIP_* variables documented in that file apply.
|
||||
# 2. Prompt autocomplete, when it was turned on (`autocomplete = true` in the
|
||||
# LLeMbas layer's options exports LLEMBAS_TTY_AUTOCOMPLETE=1). Off by default.
|
||||
|
||||
if [ -z "${LLEMBAS_TTY-}" ]; then
|
||||
return 0
|
||||
fi
|
||||
# shellcheck disable=SC2166
|
||||
if [ -z "${BASH_VERSION-}" -a -z "${ZSH_NAME-}" ]; then
|
||||
return 0
|
||||
fi
|
||||
case "$-" in
|
||||
*i*) ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
|
||||
if [ -n "${ZSH_NAME-}" ]; then
|
||||
# shellcheck disable=SC2296,SC2298 # zsh: the file being sourced
|
||||
__llembas_tty_dir="${${(%):-%x}:A:h}"
|
||||
else
|
||||
__llembas_tty_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
fi
|
||||
if [ -n "${LLEMBAS_TTY_SHELL_DIR-}" ]; then
|
||||
__llembas_tty_dir="$LLEMBAS_TTY_SHELL_DIR"
|
||||
fi
|
||||
|
||||
# Not twice: a WezTerm installed beside us may have loaded the same script.
|
||||
if ! typeset -f __wezterm_semantic_precmd >/dev/null 2>&1; then
|
||||
if [ -r "$__llembas_tty_dir/wezterm.sh" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$__llembas_tty_dir/wezterm.sh"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${LLEMBAS_TTY_AUTOCOMPLETE-}" = "1" ]; then
|
||||
if [ -n "${ZSH_NAME-}" ] && [ -r "$__llembas_tty_dir/autocomplete.zsh" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$__llembas_tty_dir/autocomplete.zsh"
|
||||
elif [ -n "${BASH_VERSION-}" ] && [ -r "$__llembas_tty_dir/autocomplete.bash" ]; then
|
||||
# shellcheck source=/dev/null
|
||||
. "$__llembas_tty_dir/autocomplete.bash"
|
||||
fi
|
||||
fi
|
||||
|
||||
unset __llembas_tty_dir
|
||||
true
|
||||
@@ -0,0 +1,184 @@
|
||||
-- LLeMbas TTY: a stand-in for the terminal's `wezterm` module, for the tests.
|
||||
-- It records what the layer asks the terminal to do and does none of it,
|
||||
-- except chmod, which is run for real so that the file mode can be checked.
|
||||
|
||||
local F = {}
|
||||
|
||||
function F.new(env)
|
||||
env = env or {}
|
||||
local w = {
|
||||
GLOBAL = {},
|
||||
target_triple = env.target_triple or 'x86_64-unknown-linux-gnu',
|
||||
executable_dir = env.executable_dir or '/nonexistent/bin',
|
||||
home_dir = env.home_dir or '/nonexistent/home',
|
||||
handlers = {},
|
||||
logs = {},
|
||||
spawned = {},
|
||||
child_results = env.child_results or {},
|
||||
}
|
||||
|
||||
-- wezterm.action.Name(args) and wezterm.action.Name { … } give a table
|
||||
-- that names the action; nothing more is needed to check what was bound.
|
||||
w.action = setmetatable({}, {
|
||||
__index = function(_, name)
|
||||
return function(args)
|
||||
return { action = name, args = args }
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
function w.on(name, fn)
|
||||
w.handlers[name] = w.handlers[name] or {}
|
||||
table.insert(w.handlers[name], fn)
|
||||
end
|
||||
|
||||
function w.emit(name, ...)
|
||||
local result
|
||||
for _, fn in ipairs(w.handlers[name] or {}) do
|
||||
result = fn(...)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function w.log_warn(...)
|
||||
w.logs[#w.logs + 1] = table.concat({ ... }, ' ')
|
||||
end
|
||||
w.log_info = w.log_warn
|
||||
w.log_error = w.log_warn
|
||||
|
||||
function w.config_builder()
|
||||
return {}
|
||||
end
|
||||
|
||||
function w.format(items)
|
||||
local out = {}
|
||||
for _, item in ipairs(items) do
|
||||
if type(item) == 'table' and item.Text then
|
||||
out[#out + 1] = item.Text
|
||||
end
|
||||
end
|
||||
return table.concat(out)
|
||||
end
|
||||
|
||||
function w.run_child_process(args)
|
||||
w.spawned[#w.spawned + 1] = args
|
||||
if args[1] == 'chmod' then
|
||||
local ok = os.execute(string.format("chmod %s '%s'", args[2], args[3]))
|
||||
return ok == true or ok == 0, '', ''
|
||||
end
|
||||
local key = table.concat(args, ' ', 2)
|
||||
local r = w.child_results[key]
|
||||
if r then
|
||||
return r[1], r[2], ''
|
||||
end
|
||||
return false, '', 'not found'
|
||||
end
|
||||
|
||||
function w.read_dir(dir)
|
||||
local list = {}
|
||||
local p = io.popen(string.format("ls -1 '%s' 2>/dev/null", dir))
|
||||
if p then
|
||||
for name in p:lines() do
|
||||
list[#list + 1] = dir .. '/' .. name
|
||||
end
|
||||
p:close()
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function w.json_parse(text)
|
||||
if env.json_parse then
|
||||
return env.json_parse(text)
|
||||
end
|
||||
error 'not json'
|
||||
end
|
||||
|
||||
return w
|
||||
end
|
||||
|
||||
-- A pane that records what is sent to it.
|
||||
function F.pane(spec)
|
||||
local p = {
|
||||
id = spec.id or 1,
|
||||
vars = spec.vars or {},
|
||||
sent = {},
|
||||
splits = {},
|
||||
spec = spec,
|
||||
}
|
||||
function p:pane_id()
|
||||
return self.id
|
||||
end
|
||||
function p:get_user_vars()
|
||||
return self.vars
|
||||
end
|
||||
function p:get_metadata()
|
||||
return spec.metadata
|
||||
end
|
||||
function p:is_alt_screen_active()
|
||||
return spec.alt == true
|
||||
end
|
||||
function p:get_semantic_zones()
|
||||
self.read_zones = true
|
||||
return spec.zones or {}
|
||||
end
|
||||
function p:get_text_from_semantic_zone(zone)
|
||||
self.read_text = true
|
||||
return zone.text
|
||||
end
|
||||
function p:get_lines_as_text()
|
||||
self.read_screen = true
|
||||
return spec.screen or ''
|
||||
end
|
||||
function p:get_current_working_dir()
|
||||
return spec.cwd
|
||||
end
|
||||
function p:get_foreground_process_name()
|
||||
return spec.program
|
||||
end
|
||||
function p:get_domain_name()
|
||||
return spec.domain or 'local'
|
||||
end
|
||||
function p:tab()
|
||||
return spec.tab
|
||||
end
|
||||
function p:send_text(text)
|
||||
self.sent[#self.sent + 1] = { 'text', text }
|
||||
end
|
||||
function p:send_paste(text)
|
||||
self.sent[#self.sent + 1] = { 'paste', text }
|
||||
end
|
||||
function p:split(args)
|
||||
self.splits[#self.splits + 1] = args
|
||||
local new = F.pane { id = (spec.next_id or 100) + #self.splits }
|
||||
self.last_split = new
|
||||
return new
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
function F.tab(panes)
|
||||
local t = { list = panes }
|
||||
function t:panes()
|
||||
return self.list
|
||||
end
|
||||
for _, p in ipairs(panes) do
|
||||
p.spec.tab = t
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function F.window(id)
|
||||
local win = { id = id or 1, actions = {}, status = nil }
|
||||
function win:window_id()
|
||||
return self.id
|
||||
end
|
||||
function win:perform_action(action, pane)
|
||||
self.actions[#self.actions + 1] = { action = action, pane = pane }
|
||||
end
|
||||
function win:set_right_status(text)
|
||||
self.status = text
|
||||
end
|
||||
return win
|
||||
end
|
||||
|
||||
return F
|
||||
@@ -0,0 +1,929 @@
|
||||
-- LLeMbas TTY: tests of the LLeMbas layer, without a terminal.
|
||||
--
|
||||
-- scripts/test-lua.sh (finds a Lua and gives this a scratch directory)
|
||||
--
|
||||
-- Runs under Lua 5.1 (LuaJIT, `nvim -l`) and Lua 5.4. The layer's decisions
|
||||
-- are in llembas.core and are tested directly; llembas (init.lua) is run
|
||||
-- against a stand-in for the terminal (fake_wezterm.lua).
|
||||
|
||||
local here = (arg and arg[0] or 'llembas/tests/run.lua'):match('^(.*)[/\\][^/\\]+$') or '.'
|
||||
package.path = here .. '/?.lua;' .. here .. '/../lua/?.lua;' .. here .. '/../lua/?/init.lua;' .. package.path
|
||||
|
||||
local real_getenv = os.getenv
|
||||
local TMP = real_getenv 'LLEMBAS_TEST_TMP'
|
||||
if not TMP or TMP == '' then
|
||||
io.stderr:write 'run.lua: set LLEMBAS_TEST_TMP to an empty scratch directory (scripts/test-lua.sh does)\n'
|
||||
os.exit(2)
|
||||
end
|
||||
|
||||
local fake = require 'fake_wezterm'
|
||||
local core = require 'llembas.core'
|
||||
|
||||
local passed, failed = 0, 0
|
||||
local current = ''
|
||||
|
||||
local function show(v)
|
||||
if type(v) == 'string' then
|
||||
return string.format('%q', v)
|
||||
end
|
||||
return tostring(v)
|
||||
end
|
||||
|
||||
local function check(cond, what)
|
||||
if cond then
|
||||
passed = passed + 1
|
||||
else
|
||||
failed = failed + 1
|
||||
io.stderr:write(string.format('FAIL %s: %s\n', current, what or '?'))
|
||||
end
|
||||
end
|
||||
|
||||
local function eq(got, want, what)
|
||||
check(got == want, string.format('%s: got %s, want %s', what or 'value', show(got), show(want)))
|
||||
end
|
||||
|
||||
local function test(name, fn)
|
||||
current = name
|
||||
local ok, err = pcall(fn)
|
||||
if not ok then
|
||||
failed = failed + 1
|
||||
io.stderr:write(string.format('FAIL %s: error: %s\n', name, tostring(err)))
|
||||
end
|
||||
end
|
||||
|
||||
local function sh(cmd)
|
||||
local p = io.popen(cmd)
|
||||
local out = p:read '*a'
|
||||
p:close()
|
||||
return (out:gsub('%s+$', ''))
|
||||
end
|
||||
|
||||
local function read_file(path)
|
||||
local f = io.open(path, 'r')
|
||||
if not f then
|
||||
return nil
|
||||
end
|
||||
local s = f:read '*a'
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local function write_file(path, text)
|
||||
local f = assert(io.open(path, 'w'))
|
||||
f:write(text or '')
|
||||
f:close()
|
||||
end
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- core: text
|
||||
|
||||
test('clean removes control characters and escape sequences', function()
|
||||
eq(core.clean('a\27[31mb\7c', false), 'a[31mbc', 'ESC and BEL')
|
||||
eq(core.clean('a\nb\tc\rd', false), 'a b c d', 'one line')
|
||||
eq(core.clean('a\nb\tc\rd', true), 'a\nb\tcd', 'multi line keeps \\n and \\t')
|
||||
eq(core.clean('x\194\155y', false), 'xy', 'C1 CSI (U+009B)')
|
||||
eq(core.clean('x\194\157y', true), 'xy', 'C1 OSC (U+009D)')
|
||||
eq(core.clean('del\127!', false), 'del!', 'DEL')
|
||||
eq(core.clean(nil), '', 'nil')
|
||||
eq(core.clean(42), '', 'number')
|
||||
end)
|
||||
|
||||
test('clean keeps UTF-8 and replaces what is not', function()
|
||||
eq(core.clean('žltý kôň ✓ 🙂', false), 'žltý kôň ✓ 🙂', 'valid')
|
||||
eq(core.clean('a\255b', false), 'a\239\191\189b', 'invalid byte')
|
||||
eq(core.clean('a\226\130', false), 'a\239\191\189\239\191\189', 'cut sequence')
|
||||
eq(core.clean('\192\128', false), '\239\191\189\239\191\189', 'overlong NUL')
|
||||
eq(core.clean('\237\160\128', false), '\239\191\189\239\191\189\239\191\189', 'surrogate')
|
||||
end)
|
||||
|
||||
test('cap_chars and one_line', function()
|
||||
eq(core.cap_chars('abcdef', 3), 'abc…', 'cut')
|
||||
eq(core.cap_chars('abc', 3), 'abc', 'exact')
|
||||
eq(core.cap_chars('žžžž', 2), 'žž…', 'never inside a character')
|
||||
eq(core.one_line(' hi\27]0;x\7 there \n', 64), 'hi]0;x there', 'trimmed and cleaned')
|
||||
eq(#core.one_line(string.rep('x', 500)), 64 + #'…', 'default cap')
|
||||
end)
|
||||
|
||||
test('tail', function()
|
||||
eq(core.tail('a\nb\nc\nd', 2), 'c\nd', 'lines')
|
||||
eq(core.tail('a\nb\nc\nd\n', 2), 'c\nd\n', 'final newline is not a line')
|
||||
eq(core.tail('a\nb', 5), 'a\nb', 'fewer lines than asked')
|
||||
eq(core.tail('one\ntwo\nthree', nil, 7), 'three', 'bytes cut at a line start')
|
||||
eq(core.tail('abcdefgh', nil, 3), 'fgh', 'bytes, one line')
|
||||
eq(core.tail('až', nil, 1), '', 'never starts inside a character')
|
||||
eq(core.tail('', 3, 10), '', 'empty')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- core: JSON
|
||||
|
||||
test('json_encode', function()
|
||||
eq(core.json_encode { b = 1, a = 'x' }, '{"a":"x","b":1}', 'keys sorted')
|
||||
eq(core.json_encode({ b = 1, a = 'x' }, { 'b' }), '{"b":1,"a":"x"}', 'key order')
|
||||
eq(core.json_encode { 1, 'two', true, false }, '[1,"two",true,false]', 'array')
|
||||
eq(core.json_encode(core.array {}), '[]', 'empty array')
|
||||
eq(core.json_encode {}, '{}', 'empty object')
|
||||
eq(core.json_encode { x = core.null }, '{"x":null}', 'null')
|
||||
eq(core.json_encode 'a"b\\c\nd\te', '"a\\"b\\\\c\\nd\\te"', 'escapes')
|
||||
eq(core.json_encode 'a\27[0mb', '"a[0mb"', 'no control character reaches the file')
|
||||
eq(core.json_encode 'a\255', '"a\239\191\189"', 'invalid UTF-8 replaced')
|
||||
eq(core.json_encode(1.5), '1.5', 'fraction')
|
||||
eq(core.json_encode(0 / 0), 'null', 'NaN')
|
||||
eq(core.json_encode(3), '3', 'integer has no fraction')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- core: options
|
||||
|
||||
test('options: defaults', function()
|
||||
local o, w = core.options(nil)
|
||||
eq(#w, 0, 'no warnings')
|
||||
eq(o.enabled, true, 'enabled')
|
||||
eq(o.autocomplete, false, 'autocomplete is off')
|
||||
eq(o.keys.ask.key, 'A', 'ask key')
|
||||
eq(o.keys.ask.mods, 'CTRL|SHIFT', 'ask mods')
|
||||
eq(o.split.size, 0.45, 'split size')
|
||||
eq(o.context.blocks, 5, 'blocks')
|
||||
eq(o.context.output_lines, 200, 'output lines')
|
||||
eq(o.context.output_bytes, 16384, 'output bytes')
|
||||
eq(o.context.alt_screen, false, 'alt screen')
|
||||
end)
|
||||
|
||||
test('options: merge, turn off, clamp', function()
|
||||
local o, w = core.options {
|
||||
session_bar = false,
|
||||
keys = { ask = { key = 'Space', mods = 'CTRL' }, resume = false },
|
||||
context = { blocks = 99, output_lines = 0 },
|
||||
split = { size = 0.3 },
|
||||
autocomplete = true,
|
||||
cli = '/opt/lembas',
|
||||
}
|
||||
eq(#w, 0, 'no warnings')
|
||||
eq(o.session_bar, false, 'bar off')
|
||||
eq(o.tab_marker, true, 'untouched option stays')
|
||||
eq(o.keys.ask.key, 'Space', 'key replaced')
|
||||
eq(o.keys.resume, false, 'key off')
|
||||
eq(o.keys.private.key, 'H', 'other keys stay')
|
||||
eq(o.context.blocks, 20, 'blocks capped at 20')
|
||||
eq(o.context.output_lines, 1, 'lines at least 1')
|
||||
eq(o.split.size, 0.3, 'size')
|
||||
eq(o.split.direction, 'Right', 'direction stays')
|
||||
eq(o.cli, '/opt/lembas', 'cli')
|
||||
end)
|
||||
|
||||
test('options: mistakes warn and never throw', function()
|
||||
local o, w = core.options {
|
||||
sesion_bar = false,
|
||||
palette = 'yes',
|
||||
keys = { ask = 'A', nope = false },
|
||||
split = { direction = 'Sideways', size = -1 },
|
||||
new_session_in = 'window',
|
||||
bar = { fields = { 'model', 'nonsense' } },
|
||||
context = 'all',
|
||||
cli = 7,
|
||||
}
|
||||
check(#w >= 8, 'a warning for each: got ' .. #w)
|
||||
eq(o.palette, true, 'wrong type keeps the default')
|
||||
eq(o.keys.ask.key, 'A', 'bad key keeps the default')
|
||||
eq(o.split.direction, 'Right', 'direction')
|
||||
eq(o.split.size, 0.45, 'size')
|
||||
eq(o.new_session_in, 'split', 'new_session_in')
|
||||
eq(#o.bar.fields, 1, 'unknown field dropped')
|
||||
eq(o.context.blocks, 5, 'context untouched')
|
||||
eq(o.cli, nil, 'cli')
|
||||
local _, w2 = core.options 'nonsense'
|
||||
eq(#w2, 1, 'not a table')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- core: the session bar
|
||||
|
||||
test('session_from_vars', function()
|
||||
eq(core.session_from_vars {}, nil, 'no vars')
|
||||
eq(core.session_from_vars { WEZTERM_PROG = 'vim' }, nil, 'other vars')
|
||||
eq(core.session_from_vars(nil), nil, 'nil')
|
||||
local s = core.session_from_vars {
|
||||
lembas_session = 'abc123',
|
||||
lembas_model = 'big\27[31m-model\7',
|
||||
lembas_mode = 'auto',
|
||||
lembas_state = 'thinking',
|
||||
lembas_context = '41.6',
|
||||
lembas_title = string.rep('t', 300),
|
||||
}
|
||||
eq(s.session, 'abc123', 'session')
|
||||
eq(s.model, 'big[31m-model', 'escape sequence defused')
|
||||
eq(s.state, 'thinking', 'state')
|
||||
eq(s.context, 42, 'context rounded')
|
||||
check(#s.title <= 80 + #'…', 'title capped')
|
||||
eq(core.session_from_vars({ lembas_session = 'x', lembas_state = 'rm -rf' }).state, nil, 'unknown state dropped')
|
||||
eq(core.session_from_vars({ lembas_session = 'x', lembas_context = '250' }).context, nil, 'context out of range')
|
||||
eq(core.session_from_vars({ lembas_session = 'x', lembas_context = '%s%n' }).context, nil, 'context not a number')
|
||||
eq(core.session_from_vars({ lembas_session = 'x', lembas_context = '7%' }).context, 7, 'context with a percent sign')
|
||||
eq(core.session_from_vars({ lembas_state = 'idle' }).state, 'idle', 'state alone is enough')
|
||||
end)
|
||||
|
||||
test('bar_parts and bar_items', function()
|
||||
local fields = { 'model', 'mode', 'state', 'context' }
|
||||
eq(core.bar_items(nil, fields, false), nil, 'no session, not private: nothing')
|
||||
local s = core.session_from_vars {
|
||||
lembas_session = 'x',
|
||||
lembas_model = 'm1',
|
||||
lembas_mode = 'edit',
|
||||
lembas_state = 'asking',
|
||||
lembas_context = '12',
|
||||
lembas_spend = '0.02',
|
||||
}
|
||||
local parts = core.bar_parts(s, fields, false)
|
||||
eq(#parts, 4, 'four parts')
|
||||
eq(parts[1].text, 'm1', 'model')
|
||||
eq(parts[3].text, 'needs you', 'asking in words')
|
||||
eq(parts[3].attention, true, 'asking stands out')
|
||||
eq(parts[4].text, 'ctx 12%', 'context')
|
||||
eq(#core.bar_parts(s, { 'spend', 'bogus' }, false), 1, 'only fields that exist')
|
||||
local p = core.bar_parts(nil, fields, true)
|
||||
eq(#p, 1, 'private alone')
|
||||
eq(p[1].text, 'private', 'private text')
|
||||
local items = core.bar_items(s, fields, true)
|
||||
local text = {}
|
||||
for _, item in ipairs(items) do
|
||||
if type(item) == 'table' and item.Text then
|
||||
text[#text + 1] = item.Text
|
||||
check(not item.Text:find '[%c]', 'no control character in a Text item')
|
||||
end
|
||||
end
|
||||
eq(table.concat(text), ' m1 · edit · needs you · ctx 12% · private ', 'whole bar')
|
||||
end)
|
||||
|
||||
test('tab_title and find_session_pane', function()
|
||||
local asking = { pane_id = 2, user_vars = { lembas_session = 's', lembas_state = 'asking' } }
|
||||
local idle = { pane_id = 3, user_vars = { lembas_session = 's', lembas_state = 'idle' } }
|
||||
local shell = { pane_id = 1, user_vars = {} }
|
||||
eq(core.tab_title { tab_index = 0, panes = { shell, idle }, active_pane = { title = 'zsh' } }, nil, 'nobody asks')
|
||||
eq(core.tab_title(nil), nil, 'nil')
|
||||
local items = core.tab_title(
|
||||
{ tab_index = 1, tab_title = '', panes = { shell, asking }, active_pane = { title = 'zsh\27]0;evil\7' } },
|
||||
{ max_width = 16 }
|
||||
)
|
||||
check(type(items) == 'table', 'asking: items')
|
||||
local text = ''
|
||||
for _, item in ipairs(items) do
|
||||
if type(item) == 'table' and item.Text then
|
||||
text = text .. item.Text
|
||||
end
|
||||
end
|
||||
eq(text, ' ● 2: zsh]0;ev… ', 'marked, indexed, cut to 16 cells, cleaned')
|
||||
eq(core.find_session_pane({ shell, idle }, 1), 3, 'the other pane')
|
||||
eq(core.find_session_pane({ shell }, 1), nil, 'none')
|
||||
eq(core.find_session_pane({ idle, asking }, 3), 2, 'not the one the person is in')
|
||||
eq(core.find_session_pane({ idle }, 3), 3, 'only itself')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- core: terminal context
|
||||
|
||||
local function zone(kind, y, text, y2)
|
||||
-- the command line starts after the prompt, on the same row
|
||||
local x = kind == 'Input' and 2 or 0
|
||||
return { semantic_type = kind, start_y = y, start_x = x, end_y = y2 or y, end_x = 10, text = text }
|
||||
end
|
||||
|
||||
local function text_of(z)
|
||||
return z.text
|
||||
end
|
||||
|
||||
local LIM = { blocks = 5, output_lines = 200, output_bytes = 16384 }
|
||||
|
||||
test('blocks_from_zones: commands and their output', function()
|
||||
local zones = {
|
||||
zone('Prompt', 0, '$ '),
|
||||
zone('Input', 0, 'ls'),
|
||||
zone('Output', 1, 'a\nb\n', 2),
|
||||
zone('Prompt', 3, '$ '),
|
||||
zone('Input', 3, 'cd /tmp'),
|
||||
zone('Prompt', 4, '$ '),
|
||||
zone('Input', 4, 'make test '),
|
||||
zone('Output', 5, 'ok\27[0m\n', 9),
|
||||
zone('Prompt', 10, '$ '),
|
||||
zone('Input', 10, 'still typi'),
|
||||
}
|
||||
local blocks = core.blocks_from_zones(zones, text_of, LIM)
|
||||
eq(#blocks, 3, 'three run commands; the line being typed is not one')
|
||||
eq(blocks[1].command, 'ls', 'first')
|
||||
eq(blocks[1].output, 'a\nb', 'output, trailing space trimmed')
|
||||
eq(blocks[2].command, 'cd /tmp', 'a command with no output')
|
||||
eq(blocks[2].output, '', 'empty output')
|
||||
eq(blocks[3].command, 'make test', 'trimmed')
|
||||
eq(blocks[3].output, 'ok[0m', 'escape defused')
|
||||
eq(blocks[3].exit, core.null, 'exit is null')
|
||||
end)
|
||||
|
||||
test('blocks_from_zones: order, limits, nothing', function()
|
||||
local zones = {}
|
||||
for i = 1, 30 do
|
||||
zones[#zones + 1] = zone('Output', i * 3 + 1, 'out' .. i)
|
||||
zones[#zones + 1] = zone('Input', i * 3, 'cmd' .. i)
|
||||
zones[#zones + 1] = zone('Prompt', i * 3, '$ ')
|
||||
end
|
||||
local blocks = core.blocks_from_zones(zones, text_of, LIM)
|
||||
eq(#blocks, 5, 'the last five')
|
||||
eq(blocks[1].command, 'cmd26', 'sorted by position, oldest first')
|
||||
eq(blocks[5].output, 'out30', 'newest last')
|
||||
local called = 0
|
||||
core.blocks_from_zones(zones, function(z)
|
||||
called = called + 1
|
||||
return z.text
|
||||
end, LIM)
|
||||
eq(called, 10, 'text is read only for the blocks that are used')
|
||||
eq(#core.blocks_from_zones({}, text_of, LIM), 0, 'no zones')
|
||||
eq(#core.blocks_from_zones(nil, text_of, LIM), 0, 'nil')
|
||||
eq(#core.blocks_from_zones(zones, text_of, { blocks = 0, output_lines = 1, output_bytes = 256 }), 0, 'zero blocks asked')
|
||||
eq(#core.blocks_from_zones({ zone('Output', 1, 'x'), zone('Prompt', 2, '$ ') }, text_of, LIM), 0, 'output with no command')
|
||||
local long = {}
|
||||
for i = 1, 500 do
|
||||
long[i] = 'line ' .. i
|
||||
end
|
||||
local b = core.blocks_from_zones(
|
||||
{ zone('Input', 0, 'seq'), zone('Output', 1, table.concat(long, '\n')) },
|
||||
text_of,
|
||||
{ blocks = 5, output_lines = 3, output_bytes = 16384 }
|
||||
)
|
||||
eq(b[1].output, 'line 498\nline 499\nline 500', 'output cut to its tail')
|
||||
local wide = core.blocks_from_zones(
|
||||
{ zone('Input', 0, 'x'), zone('Output', 1, string.rep('y', 5000)) },
|
||||
text_of,
|
||||
{ blocks = 5, output_lines = 200, output_bytes = 1024 }
|
||||
)
|
||||
eq(#wide[1].output, 1024, 'output cut to its bytes')
|
||||
end)
|
||||
|
||||
test('context and encode_context', function()
|
||||
local blocks = core.blocks_from_zones({ zone('Input', 0, 'ls'), zone('Output', 1, 'a') }, text_of, LIM)
|
||||
local ctx = core.context { pane = 7, cwd = '/home/u/p', shell = 'zsh', blocks = blocks, screen = 'ignored' }
|
||||
eq(
|
||||
core.encode_context(ctx),
|
||||
'{"version":1,"pane":7,"cwd":"/home/u/p","shell":"zsh","blocks":[{"command":"ls","exit":null,"output":"a"}]}',
|
||||
'with blocks: no screen'
|
||||
)
|
||||
local bare = core.context { pane = 1, blocks = core.array {}, screen = 'top\nbottom' }
|
||||
eq(core.encode_context(bare), '{"version":1,"pane":1,"cwd":"","blocks":[],"screen":"top\\nbottom"}', 'no integration: screen, empty blocks')
|
||||
eq(core.encode_context(core.context { pane = 2 }), '{"version":1,"pane":2,"cwd":"","blocks":[]}', 'nothing at all')
|
||||
end)
|
||||
|
||||
test('encode_context stays under the limit', function()
|
||||
local blocks = core.array {}
|
||||
for i = 1, 20 do
|
||||
blocks[i] = { command = 'c' .. i, exit = core.null, output = string.rep('o', 16000) }
|
||||
end
|
||||
local ctx = core.context { pane = 1, cwd = '/', blocks = blocks }
|
||||
local json = core.encode_context(ctx)
|
||||
check(#json < 256 * 1024, 'under 256 KiB: ' .. #json)
|
||||
check(#ctx.blocks < 20 and #ctx.blocks >= 15, 'oldest blocks dropped: ' .. #ctx.blocks)
|
||||
eq(ctx.blocks[#ctx.blocks].command, 'c20', 'the newest stays')
|
||||
local s = core.context { pane = 1, screen = string.rep('line\n', 2000) }
|
||||
local small = core.encode_context(s, 1000)
|
||||
check(#small < 1000, 'screen cut: ' .. #small)
|
||||
check(small:find('"screen"', 1, true) ~= nil, 'still a screen')
|
||||
end)
|
||||
|
||||
test('context files: names and age', function()
|
||||
local name = core.context_file_name(1700000000, 'deadbeef')
|
||||
eq(name, 'context-1700000000-deadbeef.json', 'name')
|
||||
eq(core.context_file_age('/run/x/' .. name, 1700000100), 100, 'age from the name')
|
||||
eq(core.is_stale_context_file(name, 1700000100), false, 'fresh')
|
||||
eq(core.is_stale_context_file(name, 1700000601), true, 'stale after ten minutes')
|
||||
eq(core.is_stale_context_file('gui-sock-123', 1700009999), false, 'not ours: never')
|
||||
eq(core.is_stale_context_file('context-1-zz.json', 1700009999), false, 'not hex: never')
|
||||
eq(core.is_stale_context_file('xcontext-1-ab.json', 1700009999), false, 'prefix: never')
|
||||
eq(core.hex '\0\255A', '00ff41', 'hex')
|
||||
end)
|
||||
|
||||
test('cwd_from and shell_name', function()
|
||||
eq(core.cwd_from 'file://host/home/u/my%20dir', '/home/u/my dir', 'file URL')
|
||||
eq(core.cwd_from 'file:///tmp', '/tmp', 'no host')
|
||||
eq(core.cwd_from '/plain/path', '/plain/path', 'plain path')
|
||||
eq(core.cwd_from 'ftp://x/y', nil, 'not a file')
|
||||
eq(core.cwd_from(nil), nil, 'nil')
|
||||
eq(core.cwd_from { scheme = 'file', file_path = '/a/b' }, '/a/b', 'Url object')
|
||||
eq(core.cwd_from { scheme = 'sftp', file_path = '/a/b' }, nil, 'other scheme')
|
||||
eq(core.shell_name '/usr/bin/zsh', 'zsh', 'zsh')
|
||||
eq(core.shell_name '-bash', 'bash', 'login shell')
|
||||
eq(core.shell_name 'C:\\Program Files\\PowerShell\\pwsh.EXE', 'pwsh', 'windows')
|
||||
eq(core.shell_name '/usr/bin/vim', nil, 'not a shell')
|
||||
eq(core.shell_name(nil), nil, 'nil')
|
||||
end)
|
||||
|
||||
test('question_text and context_command', function()
|
||||
eq(core.question_text ' why did it fail? ', 'why did it fail?', 'trimmed')
|
||||
eq(core.question_text 'a\27[201~b\3', 'a[201~b', 'cannot end a paste or press a key')
|
||||
eq(core.question_text 'two\nlines', 'two\nlines', 'a line break stays')
|
||||
eq(core.question_text '', '', 'empty')
|
||||
check(#core.question_text(string.rep('q', 100000)) <= 16384, 'capped')
|
||||
eq(
|
||||
core.context_command '/run/user/1000/llembas-tty/context-1-ab.json',
|
||||
'/terminal-context /run/user/1000/llembas-tty/context-1-ab.json',
|
||||
'command'
|
||||
)
|
||||
eq(core.context_command '/x\r/quit', '/terminal-context /x /quit', 'no line break can be smuggled in')
|
||||
eq(core.ask_bytes('hi', nil), '\27[200~hi\27[201~\r', 'question alone')
|
||||
eq(core.ask_bytes('a\nb', '/r/c.json'), '/terminal-context /r/c.json\r\27[200~a\nb\27[201~\r', 'context, then a two-line question')
|
||||
eq(core.ask_bytes('x\27[201~\ry', nil), '\27[200~x[201~y\27[201~\r', 'the paste cannot be ended from inside')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- core: the CLI
|
||||
|
||||
test('versions', function()
|
||||
eq(core.compare_versions('2.0.0', '2.0.0'), 0, 'equal')
|
||||
eq(core.compare_versions('2.0.1', '2.0.0'), 1, 'patch')
|
||||
eq(core.compare_versions('1.9.9', '2.0.0'), -1, 'major')
|
||||
eq(core.compare_versions('2.0.0-beta.17', '2.0.0'), -1, 'pre-release before release')
|
||||
eq(core.compare_versions('2.0.0-beta.17', '2.0.0-beta.18'), -1, 'beta numbers')
|
||||
eq(core.compare_versions('2.0.0-beta.9', '2.0.0-beta.10'), -1, 'numeric, not text')
|
||||
eq(core.compare_versions('2.0.0-beta.2', '2.0.0-alpha.9'), 1, 'names')
|
||||
eq(core.compare_versions('2.0.0-beta', '2.0.0-beta.1'), -1, 'shorter first')
|
||||
eq(core.compare_versions('lembas 2.1.0\n', 'v2.0.0'), 1, 'found in text')
|
||||
eq(core.compare_versions('nonsense', '2.0.0'), nil, 'not a version')
|
||||
eq(core.cli_supports_terminal(core.MIN_CLI_VERSION), true, 'the minimum itself')
|
||||
eq(core.cli_supports_terminal '2.0.0-beta.17', false, 'older')
|
||||
eq(core.cli_supports_terminal '2.0.0', true, 'release')
|
||||
eq(core.cli_supports_terminal '3.1.4', true, 'newer')
|
||||
eq(core.cli_supports_terminal '', nil, 'cannot tell')
|
||||
end)
|
||||
|
||||
test('cli_candidates', function()
|
||||
local c = core.cli_candidates(nil, '/opt/tty/bin', '/usr/local/bin:/usr/bin', false)
|
||||
eq(c[1], '/opt/tty/bin/lembas', 'beside the terminal first')
|
||||
eq(c[2], '/usr/local/bin/lembas', 'then PATH, in order')
|
||||
eq(c[3], '/usr/bin/lembas', 'PATH 2')
|
||||
eq(#core.cli_candidates('/x/lembas', '/opt', '/usr/bin', false), 1, 'explicit: only that')
|
||||
eq(core.cli_candidates(nil, 'C:\\tty', 'C:\\a;C:\\b', true)[3], 'C:\\b\\lembas.exe', 'windows')
|
||||
eq(#core.cli_candidates(nil, nil, nil, false), 0, 'nothing known')
|
||||
end)
|
||||
|
||||
test('session_choices and is_session_id', function()
|
||||
eq(core.session_choices 'text', nil, 'not decoded')
|
||||
eq(core.session_choices {}, nil, 'empty')
|
||||
local c = core.session_choices {
|
||||
{ id = 'ses_1', title = 'Fix the\27[2J build', model = 'm', root = '/p' },
|
||||
{ id = 'bad id; rm -rf /', title = 'x' },
|
||||
{ id = 'ses_2' },
|
||||
'junk',
|
||||
}
|
||||
eq(#c, 2, 'only real ids')
|
||||
eq(c[1].id, 'ses_1', 'id')
|
||||
eq(c[1].label, 'Fix the[2J build · m · /p', 'label cleaned')
|
||||
eq(c[2].label, 'ses_2', 'no title: the id')
|
||||
eq(#core.session_choices { sessions = { { id = 'a' } } }, 1, 'wrapped in an object')
|
||||
eq(core.is_session_id 'abc-123_x.y:z', true, 'id')
|
||||
eq(core.is_session_id '-s', false, 'cannot look like an option')
|
||||
eq(core.is_session_id '', false, 'empty')
|
||||
eq(core.is_session_id(nil), false, 'nil')
|
||||
eq(core.is_session_id(string.rep('a', 200)), false, 'too long')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
-- The layer against a stand-in terminal
|
||||
|
||||
local env = {}
|
||||
os.getenv = function(name)
|
||||
if env[name] ~= nil then
|
||||
return env[name] or nil
|
||||
end
|
||||
return real_getenv(name)
|
||||
end
|
||||
|
||||
local function layer(wez_env, options, config)
|
||||
local w = fake.new(wez_env)
|
||||
package.loaded['wezterm'] = w
|
||||
package.loaded['llembas'] = nil
|
||||
local l = require 'llembas'
|
||||
config = config or w.config_builder()
|
||||
l.apply(config, options)
|
||||
return l, w, config
|
||||
end
|
||||
|
||||
-- A directory of its own for one test, inside the scratch directory.
|
||||
local function fresh_dir(name)
|
||||
local dir = TMP .. '/' .. name
|
||||
sh(string.format("mkdir -p '%s/bin' '%s/run'", dir, dir))
|
||||
return dir
|
||||
end
|
||||
|
||||
local function with_cli(dir)
|
||||
write_file(dir .. '/bin/lembas', '#!/bin/sh\n')
|
||||
env.PATH = dir .. '/bin'
|
||||
env.LLEMBAS_TTY_UNIX_SOCKET = dir .. '/run/gui-sock-1'
|
||||
env.XDG_RUNTIME_DIR = false
|
||||
end
|
||||
|
||||
local NEW = { ['--version'] = { true, '2.0.0-beta.18\n' } }
|
||||
local OLD = { ['--version'] = { true, '2.0.0-beta.17\n' } }
|
||||
|
||||
local function context_files(dir)
|
||||
local out = sh(string.format("ls -1 '%s/run' | grep '^context-' || true", dir))
|
||||
local list = {}
|
||||
for name in out:gmatch '[^\n]+' do
|
||||
list[#list + 1] = dir .. '/run/' .. name
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local ZONES = {
|
||||
zone('Prompt', 0, '$ '),
|
||||
zone('Input', 0, 'cargo test'),
|
||||
zone('Output', 1, 'error: it broke\n'),
|
||||
zone('Prompt', 2, '$ '),
|
||||
}
|
||||
|
||||
test('apply: keys, events, and nothing else happens', function()
|
||||
local dir = fresh_dir 'apply'
|
||||
with_cli(dir)
|
||||
local _, w, config = layer({ child_results = NEW }, nil, { keys = { { key = 'x', mods = 'CTRL', action = 'mine' } } })
|
||||
eq(#config.keys, 6, 'five keys added to the one that was there')
|
||||
eq(config.keys[1].action, 'mine', "the person's own key stays first")
|
||||
eq(config.keys[2].key, 'A', 'ask')
|
||||
eq(config.keys[2].action.action, 'EmitEvent', 'an event')
|
||||
eq(config.keys[2].action.args, 'llembas-ask', 'ask event')
|
||||
eq(#w.spawned, 0, 'no process started by applying')
|
||||
eq(config.set_environment_variables, nil, 'no environment touched')
|
||||
for _, name in ipairs { 'update-status', 'format-tab-title', 'augment-command-palette', 'user-var-changed', 'llembas-ask' } do
|
||||
check(w.handlers[name] ~= nil, 'handler for ' .. name)
|
||||
end
|
||||
local entries = w.emit 'augment-command-palette'
|
||||
eq(#entries, 7, 'seven palette entries')
|
||||
eq(entries[1].brief, 'LLeMbas: ask the model', 'first entry')
|
||||
eq(#context_files(dir), 0, 'no file written')
|
||||
end)
|
||||
|
||||
test('apply: everything can be turned off', function()
|
||||
local _, w, config = layer({}, { enabled = false })
|
||||
eq(config.keys, nil, 'disabled: no keys')
|
||||
eq(next(w.handlers), nil, 'disabled: no handlers')
|
||||
local _, w2, config2 = layer({}, {
|
||||
session_bar = false,
|
||||
tab_marker = false,
|
||||
palette = false,
|
||||
keys = { ask = false, new_session = false, resume = false, toggle_display = false, private = false },
|
||||
})
|
||||
eq(#config2.keys, 0, 'no keys')
|
||||
eq(w2.handlers['update-status'], nil, 'no bar')
|
||||
eq(w2.handlers['format-tab-title'], nil, 'no tab mark')
|
||||
eq(w2.handlers['augment-command-palette'], nil, 'no palette')
|
||||
local _, w3 = layer({}, { nonsense = 1 })
|
||||
check(#w3.logs == 1 and w3.logs[1]:find('nonsense', 1, true), 'a typo is logged')
|
||||
end)
|
||||
|
||||
test('apply: autocomplete exports the switch', function()
|
||||
local dir = fresh_dir 'ac'
|
||||
with_cli(dir)
|
||||
local _, w, config = layer({}, { autocomplete = true }, { set_environment_variables = { MINE = '1' } })
|
||||
eq(config.set_environment_variables.LLEMBAS_TTY_AUTOCOMPLETE, '1', 'switch')
|
||||
eq(config.set_environment_variables.LLEMBAS_TTY_CLI, dir .. '/bin/lembas', 'the CLI found')
|
||||
eq(config.set_environment_variables.MINE, '1', "the person's own stays")
|
||||
eq(#w.spawned, 0, 'still no process')
|
||||
end)
|
||||
|
||||
test('ask key opens a one-line prompt', function()
|
||||
local _, w = layer {}
|
||||
local win, pane = fake.window(), fake.pane {}
|
||||
w.emit('llembas-ask', win, pane)
|
||||
eq(#win.actions, 1, 'one action')
|
||||
eq(win.actions[1].action.action, 'PromptInputLine', 'prompt')
|
||||
eq(win.actions[1].action.args.action.args, 'llembas-ask-line', 'answer goes to ask-line')
|
||||
eq(pane.read_zones, nil, 'nothing read yet')
|
||||
end)
|
||||
|
||||
test('ask: new session beside the pane, with a context file', function()
|
||||
local dir = fresh_dir 'ask'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local win = fake.window()
|
||||
local pane = fake.pane { id = 7, zones = ZONES, cwd = 'file:///home/u/proj', program = '/bin/zsh', screen = 'SCREEN' }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', win, pane, 'why did it fail?')
|
||||
local files = context_files(dir)
|
||||
eq(#files, 1, 'one context file')
|
||||
eq(sh(string.format("stat -c %%a '%s'", files[1])), '600', 'mode 0600')
|
||||
eq(
|
||||
read_file(files[1]),
|
||||
'{"version":1,"pane":7,"cwd":"/home/u/proj","shell":"zsh","blocks":[{"command":"cargo test","exit":null,"output":"error: it broke"}]}',
|
||||
'content'
|
||||
)
|
||||
eq(pane.read_screen, nil, 'screen not read when there are blocks')
|
||||
eq(#pane.splits, 1, 'split')
|
||||
local s = pane.splits[1]
|
||||
eq(s.direction, 'Right', 'to the right')
|
||||
eq(s.size, 0.45, '45 %')
|
||||
eq(s.cwd, '/home/u/proj', "in the pane's directory")
|
||||
eq(s.args[1], dir .. '/bin/lembas', 'the CLI')
|
||||
eq(s.args[2], '--terminal-context', 'flag')
|
||||
eq(s.args[3], files[1], 'file')
|
||||
eq(#s.args, 3, 'the question is not on the command line')
|
||||
local new = pane.last_split
|
||||
eq(#new.sent, 0, 'nothing sent before the session is ready')
|
||||
w.emit('user-var-changed', win, new, 'lembas_state', 'thinking')
|
||||
eq(#new.sent, 0, 'not on another state')
|
||||
w.emit('user-var-changed', win, new, 'lembas_state', 'idle')
|
||||
eq(#new.sent, 1, 'sent when idle, in one write')
|
||||
eq(new.sent[1][1], 'text', 'written, not handed to the asynchronous paste')
|
||||
eq(new.sent[1][2], '\27[200~why did it fail?\27[201~\r', 'the question as a bracketed paste, then Enter')
|
||||
w.emit('user-var-changed', win, new, 'lembas_state', 'idle')
|
||||
eq(#new.sent, 1, 'only once')
|
||||
end)
|
||||
|
||||
test('ask: into the LLeMbas pane the tab already has', function()
|
||||
local dir = fresh_dir 'ask2'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local win = fake.window()
|
||||
local pane = fake.pane { id = 1, zones = ZONES, cwd = '/p' }
|
||||
local agent = fake.pane { id = 2, vars = { lembas_session = 's1', lembas_state = 'idle' } }
|
||||
fake.tab { pane, agent }
|
||||
w.emit('llembas-ask-line', win, pane, 'explain\27[201~ this')
|
||||
local files = context_files(dir)
|
||||
eq(#files, 1, 'context file')
|
||||
eq(#pane.splits, 0, 'no new pane')
|
||||
eq(#agent.sent, 1, 'one write')
|
||||
eq(
|
||||
agent.sent[1][2],
|
||||
'/terminal-context ' .. files[1] .. '\r\27[200~explain[201~ this\27[201~\r',
|
||||
'context line, Enter, the question pasted (and unable to end the paste), Enter'
|
||||
)
|
||||
eq(agent.read_zones, nil, 'the LLeMbas pane itself is not read')
|
||||
end)
|
||||
|
||||
test('ask: from inside the LLeMbas pane it is just typed', function()
|
||||
local dir = fresh_dir 'ask3'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local agent = fake.pane { id = 2, vars = { lembas_session = 's1' }, zones = ZONES }
|
||||
fake.tab { agent }
|
||||
w.emit('llembas-ask-line', fake.window(), agent, 'hello')
|
||||
eq(#context_files(dir), 0, 'no context')
|
||||
eq(agent.sent[1][2], '\27[200~hello\27[201~\r', 'typed')
|
||||
eq(agent.read_zones, nil, 'not read')
|
||||
end)
|
||||
|
||||
test('ask: no shell integration gives the screen', function()
|
||||
local dir = fresh_dir 'ask4'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local pane = fake.pane { id = 3, screen = 'l1\nl2\27[0m\n', cwd = '/p', program = '/usr/bin/python3' }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', fake.window(), pane, 'q')
|
||||
eq(read_file(context_files(dir)[1]), '{"version":1,"pane":3,"cwd":"/p","blocks":[],"screen":"l1\\nl2[0m\\n"}', 'screen, no shell')
|
||||
end)
|
||||
|
||||
test('ask: a private pane gives nothing, and the question still goes', function()
|
||||
local dir = fresh_dir 'priv'
|
||||
with_cli(dir)
|
||||
local l, w = layer { child_results = NEW }
|
||||
local win = fake.window()
|
||||
local pane = fake.pane { id = 4, zones = ZONES, screen = 'secret' }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-private', win, pane)
|
||||
eq(l.is_private(4), true, 'private')
|
||||
eq(l.is_private(5), false, 'only that pane')
|
||||
w.emit('update-status', win, pane)
|
||||
eq(win.status, ' private ', 'shown in the bar')
|
||||
w.emit('llembas-ask-line', win, pane, 'q')
|
||||
eq(#context_files(dir), 0, 'no file')
|
||||
eq(pane.read_zones, nil, 'zones not read')
|
||||
eq(pane.read_screen, nil, 'screen not read')
|
||||
eq(#pane.splits, 1, 'session still starts')
|
||||
eq(#pane.splits[1].args, 1, 'with no context')
|
||||
eq(win.actions[#win.actions].action.action, 'InputSelector', 'and the person is told')
|
||||
w.emit('llembas-private', win, pane)
|
||||
eq(l.is_private(4), false, 'off again')
|
||||
w.emit('update-status', win, pane)
|
||||
eq(win.status, '', 'bar cleared')
|
||||
end)
|
||||
|
||||
test('ask: a password prompt gives nothing', function()
|
||||
local dir = fresh_dir 'pw'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local pane = fake.pane { id = 5, zones = ZONES, metadata = { password_input = true } }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', fake.window(), pane, 'q')
|
||||
eq(#context_files(dir), 0, 'no file')
|
||||
eq(pane.read_zones, nil, 'not read')
|
||||
end)
|
||||
|
||||
test('ask: a full-screen program gives nothing unless asked', function()
|
||||
local dir = fresh_dir 'alt'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local pane = fake.pane { id = 6, alt = true, zones = ZONES, screen = 'vim buffer', cwd = '/p' }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', fake.window(), pane, 'q')
|
||||
eq(read_file(context_files(dir)[1]), '{"version":1,"pane":6,"cwd":"/p","blocks":[]}', 'only where it is')
|
||||
eq(pane.read_screen, nil, 'screen not read')
|
||||
local dir2 = fresh_dir 'alt2'
|
||||
with_cli(dir2)
|
||||
w.emit('llembas-ask-screen-line', fake.window(), pane, 'q')
|
||||
eq(read_file(context_files(dir2)[1]), '{"version":1,"pane":6,"cwd":"/p","blocks":[],"screen":"vim buffer"}', 'asked about the screen')
|
||||
end)
|
||||
|
||||
test('ask: context off, empty line, remote pane', function()
|
||||
local dir = fresh_dir 'off'
|
||||
with_cli(dir)
|
||||
local _, w = layer({ child_results = NEW }, { context = { enabled = false } })
|
||||
local pane = fake.pane { id = 8, zones = ZONES }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', fake.window(), pane, 'q')
|
||||
eq(#context_files(dir), 0, 'context off: no file')
|
||||
eq(pane.read_zones, nil, 'not read')
|
||||
eq(#pane.splits, 1, 'question still goes')
|
||||
local p2 = fake.pane { id = 9, zones = ZONES }
|
||||
w.emit('llembas-ask-line', fake.window(), p2, nil)
|
||||
w.emit('llembas-ask-line', fake.window(), p2, ' ')
|
||||
eq(#p2.splits, 0, 'cancelled or empty: nothing')
|
||||
local win = fake.window()
|
||||
local far = fake.pane { id = 10, zones = ZONES, domain = 'SSH:server' }
|
||||
w.emit('llembas-ask-line', win, far, 'q')
|
||||
eq(#far.splits, 0, 'remote pane: nothing started')
|
||||
eq(far.read_zones, nil, 'remote pane: not read')
|
||||
check(win.actions[1].action.args.description:find('local panes', 1, true), 'told in words')
|
||||
end)
|
||||
|
||||
test('missing CLI: said clearly, never silently', function()
|
||||
local dir = fresh_dir 'nocli'
|
||||
env.PATH = dir .. '/bin'
|
||||
env.LLEMBAS_TTY_UNIX_SOCKET = dir .. '/run/gui-sock-1'
|
||||
local _, w = layer {}
|
||||
local win, pane = fake.window(), fake.pane { zones = ZONES }
|
||||
w.emit('llembas-ask-line', win, pane, 'q')
|
||||
eq(#win.actions, 1, 'a message')
|
||||
check(win.actions[1].action.args.description:find('get.sh | bash', 1, true), 'names the install command')
|
||||
eq(pane.read_zones, nil, 'nothing read')
|
||||
eq(#w.spawned, 0, 'nothing started')
|
||||
w.emit('llembas-new-session', win, pane)
|
||||
eq(#win.actions, 2, 'a message again')
|
||||
check(win.actions[2].action.args.description:find('still not found', 1, true), 'the short one')
|
||||
eq(#pane.splits, 0, 'no pane')
|
||||
end)
|
||||
|
||||
test('a CLI that is too old: said in words', function()
|
||||
local dir = fresh_dir 'old'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = OLD }
|
||||
local win, pane = fake.window(), fake.pane { zones = ZONES }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', win, pane, 'q')
|
||||
eq(#pane.splits, 0, 'nothing started')
|
||||
eq(pane.read_zones, nil, 'nothing read')
|
||||
local d = win.actions[1].action.args.description
|
||||
check(d:find('2.0.0-beta.17', 1, true) and d:find('lembas update', 1, true), 'says which and what to do')
|
||||
w.emit('llembas-ask-line', win, pane, 'q')
|
||||
eq(#w.spawned, 1, 'version asked once')
|
||||
w.emit('llembas-new-session', win, pane)
|
||||
eq(#pane.splits, 1, 'a session still starts with an old CLI')
|
||||
end)
|
||||
|
||||
test('a CLI whose version cannot be read is tried', function()
|
||||
local dir = fresh_dir 'unk'
|
||||
with_cli(dir)
|
||||
local _, w = layer {}
|
||||
local pane = fake.pane { zones = ZONES }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', fake.window(), pane, 'q')
|
||||
eq(#pane.splits, 1, 'tried')
|
||||
end)
|
||||
|
||||
test('stale context files are swept, other files never', function()
|
||||
local dir = fresh_dir 'sweep'
|
||||
with_cli(dir)
|
||||
local now = os.time()
|
||||
local old = dir .. '/run/' .. core.context_file_name(now - 601, 'aa')
|
||||
local young = dir .. '/run/' .. core.context_file_name(now - 30, 'bb')
|
||||
local other = dir .. '/run/gui-sock-1'
|
||||
write_file(old)
|
||||
write_file(young)
|
||||
write_file(other)
|
||||
local _, w = layer { child_results = NEW }
|
||||
local pane = fake.pane { zones = ZONES }
|
||||
fake.tab { pane }
|
||||
w.emit('llembas-ask-line', fake.window(), pane, 'q')
|
||||
eq(read_file(old), nil, 'old one gone')
|
||||
check(read_file(young) ~= nil, 'young one stays')
|
||||
check(read_file(other) ~= nil, 'the socket stays')
|
||||
eq(#context_files(dir), 2, 'young + new')
|
||||
end)
|
||||
|
||||
test('sessions: new, in a split or a tab', function()
|
||||
local dir = fresh_dir 'new'
|
||||
with_cli(dir)
|
||||
local _, w = layer {}
|
||||
local win, pane = fake.window(), fake.pane { cwd = '/p' }
|
||||
w.emit('llembas-new-session', win, pane)
|
||||
eq(#pane.splits, 1, 'split')
|
||||
eq(#pane.splits[1].args, 1, 'just lembas')
|
||||
eq(pane.splits[1].cwd, '/p', 'cwd')
|
||||
eq(#w.spawned, 0, 'no version probe needed')
|
||||
local _, w2 = layer({}, { new_session_in = 'tab' })
|
||||
local win2, pane2 = fake.window(), fake.pane { cwd = '/p' }
|
||||
w2.emit('llembas-new-session', win2, pane2)
|
||||
eq(#pane2.splits, 0, 'no split')
|
||||
eq(win2.actions[1].action.action, 'SpawnCommandInNewTab', 'a tab')
|
||||
eq(win2.actions[1].action.args.cwd, '/p', 'cwd')
|
||||
end)
|
||||
|
||||
test('sessions: resume from a JSON list', function()
|
||||
local dir = fresh_dir 'resume'
|
||||
with_cli(dir)
|
||||
local _, w = layer {
|
||||
child_results = { ['sessions --json'] = { true, 'JSON' } },
|
||||
json_parse = function(text)
|
||||
assert(text == 'JSON')
|
||||
return { { id = 'ses_9', title = 'T' }, { id = '--evil' } }
|
||||
end,
|
||||
}
|
||||
local win, pane = fake.window(), fake.pane { cwd = '/p' }
|
||||
w.emit('llembas-resume', win, pane)
|
||||
local a = win.actions[1].action
|
||||
eq(a.action, 'InputSelector', 'a list')
|
||||
eq(#a.args.choices, 1, 'only real ids')
|
||||
eq(a.args.action.args, 'llembas-resume-pick', 'pick event')
|
||||
w.emit('llembas-resume-pick', win, pane, 'ses_9', 'T')
|
||||
eq(pane.splits[1].args[2], '-s', 'resume flag')
|
||||
eq(pane.splits[1].args[3], 'ses_9', 'id')
|
||||
w.emit('llembas-resume-pick', win, pane, '--evil', 'x')
|
||||
w.emit('llembas-resume-pick', win, pane, nil, nil)
|
||||
eq(#pane.splits, 1, 'a bad or missing id starts nothing')
|
||||
end)
|
||||
|
||||
test('sessions: resume falls back to the list of the CLI itself', function()
|
||||
local dir = fresh_dir 'resume2'
|
||||
with_cli(dir)
|
||||
local _, w = layer { child_results = { ['sessions --json'] = { true, 'ses_1 2026-01-01 10:00 m /p\n' } } }
|
||||
local win, pane = fake.window(), fake.pane {}
|
||||
w.emit('llembas-resume', win, pane)
|
||||
eq(#win.actions, 0, 'no list of ours')
|
||||
eq(#pane.splits, 1, 'the CLI in a pane')
|
||||
local new = pane.last_split
|
||||
w.emit('user-var-changed', win, new, 'lembas_state', 'idle')
|
||||
eq(new.sent[1][2], '/sessions\r', 'its own session list')
|
||||
end)
|
||||
|
||||
test('sessions: display toggle, log in', function()
|
||||
local dir = fresh_dir 'misc'
|
||||
with_cli(dir)
|
||||
local _, w = layer {}
|
||||
local win = fake.window()
|
||||
local pane = fake.pane { id = 1 }
|
||||
local agent = fake.pane { id = 2, vars = { lembas_session = 's' } }
|
||||
fake.tab { pane, agent }
|
||||
w.emit('llembas-toggle-display', win, pane)
|
||||
eq(win.actions[1].action.action, 'SendKey', 'a key')
|
||||
eq(win.actions[1].action.args.key, 'd', 'd')
|
||||
eq(win.actions[1].action.args.mods, 'ALT', 'Alt')
|
||||
eq(win.actions[1].pane, agent, 'to the LLeMbas pane')
|
||||
local lone = fake.pane { id = 3 }
|
||||
fake.tab { lone }
|
||||
w.emit('llembas-toggle-display', win, lone)
|
||||
eq(win.actions[2].action.action, 'InputSelector', 'no LLeMbas pane: said')
|
||||
w.emit('llembas-login', win, pane)
|
||||
eq(pane.splits[1].args[2], 'login', 'lembas login')
|
||||
end)
|
||||
|
||||
test('session bar: shows the session, and nothing of ours otherwise', function()
|
||||
local _, w = layer {}
|
||||
local win = fake.window()
|
||||
local shell = fake.pane { id = 1, zones = ZONES, screen = 'x' }
|
||||
w.emit('update-status', win, shell)
|
||||
eq(win.status, nil, 'no LLeMbas pane: the status is not touched')
|
||||
local agent = fake.pane {
|
||||
id = 2,
|
||||
vars = { lembas_session = 's', lembas_model = 'm\27[5m', lembas_mode = 'auto', lembas_state = 'tools', lembas_context = '9' },
|
||||
}
|
||||
w.emit('update-status', win, agent)
|
||||
eq(win.status, ' m[5m · auto · tools · ctx 9% ', 'the bar')
|
||||
w.emit('update-status', win, shell)
|
||||
eq(win.status, '', 'cleared when the person leaves the pane')
|
||||
win.status = 'theirs'
|
||||
w.emit('update-status', win, shell)
|
||||
eq(win.status, 'theirs', 'and then left alone')
|
||||
eq(shell.read_zones, nil, 'the bar never reads zones')
|
||||
eq(shell.read_screen, nil, 'the bar never reads the screen')
|
||||
end)
|
||||
|
||||
test('tab mark', function()
|
||||
local _, w = layer {}
|
||||
local tab = {
|
||||
tab_index = 0,
|
||||
tab_title = '',
|
||||
active_pane = { title = 'lembas' },
|
||||
panes = { { pane_id = 1, user_vars = { lembas_session = 's', lembas_state = 'asking' } } },
|
||||
}
|
||||
local items = w.emit('format-tab-title', tab, {}, {}, { show_tab_index_in_tab_bar = true }, false, 20)
|
||||
check(type(items) == 'table', 'marked')
|
||||
tab.panes[1].user_vars.lembas_state = 'idle'
|
||||
eq(w.emit('format-tab-title', tab, {}, {}, {}, false, 20), nil, 'not marked: left to the terminal')
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
os.getenv = real_getenv
|
||||
io.stdout:write(string.format('llembas layer: %d checks passed, %d failed\n', passed, failed))
|
||||
os.exit(failed == 0 and 0 or 1)
|
||||
Executable
+111
@@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env bash
|
||||
# Smoke test of built binaries, with no display: the identity (names, directories, variables),
|
||||
# the built-in LLeMbas layer, and the `cli` commands the LLeMbas CLI drives a pane with.
|
||||
#
|
||||
# llembas/tests/smoke.sh <dir with llembas-tty, llembas-tty-mux-server>
|
||||
#
|
||||
# Starts a headless mux server in a scratch HOME, talks to it, and stops it. Nothing of the
|
||||
# person's own is read or written. CI runs it on what it has just built.
|
||||
set -uo pipefail
|
||||
BIN="$(cd "${1:?usage: smoke.sh <dir with the binaries>}" && pwd)"
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
TTY="${SMOKE_TTY:-$BIN/llembas-tty}"
|
||||
MUX="${SMOKE_MUX:-$BIN/llembas-tty-mux-server}"
|
||||
# The names under test; SMOKE_PREFIX=WEZTERM runs the same steps against upstream's binaries.
|
||||
P="${SMOKE_PREFIX:-LLEMBAS_TTY}"
|
||||
APPDIR="${SMOKE_APPDIR:-llembas-tty}"
|
||||
|
||||
work="$(mktemp -d)"
|
||||
pid=""
|
||||
failed=0
|
||||
# shellcheck disable=SC2317 # reached through the trap
|
||||
cleanup() {
|
||||
if [ -n "$pid" ]; then kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; fi
|
||||
rm -rf "${work:?}"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
mkdir -p "$work/home" "$work/run" "$work/cfg"
|
||||
chmod 700 "$work/run"
|
||||
|
||||
clean() { env -i PATH=/usr/bin:/bin HOME="$work/home" XDG_RUNTIME_DIR="$work/run" XDG_CONFIG_HOME="$work/cfg" "$@"; }
|
||||
ok() { echo "ok $1"; }
|
||||
# On GitHub a failure is also an annotation on the run: a line, with newlines made visible.
|
||||
note() { [ -z "${GITHUB_ACTIONS:-}" ] || printf '::error title=smoke::%s\n' "$(printf '%s' "$1" | head -c 900 | tr '\n\r' ' ' | sed 's/%/%25/g')"; }
|
||||
bad() { echo "FAIL $1"; note "$1"; failed=1; }
|
||||
expect() { # name, text, pattern
|
||||
if printf '%s' "$2" | grep -Eq -- "$3"; then ok "$1"; else bad "$1: wanted /$3/ in: $2"; fi
|
||||
}
|
||||
|
||||
version="$(tr -d '[:space:]' < "$ROOT/VERSION")"
|
||||
if [ "$P" = LLEMBAS_TTY ]; then
|
||||
expect "--version names us and our version" "$(clean "$TTY" --version)" "^llembas-tty ${version//./\\.} \(based on WezTerm .+\)$"
|
||||
expect "mux server --version" "$(clean "$MUX" --version)" "^llembas-tty-mux-server ${version//./\\.}"
|
||||
fi
|
||||
|
||||
# A WezTerm that started us must not be passed on, nor talked to.
|
||||
# (exec, so that the process id we keep is the server's own and stopping it stops the server)
|
||||
(
|
||||
exec env -i PATH=/usr/bin:/bin HOME="$work/home" XDG_RUNTIME_DIR="$work/run" XDG_CONFIG_HOME="$work/cfg" \
|
||||
WEZTERM_PANE=77 WEZTERM_UNIX_SOCKET="$work/run/not-ours" WEZTERM_CONFIG_FILE="$work/nope.lua" \
|
||||
"$MUX"
|
||||
) > "$work/server.txt" 2>&1 &
|
||||
pid=$!
|
||||
sock="$work/run/$APPDIR/sock"
|
||||
for _ in $(seq 40); do
|
||||
[ -S "$sock" ] && break
|
||||
kill -0 "$pid" 2>/dev/null || break
|
||||
sleep 0.25
|
||||
done
|
||||
if [ -S "$sock" ]; then ok "the server listens in its own runtime directory ($APPDIR)"; else bad "no socket at $sock; the server said: $(tail -c 600 "$work/server.txt"); in the runtime directory: $(cd "$work/run" && find . | head -20 | tr '\n' ' ')"; cat "$work/server.txt"; exit 1; fi
|
||||
|
||||
cli() { clean "$TTY" cli --no-auto-start "$@"; }
|
||||
# shellcheck disable=SC2016 # the pane's shell expands these, not this one
|
||||
pane="$(cli spawn --new-window -- sh -c 'printf "%s\n" "id=[$'"$P"'_PANE]" "tty=[$LLEMBAS_TTY]" "exe=[$'"$P"'_EXECUTABLE]" "sock=[$'"$P"'_UNIX_SOCKET]" "term=[$TERM_PROGRAM]" "wez=[${WEZTERM_PANE-unset}/${WEZTERM_UNIX_SOCKET-unset}]"; exec cat')"
|
||||
expect "cli spawn gives a pane id" "$pane" '^[0-9]+$'
|
||||
sleep 1
|
||||
# One value a line, and the lines joined again: a pane is 80 columns wide and wraps a long path,
|
||||
# which is the pane's doing and not what is under test.
|
||||
text="$(cli get-text --pane-id "$pane" | tr -d '\n')"
|
||||
expect "the pane knows its own id" "$text" "id=\[$pane\]"
|
||||
expect "TERM_PROGRAM stays WezTerm" "$text" 'term=\[WezTerm\]'
|
||||
if [ "$P" = LLEMBAS_TTY ]; then
|
||||
expect "LLEMBAS_TTY is our version" "$text" "tty=\[${version//./\\.}\]"
|
||||
expect "LLEMBAS_TTY_EXECUTABLE is the launcher" "$text" "exe=\[$BIN/llembas-tty\]"
|
||||
expect "the socket variable is ours" "$text" "sock=\[$sock\]"
|
||||
expect "WezTerm's variables are not passed on" "$text" 'wez=\[unset/unset\]'
|
||||
fi
|
||||
|
||||
# What the LLeMbas CLI's terminal tools do: type into a pane, read it back.
|
||||
printf 'typed by the cli\n' | cli send-text --pane-id "$pane" --no-paste
|
||||
sleep 0.5
|
||||
expect "send-text --no-paste arrives, get-text reads it" "$(cli get-text --pane-id "$pane")" 'typed by the cli'
|
||||
expect "cli list shows the pane" "$(cli list)" "(^|[^0-9])$pane([^0-9]|$)"
|
||||
|
||||
kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
|
||||
if kill -0 "$pid" 2>/dev/null; then bad "the server did not stop"; else ok "the server stops when told"; fi
|
||||
pid=""
|
||||
|
||||
if [ "$P" = LLEMBAS_TTY ]; then
|
||||
# The built-in configuration applied the layer: its keys are bound. And a person's own file
|
||||
# in our own directory is the one read; --skip-config gives the plain terminal.
|
||||
# (show-keys is the gui binary's; it needs its libraries but no display.)
|
||||
if keys="$(clean "$TTY" show-keys --lua 2>"$work/keys-err.txt")"; then
|
||||
expect "built-in configuration binds the ask key" "$keys" "llembas-ask"
|
||||
plain="$(clean "$TTY" --skip-config show-keys --lua 2>/dev/null)"
|
||||
if printf '%s' "$plain" | grep -q llembas-ask; then bad "--skip-config still has the layer"; else ok "--skip-config is the plain terminal"; fi
|
||||
mkdir -p "$work/cfg/llembas-tty"
|
||||
cat > "$work/cfg/llembas-tty/llembas-tty.lua" <<'LUA'
|
||||
local wezterm = require 'wezterm'
|
||||
local config = wezterm.config_builder()
|
||||
require('llembas').apply(config, { keys = { ask = { key = 'F9', mods = 'NONE' }, resume = false } })
|
||||
return config
|
||||
LUA
|
||||
own="$(clean "$TTY" show-keys --lua 2>"$work/keys-err.txt")"
|
||||
expect "a person's own file in our directory is read, and require 'llembas' works there" "$own" "F9"
|
||||
else
|
||||
bad "show-keys did not run: $(head -5 "$work/keys-err.txt")"
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "$failed" -eq 0 ] && echo "smoke: all passed"
|
||||
exit "$failed"
|
||||
+5
-3
@@ -476,10 +476,12 @@ impl LocalDomain {
|
||||
if let Some(dir) = command_dir {
|
||||
cmd.cwd(dir);
|
||||
}
|
||||
if let Ok(sock) = std::env::var("WEZTERM_UNIX_SOCKET") {
|
||||
cmd.env("WEZTERM_UNIX_SOCKET", sock);
|
||||
// LLeMbas TTY: its own variable names, so that neither this program
|
||||
// nor a WezTerm running beside it talks to the other's panes.
|
||||
if let Ok(sock) = std::env::var("LLEMBAS_TTY_UNIX_SOCKET") {
|
||||
cmd.env("LLEMBAS_TTY_UNIX_SOCKET", sock);
|
||||
}
|
||||
cmd.env("WEZTERM_PANE", pane_id.to_string());
|
||||
cmd.env("LLEMBAS_TTY_PANE", pane_id.to_string());
|
||||
if let Some(agent) = Mux::get().agent.as_ref() {
|
||||
cmd.env("SSH_AUTH_SOCK", agent.path());
|
||||
}
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
# Put the LLeMbas CLI that LLeMbas TTY carries where the package takes it from:
|
||||
# llembas/packaging/bin/lembas (git-ignored; installed beside the terminal's own binaries,
|
||||
# never on PATH)
|
||||
#
|
||||
# scripts/fetch-cli.sh [target-triple] (default: this machine's, from rustc)
|
||||
#
|
||||
# The version is the one in llembas-cli.version. The files are checked exactly as the CLI's own
|
||||
# get.sh checks them: SHA256SUMS signed by the release key in the namespace lembas-release, naming
|
||||
# this version, and the binary matching it. Nothing unverified is bundled.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
VERSION="$(tr -d '[:space:]' < llembas-cli.version)"
|
||||
TRIPLE="${1:-$(rustc -vV | sed -n 's/^host: //p')}"
|
||||
BASE="${LEMBAS_CLI_RELEASES:-https://github.com/LLeMbas/LLeMbas-CLI/releases/download}/v${VERSION}"
|
||||
PUBKEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDSZO3Byow7R3ZpOH3MCvpPIga2pZBzhfX5wXfNP1cLa"
|
||||
|
||||
case "$TRIPLE" in
|
||||
# The baseline build runs on any x86-64 CPU, not only those with AVX2: a terminal meets
|
||||
# older machines than a server does.
|
||||
x86_64-unknown-linux-gnu) ASSET=lembas-linux-x64-baseline ;;
|
||||
aarch64-unknown-linux-gnu) ASSET=lembas-linux-arm64 ;;
|
||||
*) echo "fetch-cli: no LLeMbas CLI build for $TRIPLE yet" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "${work:?}"' EXIT
|
||||
for f in SHA256SUMS SHA256SUMS.sig "$ASSET.gz"; do
|
||||
curl -fsSL --retry 3 -o "$work/$f" "$BASE/$f"
|
||||
done
|
||||
|
||||
printf 'lembas-release %s\n' "$PUBKEY" > "$work/allowed"
|
||||
ssh-keygen -Y verify -f "$work/allowed" -I lembas-release -n lembas-release \
|
||||
-s "$work/SHA256SUMS.sig" < "$work/SHA256SUMS" >/dev/null \
|
||||
|| { echo "fetch-cli: SHA256SUMS is not signed by the release key" >&2; exit 1; }
|
||||
[ "$(sed -n -E 's/^# lembas //p' "$work/SHA256SUMS" | head -n1)" = "$VERSION" ] \
|
||||
|| { echo "fetch-cli: SHA256SUMS is not for $VERSION" >&2; exit 1; }
|
||||
(cd "$work" && grep -E " $ASSET\.gz\$" SHA256SUMS | sha256sum -c --strict --quiet -) \
|
||||
|| { echo "fetch-cli: $ASSET.gz does not match SHA256SUMS" >&2; exit 1; }
|
||||
|
||||
mkdir -p llembas/packaging/bin
|
||||
gunzip -c "$work/$ASSET.gz" > llembas/packaging/bin/lembas
|
||||
chmod 755 llembas/packaging/bin/lembas
|
||||
echo "fetch-cli: LLeMbas CLI $VERSION ($ASSET) -> llembas/packaging/bin/lembas"
|
||||
@@ -32,6 +32,14 @@ while IFS= read -r -d '' f; do
|
||||
added+=$'\n'$(awk -v f="$f" '{print f": "$0}' "$f")
|
||||
done < <(git ls-files -z --others --exclude-standard)
|
||||
|
||||
# What is allowed to match, each for a reason — a line of `file: text` as built above:
|
||||
allowed=(
|
||||
# The package's maintainer address, as a .deb must carry one: the same that signs every commit.
|
||||
'^llembas/packaging/package\.sh: Maintainer: LLeMbas <houmeres@houmeres\.sk>$'
|
||||
)
|
||||
allow="$(IFS='|'; echo "${allowed[*]}")"
|
||||
added=$(printf '%s\n' "$added" | grep -vE -- "$allow" || true)
|
||||
|
||||
found=0
|
||||
for pattern in "${patterns[@]}"; do
|
||||
# grep: 0 = matched, 1 = no match, anything else is an error and must not read as "clean".
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run the tests of the LLeMbas layer (llembas/tests/run.lua) with whatever Lua is here:
|
||||
# lua5.4 (what the terminal embeds), else lua, luajit, or Neovim's LuaJIT (`nvim -l`).
|
||||
#
|
||||
# scripts/test-lua.sh the first one found
|
||||
# scripts/test-lua.sh --all every one found (CI: 5.4 and LuaJIT must agree)
|
||||
# LUA="lua5.4" scripts/test-lua.sh
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
tmp="$(mktemp -d)"
|
||||
trap 'rm -rf "${tmp:?}"' EXIT
|
||||
|
||||
found=()
|
||||
if [ -n "${LUA:-}" ]; then
|
||||
found=("$LUA")
|
||||
else
|
||||
for c in lua5.4 lua luajit; do
|
||||
command -v "$c" >/dev/null 2>&1 && found+=("$c")
|
||||
done
|
||||
command -v nvim >/dev/null 2>&1 && found+=("nvim -l")
|
||||
fi
|
||||
[ "${#found[@]}" -gt 0 ] || { echo "test-lua: no Lua here (lua5.4, lua, luajit or nvim)" >&2; exit 2; }
|
||||
[ "${1:-}" = "--all" ] || found=("${found[0]}")
|
||||
|
||||
n=0
|
||||
for lua in "${found[@]}"; do
|
||||
echo "test-lua: $lua"
|
||||
n=$((n + 1))
|
||||
mkdir "$tmp/run$n"
|
||||
# shellcheck disable=SC2086 # "nvim -l" is two words on purpose
|
||||
LLEMBAS_TEST_TMP="$tmp/run$n" $lua llembas/tests/run.lua
|
||||
done
|
||||
@@ -1223,7 +1223,9 @@ impl Client {
|
||||
prefer_mux: bool,
|
||||
class_name: &str,
|
||||
) -> anyhow::Result<config::UnixDomain> {
|
||||
match std::env::var_os("WEZTERM_UNIX_SOCKET") {
|
||||
// LLeMbas TTY: its own variable names here and below; WezTerm's own
|
||||
// are never read, so a WezTerm pane that starts us is not taken for ours.
|
||||
match std::env::var_os("LLEMBAS_TTY_UNIX_SOCKET") {
|
||||
Some(path) if !path.is_empty() => Ok(config::UnixDomain {
|
||||
socket_path: Some(path.into()),
|
||||
..Default::default()
|
||||
@@ -1245,7 +1247,7 @@ impl Client {
|
||||
.first()
|
||||
.ok_or_else(|| {
|
||||
anyhow!(
|
||||
"no default unix domain is configured and WEZTERM_UNIX_SOCKET \
|
||||
"no default unix domain is configured and LLEMBAS_TTY_UNIX_SOCKET \
|
||||
is not set in the environment"
|
||||
)
|
||||
})?
|
||||
@@ -1315,7 +1317,7 @@ impl Client {
|
||||
let pane_id: PaneId = match pane_id {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
if let Ok(pane) = std::env::var("WEZTERM_PANE") {
|
||||
if let Ok(pane) = std::env::var("LLEMBAS_TTY_PANE") {
|
||||
pane.parse()?
|
||||
} else {
|
||||
let mut clients = self.list_clients().await?.clients;
|
||||
@@ -1323,7 +1325,7 @@ impl Client {
|
||||
clients.sort_by(|a, b| b.last_input.cmp(&a.last_input));
|
||||
if clients.is_empty() {
|
||||
anyhow::bail!(
|
||||
"--pane-id was not specified and $WEZTERM_PANE
|
||||
"--pane-id was not specified and $LLEMBAS_TTY_PANE
|
||||
is not set in the environment, and I couldn't
|
||||
determine which pane was currently focused"
|
||||
);
|
||||
|
||||
@@ -4,7 +4,8 @@ use config::{GuiPosition, SshParameters};
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub const DEFAULT_WINDOW_CLASS: &str = "org.wezfurlong.wezterm";
|
||||
// LLeMbas TTY: its own window class / app id
|
||||
pub const DEFAULT_WINDOW_CLASS: &str = "eu.llembas.tty";
|
||||
|
||||
/// Helper for parsing config overrides
|
||||
pub fn name_equals_value(arg: &str) -> Result<(String, String), String> {
|
||||
@@ -62,7 +63,7 @@ pub struct StartCommand {
|
||||
pub _cmd: bool,
|
||||
|
||||
/// Override the default windowing system class.
|
||||
/// The default is "org.wezfurlong.wezterm".
|
||||
/// The default is "eu.llembas.tty".
|
||||
/// Under X11 and Windows this changes the window class.
|
||||
/// Under Wayland this changes the app_id.
|
||||
/// This changes the class for all windows spawned by this
|
||||
@@ -143,7 +144,7 @@ pub struct SshCommand {
|
||||
pub verbose: bool,
|
||||
|
||||
/// Override the default windowing system class.
|
||||
/// The default is "org.wezfurlong.wezterm".
|
||||
/// The default is "eu.llembas.tty".
|
||||
/// Under X11 and Windows this changes the window class.
|
||||
/// Under Wayland this changes the app_id.
|
||||
/// This changes the class for all windows spawned by this
|
||||
@@ -175,7 +176,7 @@ pub struct SerialCommand {
|
||||
pub baud: Option<usize>,
|
||||
|
||||
/// Override the default windowing system class.
|
||||
/// The default is "org.wezfurlong.wezterm".
|
||||
/// The default is "eu.llembas.tty".
|
||||
/// Under X11 and Windows this changes the window class.
|
||||
/// Under Wayland this changes the app_id.
|
||||
/// This changes the class for all windows spawned by this
|
||||
@@ -213,7 +214,7 @@ pub struct ConnectCommand {
|
||||
pub new_tab: bool,
|
||||
|
||||
/// Override the default windowing system class.
|
||||
/// The default is "org.wezfurlong.wezterm".
|
||||
/// The default is "eu.llembas.tty".
|
||||
/// Under X11 and Windows this changes the window class.
|
||||
/// Under Wayland this changes the app_id.
|
||||
/// This changes the class for all windows spawned by this
|
||||
|
||||
@@ -9,6 +9,12 @@ publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
# LLeMbas TTY: its own binary name, so that it installs beside WezTerm.
|
||||
# The package keeps upstream's name.
|
||||
[[bin]]
|
||||
name = "llembas-tty-gui"
|
||||
path = "src/main.rs"
|
||||
|
||||
[features]
|
||||
default = ["vendored-fonts", "wayland"]
|
||||
wayland = ["window/wayland"]
|
||||
|
||||
+10
-5
@@ -66,9 +66,11 @@ pub use selection::SelectionMode;
|
||||
pub use termwindow::{set_window_class, set_window_position, TermWindow, ICON_DATA};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
// LLeMbas TTY: its own name and version
|
||||
#[command(
|
||||
about = "Wez's Terminal Emulator\nhttp://github.com/wezterm/wezterm",
|
||||
version = config::wezterm_version()
|
||||
name = "llembas-tty-gui",
|
||||
about = "LLeMbas TTY: a terminal with LLeMbas built in, based on Wez's Terminal Emulator\nhttp://github.com/wezterm/wezterm",
|
||||
version = config::llembas_tty_long_version()
|
||||
)]
|
||||
struct Opt {
|
||||
/// Skip loading wezterm.lua
|
||||
@@ -412,7 +414,8 @@ async fn async_run_terminal_gui(
|
||||
) -> anyhow::Result<()> {
|
||||
let unix_socket_path =
|
||||
config::RUNTIME_DIR.join(format!("gui-sock-{}", unsafe { libc::getpid() }));
|
||||
std::env::set_var("WEZTERM_UNIX_SOCKET", unix_socket_path.clone());
|
||||
// LLeMbas TTY: its own variable name
|
||||
std::env::set_var("LLEMBAS_TTY_UNIX_SOCKET", unix_socket_path.clone());
|
||||
wezterm_blob_leases::register_storage(Arc::new(
|
||||
wezterm_blob_leases::simple_tempdir::SimpleTempDir::new_in(&*config::CACHE_DIR)?,
|
||||
))?;
|
||||
@@ -561,7 +564,8 @@ impl Publish {
|
||||
"Running GUI is a different executable from us, will start a new one");
|
||||
}
|
||||
if vers.config_file_path
|
||||
!= std::env::var_os("WEZTERM_CONFIG_FILE").map(Into::into)
|
||||
// LLeMbas TTY: its own variable name
|
||||
!= std::env::var_os("LLEMBAS_TTY_CONFIG_FILE").map(Into::into)
|
||||
{
|
||||
*self = Publish::NoConnectNoPublish;
|
||||
anyhow::bail!(
|
||||
@@ -1172,7 +1176,8 @@ fn run() -> anyhow::Result<()> {
|
||||
{
|
||||
unsafe {
|
||||
::windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID(
|
||||
::windows::core::PCWSTR(wide_string("org.wezfurlong.wezterm").as_ptr()),
|
||||
// LLeMbas TTY: its own application id
|
||||
::windows::core::PCWSTR(wide_string("eu.llembas.tty").as_ptr()),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,9 @@ lazy_static::lazy_static! {
|
||||
static ref POSITION: Mutex<Option<GuiPosition>> = Mutex::new(None);
|
||||
}
|
||||
|
||||
pub const ICON_DATA: &'static [u8] = include_bytes!("../../../assets/icon/terminal.png");
|
||||
// LLeMbas TTY: its own window icon (128x128 RGBA PNG, as upstream's is)
|
||||
pub const ICON_DATA: &'static [u8] =
|
||||
include_bytes!("../../../llembas/packaging/icons/eu.llembas.tty-128.png");
|
||||
|
||||
pub fn set_window_position(pos: GuiPosition) {
|
||||
POSITION.lock().unwrap().replace(pos);
|
||||
|
||||
@@ -868,7 +868,8 @@ impl SessionHandler {
|
||||
codec_vers: CODEC_VERSION,
|
||||
version_string: config::wezterm_version().to_owned(),
|
||||
executable_path,
|
||||
config_file_path: std::env::var_os("WEZTERM_CONFIG_FILE")
|
||||
// LLeMbas TTY: its own variable name
|
||||
config_file_path: std::env::var_os("LLEMBAS_TTY_CONFIG_FILE")
|
||||
.map(Into::into),
|
||||
})))
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
# LLeMbas TTY: its own binary name, so that it installs beside WezTerm.
|
||||
# The package keeps upstream's name.
|
||||
[[bin]]
|
||||
name = "llembas-tty-mux-server"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
async_ossl.workspace = true
|
||||
|
||||
@@ -15,9 +15,11 @@ use wezterm_mux_server_impl::update_mux_domains_for_server;
|
||||
mod daemonize;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
// LLeMbas TTY: its own name and version
|
||||
#[command(
|
||||
about = "Wez's Terminal Emulator\nhttp://github.com/wezterm/wezterm",
|
||||
version = config::wezterm_version(),
|
||||
name = "llembas-tty-mux-server",
|
||||
about = "LLeMbas TTY: a terminal with LLeMbas built in, based on Wez's Terminal Emulator\nhttp://github.com/wezterm/wezterm",
|
||||
version = config::llembas_tty_long_version(),
|
||||
trailing_var_arg = true,
|
||||
)]
|
||||
struct Opt {
|
||||
@@ -195,8 +197,9 @@ fn run() -> anyhow::Result<()> {
|
||||
"OLDPWD",
|
||||
"PWD",
|
||||
"SHLVL",
|
||||
"WEZTERM_PANE",
|
||||
"WEZTERM_UNIX_SOCKET",
|
||||
// LLeMbas TTY: its own variable names
|
||||
"LLEMBAS_TTY_PANE",
|
||||
"LLEMBAS_TTY_UNIX_SOCKET",
|
||||
"_",
|
||||
] {
|
||||
std::env::remove_var(name);
|
||||
@@ -311,7 +314,8 @@ mod ossl;
|
||||
pub fn spawn_listener() -> anyhow::Result<()> {
|
||||
let config = configuration();
|
||||
for unix_dom in &config.unix_domains {
|
||||
std::env::set_var("WEZTERM_UNIX_SOCKET", unix_dom.socket_path());
|
||||
// LLeMbas TTY: its own variable name
|
||||
std::env::set_var("LLEMBAS_TTY_UNIX_SOCKET", unix_dom.socket_path());
|
||||
let mut listener = wezterm_mux_server_impl::local::LocalListener::with_domain(unix_dom)?;
|
||||
thread::spawn(move || {
|
||||
listener.run();
|
||||
|
||||
@@ -105,9 +105,10 @@ async fn show_notif_impl(notif: ToastNotification) -> Result<(), Box<dyn std::er
|
||||
hints.insert("urgency", Value::U8(1 /* Normal */));
|
||||
let notification = proxy
|
||||
.notify(
|
||||
"wezterm",
|
||||
// LLeMbas TTY: its own application name and icon
|
||||
"llembas-tty",
|
||||
0,
|
||||
"org.wezfurlong.wezterm",
|
||||
"eu.llembas.tty",
|
||||
¬if.title,
|
||||
¬if.message,
|
||||
if notif.url.is_some() {
|
||||
|
||||
@@ -78,7 +78,8 @@ fn show_notif_impl(toast: TN) -> Result<(), Box<dyn std::error::Error>> {
|
||||
*/
|
||||
|
||||
let notifier = ToastNotificationManager::CreateToastNotifierWithId(HSTRING::from(
|
||||
"org.wezfurlong.wezterm",
|
||||
// LLeMbas TTY: its own application id
|
||||
"eu.llembas.tty",
|
||||
))?;
|
||||
|
||||
notifier.Show(¬if)?;
|
||||
|
||||
@@ -7,6 +7,12 @@ publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
# LLeMbas TTY: its own binary name, so that it installs beside WezTerm.
|
||||
# The package keeps upstream's name.
|
||||
[[bin]]
|
||||
name = "llembas-tty"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
chrono.workspace = true
|
||||
|
||||
@@ -6,7 +6,7 @@ use wezterm_client::client::Client;
|
||||
pub struct ActivatePane {
|
||||
/// Specify the target pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use wezterm_client::client::Client;
|
||||
pub struct ActivatePaneDirection {
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ pub struct ActivateTab {
|
||||
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
///
|
||||
/// The pane is used to figure out which window
|
||||
/// contains appropriate tabs
|
||||
|
||||
@@ -9,7 +9,7 @@ use wezterm_client::client::Client;
|
||||
pub struct CliAdjustPaneSize {
|
||||
/// Specify the target pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
/// Specify the direction to resize in
|
||||
|
||||
@@ -8,7 +8,7 @@ use wezterm_client::client::Client;
|
||||
pub struct GetPaneDirection {
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use wezterm_term::{ScrollbackOrVisibleRowIndex, StableRowIndex};
|
||||
pub struct GetText {
|
||||
/// Specify the target pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use wezterm_client::client::Client;
|
||||
pub struct KillPane {
|
||||
/// Specify the target pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use wezterm_client::client::Client;
|
||||
pub struct MovePaneToNewTab {
|
||||
/// Specify the pane that should be moved.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct RenameWorkspace {
|
||||
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
///
|
||||
/// The pane is used to figure out which workspace
|
||||
/// should be renamed.
|
||||
|
||||
@@ -8,7 +8,7 @@ use wezterm_client::client::Client;
|
||||
pub struct SendText {
|
||||
/// Specify the target pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct SetTabTitle {
|
||||
tab_id: Option<TabId>,
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
///
|
||||
/// The pane is used to figure out which tab should be renamed.
|
||||
#[arg(long)]
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct SetWindowTitle {
|
||||
window_id: Option<WindowId>,
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
///
|
||||
/// The pane is used to figure out which window
|
||||
/// should be renamed.
|
||||
|
||||
@@ -12,7 +12,7 @@ use wezterm_client::client::Client;
|
||||
pub struct SpawnCommand {
|
||||
/// Specify the current pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
/// The pane is used to determine the current domain
|
||||
/// and window.
|
||||
#[arg(long)]
|
||||
|
||||
@@ -10,7 +10,7 @@ use wezterm_client::client::Client;
|
||||
pub struct SplitPane {
|
||||
/// Specify the pane that should be split.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use wezterm_client::client::Client;
|
||||
pub struct ZoomPane {
|
||||
/// Specify the target pane.
|
||||
/// The default is to use the current pane based on the
|
||||
/// environment variable WEZTERM_PANE.
|
||||
/// environment variable LLEMBAS_TTY_PANE.
|
||||
#[arg(long)]
|
||||
pane_id: Option<PaneId>,
|
||||
|
||||
|
||||
+9
-5
@@ -2,7 +2,8 @@ use anyhow::{anyhow, Context};
|
||||
use clap::builder::ValueParser;
|
||||
use clap::{Parser, ValueEnum, ValueHint};
|
||||
use clap_complete::{generate as generate_completion, shells, Generator as CompletionGenerator};
|
||||
use config::{wezterm_version, ConfigHandle};
|
||||
// LLeMbas TTY: its own version for --version
|
||||
use config::{llembas_tty_long_version, ConfigHandle};
|
||||
use mux::Mux;
|
||||
use std::ffi::OsString;
|
||||
use std::io::Read;
|
||||
@@ -22,9 +23,11 @@ mod cli;
|
||||
// let message = "; ❤ 😍🤢\n\x1b[91;mw00t\n\x1b[37;104;m bleet\x1b[0;m.";
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
// LLeMbas TTY: its own name and version
|
||||
#[command(
|
||||
about = "Wez's Terminal Emulator\nhttp://github.com/wezterm/wezterm",
|
||||
version = wezterm_version()
|
||||
name = "llembas-tty",
|
||||
about = "LLeMbas TTY: a terminal with LLeMbas built in, based on Wez's Terminal Emulator\nhttp://github.com/wezterm/wezterm",
|
||||
version = llembas_tty_long_version()
|
||||
)]
|
||||
pub struct Opt {
|
||||
/// Skip loading wezterm.lua
|
||||
@@ -771,10 +774,11 @@ fn delegate_to_gui(saver: UmaskSaver) -> anyhow::Result<()> {
|
||||
// Restore the original umask
|
||||
drop(saver);
|
||||
|
||||
// LLeMbas TTY: its own binary names
|
||||
let exe_name = if cfg!(windows) {
|
||||
"wezterm-gui.exe"
|
||||
"llembas-tty-gui.exe"
|
||||
} else {
|
||||
"wezterm-gui"
|
||||
"llembas-tty-gui"
|
||||
};
|
||||
|
||||
let exe = std::env::current_exe()?
|
||||
|
||||
Reference in new issue
Block a user