Repository navigation
Add sight console: Stata's console with highlighting, completion and colors - #335
Merged
Merged
Conversation
`sight console` runs the Stata console binary (stata-mp, stata-se, ...) in a pseudo-terminal and wraps it, in the spirit of Raven's console: syntax highlighting as you type (Sight's lexer), Tab completion (Sight's completion provider over the lines entered this session), persistent history, and best-effort output colors (errors before `r(NNN);` and `--Break--` red, notes yellow, do-file echo lines highlighted). Input follows the rlwrap model: a line goes to Stata only on Enter, whether or not a prompt was recognized, so `_request()` input and typeahead work as in plain console Stata. A recognized prompt only adds highlighting, completion, and loading of the next staged pasted line, which never runs without Enter. Bun's PTY is not the child's controlling terminal, so Ctrl+C and resizes signal Stata directly (SIGINT, SIGWINCH) rather than relying on the line discipline. Echo is turned off through the PTY's termios; if Stata turns it back on, the console shows each line once. The PTY needs Bun (the native binary); under Node, interactive use exits with a message and piped input passes straight through to Stata. Tests run the real CLI in a PTY against a fake Stata fixture.
Record `end` entered at a Mata or Python prompt so the transcript's embedded block closes, and keep a running command's failure tracking when the user types ahead. History no longer changes the mode of an existing directory.
Stata 18's console puts its terminal in raw mode and echoes input itself, so every line showed twice. When Stata echoes (raw mode or echo on), drop exactly one copy of the submitted line from the start of its output, allowing for the wrap marker Stata inserts in long lines; anything else is shown unchanged. Lines typed while Stata is busy are left for Stata to echo when it reads them. Also reset the cursor-key mode Stata turns on, and add a raw mode to the fake Stata. Verified against StataMP 18 on macOS.
Contributor
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 57 minutes. View limit details
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Console Stata is bare: no syntax highlighting, no completion, no history, plain output. Raven's
raven consolefixed that for R. This PR adds the Stata equivalent,sight console. It's simpler than Raven's: Stata can't be embedded, so there's no debugger. Sight runs the Stata console binary in a pseudo-terminal and wraps it, like a smarterrlwrap stata-mp.What you get:
r(NNN);and--Break--in red,note:/warning:in yellow, and do-file echo lines highlighted.Design points:
_request()input and typing ahead behave as in plain console Stata.TPGID 0), so Ctrl+C and resizes signal Stata directly (SIGINT, SIGWINCH).\r\n>Stata inserts when it wraps a long line). Anything else is shown unchanged.It's marked experimental. VS Code integration is left for a follow-up.
Proof:
--Break--are red.`my→`myname',summ→summarize,de→detail.sleep 10000.--more--takes one key (space continues,qbreaks). A resize changedc(linesize)from 79 to 49._request,foreachblocks, Mata and Python prompts, typing ahead, staged paste, and Ctrl+D to quit all worked. The history file has mode 600.tests/fixtures/console/fake-stata.ts) now reproduces.bun run typecheck,bun run lintandbun run check:line-endingspass.bun test ./testspasses excepthelp-topic-coverage, which needs a full local Stata install and fails the same way onmainon the build machine.Reviewed with sol-loop: 3 rounds with gpt-6.1-sol. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code); plan reviewed by Claude Sonnet and GPT-6.1 Terra.