Skip to main content

Module logic_loop

Module logic_loop 

Source
Expand description

The main REPL event loop - input handling, rendering, and evaluation dispatch.

§State

VariablePurpose
input_bufThe current line being typed
accumulatedMultiline buffer - grows until is_complete is true
cursor_posCursor position in chars (not bytes)
historySubmitted input history, navigated with /
history_idxCurrent position in history (None = live input)
attachedFiles evaluated into the env via :attach
scroll_offsetOutput scroll position (0 = bottom, higher = older)

§Multiline input

Lines are accumulated into accumulated until is_complete returns true and the last line does not end with { (a bare block opener waits for body). The prompt switches from >> to .. while accumulating. Esc cancels and clears the accumulator.

§Evaluation flow

Enter key
  |
  |- starts with ':'  ──► handle_command
  |
  |- code input
       |
       |- not complete yet --> keep accumulating
       |
       |- complete --> eval_input --> output buffer

Functions§

run_repl
Runs the REPL event loop until the user exits with Ctrl+C or :exit.