Skip to content

fix(tui): complete TUI feature — interactive demo, expected outputs, Windows link#131

Closed
MelbourneDeveloper wants to merge 11 commits into
mainfrom
feature/tui-followups
Closed

fix(tui): complete TUI feature — interactive demo, expected outputs, Windows link#131
MelbourneDeveloper wants to merge 11 commits into
mainfrom
feature/tui-followups

Conversation

@MelbourneDeveloper
Copy link
Copy Markdown
Owner

Follow-up to #130 — complete the TUI feature

PR #130 merged the core runtime (HTTP response handles, JSON parser, terminal control) to main, but a few pieces did not make it into the squash (they were untracked/empty at merge time) and main's tui_repo_table.osp shipped without a valid .expectedoutput. This PR completes and corrects it.

What this adds / fixes

  • examples/tui/api_browser.osp — the interactive colored arrow-key API browser (the showcase demo). Runs with osprey examples/tui/api_browser.osp --run.
  • Valid .expectedoutput for tui_repo_table.osp and a new tested http_response_handle.osp (status/body/header/missing-header/free/double-free). These were empty before, failing TestHTTPExamples with "MISSING expected output".
  • Windows link fix (jit_executor.go, compilation.go) — the JIT/run linker unconditionally linked -lhttp_runtime, -lssl, -lcrypto, -ldl, -lm, none of which exist on the Windows core build, so even a pure-fiber program failed to link. Link the minimal set (fiber + winpthreads) on Windows and prefer MinGW gcc there. Mac/Linux link args are unchanged.
  • builder_literals.go / runtime_builtins_generation.go\e/\xHH string escapes for ANSI colors, named hex constants (mnd lint), and select-based Result wrapping (no extra basic blocks).

Verification

  • TestHTTPExamples and TestFiberExamples pass locally.
  • api_browser.osp runs end-to-end (driven by a scripted key sequence): renders, navigates, opens detail, exits cleanly.

- spawn with a non-constant captured arg (record/runtime value): spill
  captures through per-spawn globals so the fiber closure reloads them
  instead of referencing out-of-scope parent SSA values.
- discriminated union construction: heap-allocate (malloc) instead of
  stack alloca so a union returned from a function no longer dangles
  (garbage int payload / string-payload segfault).
- m[key] on a runtime-built map (Map()/mapSet): route through the C
  runtime get (osprey_map_contains/get) instead of the flat-literal
  array reader, which segfaulted on the opaque OspreyMap* handle.

Covered by examples/tested/basics/knownbugs/bug1..bug4.
Completes the TUI work that did not make it into the squash of #130:
- examples/tui/api_browser.osp: interactive colored arrow-key API browser.
- jit_executor.go: link only the libs the Windows core build provides
  (fiber + winpthreads), prefer MinGW gcc; Mac/Linux link args unchanged.
- select-based Result wrap, \e/\xHH escapes, lowercase example types.
The expectedoutput files for tui_repo_table and http_response_handle were empty
(generated earlier from the wrong working dir), which failed TestHTTPExamples
with "MISSING expected output". Regenerate them with real content and drop the
nonexistent --sandbox-http flag from the api_browser run instructions.
@MelbourneDeveloper MelbourneDeveloper deleted the feature/tui-followups branch May 30, 2026 20:56
MelbourneDeveloper added a commit that referenced this pull request Jun 1, 2026
…eap fix (#132)

## Colored HTTP/JSON TUI — Phases 1–4 of `docs/plans/tui-http-app.md`

Lands the "write a colored TUI in Osprey that calls an HTTP API and
renders the
response" capability, plus the core codegen fix that makes
string-wrapper
helpers usable. Supersedes the closed #131 (rebuilt cleanly on top of
`main`).

### Core codegen fix
`generateInterpolatedString` built every interpolated string into a
**stack**
`alloca` and returned that pointer. The value dangled the moment it
escaped the
frame — a function returning an interpolated string, or a
nested/subsequent
interpolation reusing the frame — producing empty or garbage output. It
only
looked fine when consumed immediately by `print`. Now the buffer is
**heap-allocated** (`malloc`), matching `generateIntToString`. This is
what
makes pure ANSI colour helpers (`fn red(s) = "\e[31m${s}\e[0m"`) work
when their
result is stored in a `let` or re-interpolated.

### Runtime & examples
- **`http_server_runtime.c`** — server "listening"/request diagnostics
now go to
  **stderr**, so tested-example stdout is deterministic.
- **`examples/tested/http/tui_repo_table.osp`** (+ golden) — local
server →
`httpResponseBody` → `jsonParse`/`jsonGet`/`jsonLength` → colored,
aligned
table. Proves the end-to-end pitch. `[HTTP-RESPONSE-HANDLE]`,
`[BUILTIN-JSON]`.
- **`examples/tested/http/http_response_handle.osp`** (+ golden) — full
handle
  lifecycle: status, body, header, missing-header error, free, and a
  double-free that reports `Error` (no crash). `[HTTP-RESPONSE-HANDLE]`.
- **`examples/tui/api_browser.osp`** — interactive arrow-key repo
browser
  (raw mode, `termReadKey`, `termClear`, colored render, detail view).
  `[BUILTIN-TERM]`.
- Regenerated the two `.expectedoutput` golden files that had previously
been
  committed empty (the cause of the earlier red CI).

### Verification
- `make test` (lint + integration + unit + coverage threshold) passes
locally
with no regressions; the interpolation change is exercised across the
suite.
- `tui_repo_table` / `http_response_handle` / `http_server_example`
goldens
  match real program output.
- `api_browser.osp` compiles and renders the colored frame (verified by
a
  scripted non-interactive run).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant