Repository navigation
TurboFrame 0.3.0
The first release of stage 2. It adds the web mode: the same terminal application served to a web browser on
this machine, app --web 127.0.0.1:9090 --res 120x60, with no change to the application but one call in its
main. It also fixes the completion defect turbodoo met with a slow language server, a menu that closed right
after it opened, and two intermittent failures. Every v0.2.1 import still works, and every signature only gains
optional arguments.
TurboFrame is distributed from GitHub only. It is not on PyPI.
Install
pip install "turboframe @ git+https://github.com/divengine/turboframe@v0.3.0"
pip install "turboframe[watch,lsp,web] @ git+https://github.com/divengine/turboframe@v0.3.0" # with the extrasOr the wheel attached to this release (check it against SHA256SUMS).
Requirements
- Python 3.11 or later; tested on 3.11 and 3.12. Linux and Windows, both required in CI; macOS is not tested.
textual>=8.2,<9,textual-vision==0.0.1,rich>=14.2: unchanged.- New extra
web:aiohttp>=3.9.5,<4, for the server. The page's terminal, xterm.js 6.0.0 and its fit addon
0.11.0 (MIT), is shipped inside the package: the page loads nothing from the internet.
New: the web mode (#67)
from turboframe import web
def main() -> None:
if web.launch(title="My app"): # --web given: served until Ctrl+C
return
MyApp().run()my-app --web 127.0.0.1:9090 --res 120x60 # open the address it prints, once
my-app --web :9090 --res auto # the terminal follows the browser window- Each browser tab is a session of its own: the application started again as a child process, with the same
arguments less--weband--res, speaking Textual's web protocol. The application's code does not change. --res COLSxROWSfixes the terminal's size in cells, whatever the window (the page fits the font to it);
--res auto, the default, follows the window.- Keys, Alt and F-keys, Escape (Windows included), the mouse, Unicode, the application's copy to the system
clipboard (OSC 52, through the browser's clipboard API) and a tab's end (the application asks about unsaved
changes first) work as in a terminal. The browser keeps a few keys for itself (Ctrl+W, Ctrl+T, Ctrl+N,
Ctrl+Tab). - Without
--webnothing changes, andturboframe.webimports without the extra. - A frozen application (PyInstaller) serves itself: the child is the executable.
--collect-all turboframe --collect-all textual(or--collect-data turboframe --collect-data textual --collect-submodules textual.drivers) carries the page and the web driver. The first, divide's, is checked in CI on Linux and Windows. - The workbench example runs in a browser:
python examples/workbench/workbench.py --web 127.0.0.1:9090 --res 120x60.
Security, by design and each point with a test (docs/web.md, 4):
| What | How |
|---|---|
| Who can reach it | loopback addresses only (127.0.0.0/8, ::1, localhost); a network address is refused with a message. From another machine: SSH port forwarding, the same port at both ends. |
| The address to open | a secret token, printed once on the server's terminal. It opens once and expires unused after 10 minutes; two requests at the same moment let one browser in. It leaves the address bar at once (a redirect) and is never sent as a Referer. |
| After that | an HttpOnly, SameSite=Strict cookie named by the port (turboframe_session_<port>), for 12 hours, enforced by the server too. Not renewed. Its expiry stops new sessions (tabs, reloads) but does not end the ones already open: those last until their tab closes or the server stops. Another browser or profile needs a restart and its new address. A restart revokes everything and ends every session. |
| Other sites | Host must be the address served (DNS rebinding: 421); the WebSocket's Origin must be the page's own (403); a Content-Security-Policy allows this server only. |
| What the page can do | send keys, sizes and focus; the command is the application's, fixed at start, never a shell. At most 4 sessions (429 beyond) and 1 MiB per message. A request from the application to read the clipboard is never answered. |
| Logs | no access log; the token is not logged. |
Fixed
| Issue | What was wrong | Now |
|---|---|---|
| #69 | With a slow language server a completion that ran out of time looked like an empty one; the requests it superseded stayed in the server; Ctrl+Space waited behind them and showed nothing | LspSession.complete() raises LspTimeout or LspRequestFailed (both LspNoAnswer); a request superseded, cancelled or out of time is cancelled in the server ($/cancelRequest); one completion in flight per editor; an explicit completion is retried once (COMPLETION_RETRY) and then a message says the server did not answer in time |
| #73 | A menu opened by a click closed at once when a click on the desktop came just before it (more often on a slow machine). The cause is in textual-vision, reported there: karellen/textual-vision#2 | DesktopApp ignores, for closing the menu, a click older than the menu's opening (DropMenuBar.activated_at); a click outside an open menu still closes it |
| #68 | A reveal (go_to, a search) done just before the editor was resized (a zoom) left the line where the old size had put it |
the editor reveals again on a resize while the user has not moved the cursor or scrolled |
| #65 | An intermittent test: a language server's sync arriving while a stopped start was discarded | the behaviour is intended and now pinned by its own test; the test no longer races it. No change to the code |
| #77 | (found before release) two web servers on one machine overwrote each other's cookie | the cookie is named by the port |
Each fix has a regression test that fails without it.
Changes to existing modules
None breaks an import or a signature.
turboframe.lsp.session:LspSession.request(method, params, timeout)(with cancellation),complete(), and
the exceptionsLspNoAnswer,LspTimeout,LspRequestFailedare new.completion()behaves as in v0.2.1:
no answer is([], False); it now also cancels in the server what runs out of time.turboframe.ui.lsp.LspMixin:COMPLETION_TIMEOUT(10 s) andCOMPLETION_RETRY(10 s) are class attributes
an application may change. A completion asked while one is pending for the same editor replaces it.turboframe.ui.app.DesktopApp.on_mouse_downandturboframe.ui.desktop.DropMenuBar.activated_atare new
(#73). An application that defines its ownon_mouse_downon itsDesktopAppsubclass keeps TurboFrame's
too: Textual calls both.turboframe.ui.editor.CodeEditorreveals again on a resize (#68).
Known limitations
- Native mode over SSH: after a long idle period the application may seem slow to react to the first clicks
(#75). Not reproduced yet; no cause found in TurboFrame,
Textual or textual-vision. It does not affect the web mode. - The web mode serves this machine only. Serving to a network would need TLS and real authentication; it is not a
setting. Downloads, uploads, reconnecting to a session after a reload, and a reverse proxy are not part of it.
Verification
- 497 unit and component tests on Linux (Python 3.11 and 3.12) and Windows (Python 3.12); the real-terminal tests
on Linux and Windows; and a new CI job,web, that serves the test application and the workbench to Chromium
through Playwright on Linux and Windows (fixed and automatic sizes, keys, Escape and Alt on Windows, the mouse
and the menu bar, sessions and the processes they leave, the clipboard). Missing tools fail these suites in CI
instead of skipping them. - The release workflow builds the sdist and the wheel once, installs the wheel with every extra in clean
environments on Linux and Windows, and runs the unit, real-terminal and browser suites against it: the page and
its terminal are served from the installed package. - The package job checks that the page and xterm.js are in both the sdist and the wheel.
- A new CI job,
frozen, builds the test application as one PyInstaller file withcollect_all(divide's recipe)
on Linux and Windows and serves it to Chromium: the page from the executable's data, the session is the
executable, keys reach it, a reload starts a new session, and stopping the server leaves no process. The
--collect-datarecipe was run by hand on Linux.
Integrating in divide (the web mode's pilot)
- Dependency:
turboframe[watch,lsp,web] @ git+https://github.com/divengine/turboframe@v0.3.0(and[i18n]in
dev).webis optional: without itdivide --websays which extra to install and exits with status 2. - Replaces: nothing.
- Changes, each optional:
src/divide/app.py, first thing inmain(argv), beforeargparse(which would refuse--web):The child gets the same arguments less the web ones, sofrom turboframe import web ... def main(argv: list[str] | None = None) -> None: if web.launch(None if argv is None else ["divide", *argv], title="divide"): return parser = argparse.ArgumentParser(...)
divide --web :9090 ~/projectopens
~/projectin each tab.launch()serves before divide reads its own arguments, so a check that--mcp
and--webare not given together, if divide wants one, goes before the call.- Help:
--web [HOST:PORT]and--res COLSxROWS|autoare TurboFrame's; divide's--helpdoes not list them
unless divide adds them to its parser for the text only. packaging/divide.spec: nothing;collect_all("turboframe")andcollect_all("textual")already carry the
page and the web driver. The build environment needs thewebextra (aiohttp) installed.
- Behaviour changes to expect: menus no longer close when opened right after a click on the desktop; completion
tells the user when the server did not answer an explicit request. - Verify: divide's suites;
divide --web 127.0.0.1:9090 --res 120x60 <project>in a browser (menus by mouse and
keys, the editor, copy to the clipboard, Alt+X with unsaved changes); the same with the binary on Linux and
Windows (TurboFrame's CI checks a one-filecollect_allbuild on both). Not verified by TurboFrame: the Windows
console-script launcher (divide.exefrompip install) as the child's command; the browser tests cover
python script.pyand the frozen executable. - Rollback: pin v0.2.1; nothing else changes.
Integrating in turbodoo
- Dependency:
turboframe[lsp] @ git+https://github.com/divengine/turboframe@v0.3.0(the tag; or the release
commit's SHA, as turbodoo pins today). - Replaces: nothing. turbodoo's
LspSessionsubclass andLspMixinhooks keep working: the fix is in the
completion path they inherit. - Changes, each optional:
acceptance/journeys/test_at_030_python_completion.py: the 90 second wait for the list after Ctrl+Space was
there for #69. An explicit completion now waitsCOMPLETION_TIMEOUTplus oneCOMPLETION_RETRY(20 s by
default) and then shows " did not answer in time: no completion", so the scenario may wait for the
list or that message.LspMixin.COMPLETION_TIMEOUT/COMPLETION_RETRYmay be raised for a server known to be slow at start
(Pyright on a large project).- Code that calls
session.completion()directly may move tocomplete()to tell "no answer" from "nothing
to complete". - The web mode is open to turbodoo too (
web.launch()incli/main.py), when it chooses; it is not part of
this integration.
- Behaviour changes to expect: typing fast no longer queues completions in the server; an explicit completion
with no answer shows a message instead of nothing. - Verify: turbodoo's unit, acceptance (AT-030 on a slow machine) and real-terminal suites, the wheel in a clean
environment, the binary. - Rollback: pin v0.2.1 (
75dbdee).