@jsvision/core / flush
Function: flush()
flush(
state,options?):DecodeResult
Defined in: input/decoder.ts:126
Resolve a held, ambiguous trailing ESC as a standalone Escape keypress.
A lone ESC at the end of a chunk could be the Escape key or the first byte of a longer sequence, so decode holds it rather than guess. The host calls flush() when its inter-byte timer (ESC_TIMEOUT_MS) fires with no more bytes: a leading lone ESC in the carry then becomes a key: 'escape' event, and any bytes after it decode normally. With no held ESC, this simply re-scans the carry and typically returns nothing.
Parameters
state
The current decoder state (its carry may hold the lone ESC).
options?
Optional decode options.
Returns
The decode result, including the emitted Escape key when applicable.
Example
ts
import { createDecoderState, decode, flush } from '@jsvision/core';
// A bare ESC arrives with nothing after it.
let r = decode(Uint8Array.from([0x1b]), createDecoderState());
// r.events is empty — the ESC is held in r.state.carry.
// Later, the host's timer fires with no further bytes:
r = flush(r.state);
console.log(r.events[0]); // { type: 'key', key: 'escape', ctrl: false, ... }