Skip to main content

Module vga_input

Module vga_input 

Source
Expand description

Lock-free mouse -> console command hand-off.

The mouse task must never hold VGA_WRITER: it publishes the input work here and the console-render task (which already owns the writer) applies it. Single-producer/single-consumer ring: the mouse task pushes, the console task pops. No allocation, no locks.

Press/release ordering is preserved: the mouse task’s local button state machine emits Press before Release for a turn that observes both, and each turn is published as one unit (a single tail store) so the renderer never observes a half-written turn.

Re-exportsΒ§

use core::cell::UnsafeCell; πŸ”’
use core::sync::atomic::AtomicBool; πŸ”’
use core::sync::atomic::AtomicUsize; πŸ”’
use core::sync::atomic::Ordering; πŸ”’

StructsΒ§

InputState
Renderer-owned state carried across ticks; identical to the state the mouse task used to keep locally.
Ring πŸ”’

EnumsΒ§

InputCommand
A deferred input action, applied by the console-render task.

ConstantsΒ§

INPUT_RING_CAPACITY
Ring slot count. One slot is reserved to distinguish full from empty, so the usable capacity is INPUT_RING_CAPACITY - 1 (63) commands.
LINES_PER_NOTCH πŸ”’
Text lines moved per mouse-wheel notch. The wheel is eased: the console tick applies one line per frame, so a notch settles over three frames.
MAX_TURN_COMMANDS
Maximum commands the mouse task can emit for one turn, including the trailing InputCommand::EndTurn marker.
MOUSE_RENDER_MIN_TICKS πŸ”’
Minimum ticks between mouse visual renders (was in mouse.rs).
RING_MASK πŸ”’
SCROLLBAR_DRAG_MIN_TICKS πŸ”’
Minimum ticks between scrollbar-drag applies (was in mouse.rs).

StaticsΒ§

INPUT_PENDING πŸ”’
RING πŸ”’

FunctionsΒ§

apply_input
Drain complete turns and apply each to writer with the exact call sequence/order of the old in-lock mouse loop. Returns whether anything was applied (commands consumed or a pending visual rendered).
apply_turn πŸ”’
Apply the commands of one mouse turn, preserving the original batching.
discard
Drop every queued command (used when the console is unavailable).
has_pending_visual πŸ”’
has_space
Whether a full turn can be enqueued without dropping any command.
push_turn
Publish one turn (the slice must end with InputCommand::EndTurn). Returns false when the ring cannot hold the whole turn.
render_pending πŸ”’
Apply the pending visual updates under the original tick gates.
take_pending
Take and clear the pending flag.
wake
Publish that input work is ready; consumed by take_pending.