The log lines are not padded, so when a row got shorter than it had been in the
previous frame (the ' ..' trim marker is three characters, a value line is
more) the tail of the old row survived and read as one garbled line, e.g.
'.. t> 123'.
Each console row now ends with an erase-to-end-of-line when the view owns the
terminal, and the frames stop leaving debris behind.
Checked with ',.,.,.' fed 1 2 3 4: the trim marker shows as a clean ' ..' above
the last six events, and no row carries text from the frame before it.
requested change: keep the in (n) / out (n) inside the frame as single line
summaries, but log every event outside the frame so the interleaving of inputs
and outputs is readable:
| in (2) 123 65 |
| out (2) 123 65 |
input> 123
output> 123
input> 65
output> 65
The log keeps the last 6 events (older ones show as '..') so a long run does not
grow the console without bound; the prompt is still a separate empty 'input> '
line at the very bottom, which keeps the cursor the last thing on screen.
Tapes that only produce output now get the output> log too, which is what
replaces the replay that used to be printed after the run.
Three fixes from looking at a real run:
* input> showed only the last value. Both console lines now record every
value (with the same '..' trim as the out box), so a run that read 123 then
65 shows input> 123 65.
* output> was printed above input> even though the output happened later.
The order is now chronological: input record first, output record second,
and the prompt is a separate empty 'input> ' line under both, so the cursor
is always the very last thing and nothing can appear above it afterwards.
* with the console showing output>, replaying every OUT value after the run
was just noise: replay_output is off now (live still mutes OUT while the
frame is being drawn, so the values only appear in the console).
Checked with tapes/echo2.rot8 (',.,.'), fed 123 then 65 through a pipe: while
waiting for the second value the console reads 'output> 123' then an empty
'input> ', and at the end 'input> 123 65' / 'output> 123 65' with nothing
printed after. --input and --dump paths unchanged.
Two things were wrong with the first attempt:
* a tape that starts with INP never drew its opening frame, because the
prompt ran before the hook and there was no iterator to render with. The
input callback now receives the iterator, so it can paint the frame and
then ask -- the initial memory state is visible again.
* putting the prompt inside the frame left the cursor at the end of the
frame, which reads badly. The records stay inside:
| in (1) 13 |
| out (1) 13 |
and the prompt moved below the window, like a shell prompt under it:
output> 13
input> 13
output> grows with every OUT; input> is the prompt while INP waits and
becomes the value just given afterwards. The cursor sits right after
'input> ', outside the frame, so typing does not fight the drawing.
Tapes that never read input get none of the lines outside the frame, and the
existing tapes look exactly as before.
Checked: echo.rot8 first frame now shows step 0 / pc 0000 / op INP with the
memory grid, then input> below; --input 42 still prints 42; --dump and the
piped live run are unchanged.
Printing 'input> ' where the cursor happened to be made a mess of the frame, so
the prompt is now part of it:
| in (1) 13 |
| out (1) 13 |
While INP waits the line reads 'input> ' and the cursor is left at its end, so
the number is typed in place; afterwards the line turns into the record of what
was fed in, mirroring the out box. A tape that never reads input gets no extra
line at all, so nothing changes for the existing tapes.
The frame also got a redraw helper, because the prompt has to repaint the frame
before asking; the live hook now goes through the same helper.
One case cannot use the frame: a tape like tapes/echo.rot8 (just ',.') reaches
INP before the first frame is drawn, so there is nothing to hang the prompt
above and it falls back to a plain 'input> ' on the current line. Longer tapes
show it inside the frame.
Checked: --full frame shows in above out, compact frame shows the in line too,
wave/and/or/full_adder are unchanged, and the value still reaches the program.
INP read straight from stdin with scanf, which the live view cannot offer: the
view owns the terminal, and a tape that wants input either ate a number nobody
typed or blocked on a pipe.
INP now takes its value from, in order:
1. a queue filled by --input "7,5" (spaces or commas, scripts and tests)
2. a hook the live view installs: it prints 'input> ' under the frame and
reads a line, redraws on the next tick, and feeds 0 when stdin is done so
a tape behind a pipe still finishes
3. stdin, exactly as before
So nothing changes for a plain run, and --live can drive programs that need
input. tapes/echo.rot8 (just ',.') is the smallest tape that exercises it.
rot8_test --input 42 tapes/echo.rot8 -> 42
rot8_test --live tapes/echo.rot8 -> asks under the view
Tests: --input with one value, with a list, a live run fed through a pipe
(prints 5), and a live run with stdin already closed (feeds 0, terminates).
The --dump path and the untouched tapes (and, or, full_adder, wave) still work.
A terminal can be a pipe: web terminals and IDE panels hand the program a
pipe for stdout, so isatty() says no, --live quietly fell back to printing
one frame after another and -f was ignored. Add -t to say "there is a
terminal at the other end anyway" (and --no-tty for the opposite), and say
so on stderr when the fallback happens, so the flag can be found.
Frames no longer end with a newline, so a frame of N lines needs N rows
instead of N+1 and a 24 row terminal shows the whole compact frame. The
size heuristics follow from that: shorter than 30 rows -> compact, size
unknown (behind a pipe) -> compact, LINES is honoured when the console
cannot be asked, and --full forces the tall frame.
Colour is now only switched off for a real console that cannot do VT, not
for every stream that is not a console: behind a pipe the far end may be
perfectly capable.
The machine can now hand a hook the whole execution, and rot8_viz draws
what it sees: the 256 cell tape as a hex map, the cell under the pointer
with its eight bits, the program counter and the values OUT produced.
rot8_test --live tapes/wave.rot8 # redraw in place while it runs
rot8_test --dump tapes/and.rot8 # one static snapshot at the end
Frames are plain ASCII, so the view survives pipes, ssh and logs; colour
is ANSI and only used when the terminal can take it. Running without
--live or --dump behaves exactly as before: the tape just runs.
rot8.h gains rot8_run_hooked() plus read-only accessors for the tape,
the program counter and the step count, so that tools do not have to
reach into rot8_iter. read_tape() now reports a missing file and stops
at the end of the buffer instead of writing past it. Also fixes the
ROR/FLB opcode comments, which had the BF characters the wrong way round.
tapes/wave.rot8 is a small demo: it walks a single set bit across 240
cells, which looks like a wave moving over the tape.