Repository navigation
feat(cli): cargo-style colored output and live build progress - #89
Conversation
[Medium impact] The changes reach the `mogs` command-line workflows, especially assignment builds. The PR appears safe to merge, with a non-blocking fix needed for builds whose stdout is disabled. Findings
SummaryAdds shared colors for help, errors, command messages, and build reports.
Acknowledged choices:
|
| let notebook = found.str()?.to_string_lossy().into_owned(); | ||
|
|
||
| let sys = py.import("sys")?; | ||
| sys.getattr("stdout")?.call_method0("flush")?; |
There was a problem hiding this comment.
If a caller sets sys.stdout to None but leaves stderr attached to a terminal, live calls flush() on None. A valid build then raises AttributeError before it starts, even though caps_for accepts absent streams. Skip this flush when stdout is None so progress does not prevent the build from running.
| sys.getattr("stdout")?.call_method0("flush")?; | |
| let stdout = sys.getattr("stdout")?; | |
| if !stdout.is_none() { | |
| stdout.call_method0("flush")?; | |
| } |
Stacked on #88 (which is stacked on #87): the first four commits are theirs. After they merge, this diff shows only the four commits below.
All
mogsoutput gets one look, in the style of cargo and uv.stylemodule inmogs-cliholds the palette (anstyle) and one pure function,caps, that decides per stream whether to use color, a spinner and Unicode: color needs a terminal with a usableTERM(not unset, empty ordumb) and noNO_COLOR; Unicode needs a UTF-8 stream,TERMother thanlinux, and on Windows, Windows Terminal (WT_SESSION); on Windows the console must accept ANSI codes. clap's help and errors use cargo's colors, help texts are capitalized, and the help ends with a link to the docs.error: Build failedwith the message indented under it.initprintsCreated …and the next steps;editprintswarning: …andOpening … in marimo.warning: …lines. The rule is─only on a Unicode color terminal, else-, so a redirected report on Windows (cp1252) no longer crashes. "All done!" is gone.mogs-buildreports its steps (Reading, Resolving, Checking, Testing solved notebook, Testing blank notebook, Packing) through aProgresstrait;crates/mogsdraws them with indicatif on stderr: a spinner on a capable terminal, plain step lines on adumbterminal, nothing when piped. The spinner is cleared around Python calls that may print, on errors, on Ctrl-C and before a panic message.Checked by recording real output with
scriptunder xterm-256color,TERM=dumb,TERMunset,TERM=linux,NO_COLOR=1,LANG=C, piped, cp1252 redirected, and a notebook that triggers a SyntaxWarning: no stray escapes, braille or leftover frames where the stream can't show them. Not run on a real Windows console.