Deterministic planner for human-like typing.
https://ocaml.org/p/keyseq/latest
| examples | Initial commit | |
| lib | Initial commit | |
| test | Initial commit | |
| .gitignore | Initial commit | |
| CHANGES.md | Initial commit | |
| demo.gif | Initial commit | |
| dune-project | Initial commit | |
| keyseq.opam | Initial commit | |
| LICENSE | Initial commit | |
| README.md | Initial commit | |
keyseq
Deterministic planner for human-like typing. Turns a string into a sequence of typing events — insert, delete, delay, idle — for a renderer to play back.
Requirements
- OCaml ≥ 4.14 (uses
String.get_utf_8_uchar).
Install
opam install keyseq
Use
let state = Random.State.make [| 1 |] in
match Keyseq.plan Keyseq.default_config state "Hello, world." with
| Ok events -> Keyseq_terminal.run events
| Error (Keyseq.Invalid_utf8 offset) ->
Printf.eprintf "invalid UTF-8 at byte %d\n" offset
See examples/demo.ml for a complete, runnable example.
Behavior
Sleepis an ordinary inter-character delay.Idleis a longer pause, following a sentence-ending. ! ?, during which a renderer may animate the cursor.- Mid-clause punctuation (
, ; : —) gets aSleeppause only, noIdle. - Typos are only generated for ASCII letters and Cyrillic-block
letters; nothing else is ever mistyped, regardless of
typo_rate. - All randomness is explicit: callers pass a
Random.State.t, and the library never callsRandom.self_init. Same config, same unconsumed state, same input text — same output, every time.
Failure modes
Keyseq.planreturnsError (Invalid_utf8 offset)if the input isn't valid UTF-8.offsetis a byte offset.Keyseq.planraisesInvalid_argumentifconfigviolates its own preconditions (e.g.max_delay < min_delay) — this is a programmer error, not an input-validation failure.
License
ISC. See LICENSE.