package tiny_libs
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
From-scratch libraries for teaching: graphics, audio, compression, crypto, networking and more
Install
dune-project
Dependency
Authors
Maintainers
Sources
0.3.6.tar.gz
md5=7c636383d146d30ac6f2fa234a6253c8
sha512=c79f3823c5f8f57e5038eb640d487c61168b84aa07c61999d6622ef9fd0c890e2b03b4c6a7cdbbe9352a49e25dda00ac7bb14693cee8e3d7beeed251351a2af0
doc/src/tiny_libs.terminal_unix/Tty_unix.ml.html
Source file Tty_unix.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53(* Claude Code * * Copyright (C) 2026 Yoann Padioleau * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License * (LGPL) as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. *) (* See Tty_unix.mli *) let write (s : string) : unit = let rec go i = if i < String.length s then go (i + Unix.write_substring Unix.stdout s i (String.length s - i)) in go 0 (* the bytes waiting on stdin, none if none *) let available () : string = let buf = Bytes.create 256 in match Unix.read Unix.stdin buf 0 256 with n -> Bytes.sub_string buf 0 n | exception Unix.Unix_error (Unix.EAGAIN, _, _) -> "" let run (_caps : < Cap.stdin ; Cap.stdout ; .. >) (p : 'model Tui.program) : unit = let saved = Unix.tcgetattr Unix.stdin in (* raw: keys at once, unechoed, Control-C a key; a read returning what is there, maybe nothing *) Unix.tcsetattr Unix.stdin Unix.TCSANOW { saved with c_icanon = false; c_echo = false; c_isig = false; c_ixon = false; c_icrnl = false; c_vmin = 0; c_vtime = 0 }; write "\x1b[?1049h"; Fun.protect ~finally:(fun () -> write "\x1b[0m\x1b[?25h\x1b[?1049l"; Unix.tcsetattr Unix.stdin Unix.TCSANOW saved) (fun () -> let screen = p.view p.init in write (Curses.redraw screen); let rec loop (model : 'model) (shown : Curses.t) (last : float) = if not (p.over model) then begin (match Unix.select [ Unix.stdin ] [] [] 0.05 with _ -> () | exception Unix.Unix_error (Unix.EINTR, _, _) -> ()); let keys = Line_discipline.split_keys (available ()) in (* Control-C: the program's end, in raw mode as without *) if List.mem "\x03" keys then () else begin let model = List.fold_left (fun m k -> p.update (Key k) m) model keys in let now = Unix.gettimeofday () in (* a pause (the process stopped, Control-Z) isn't time played *) let model = p.update (Tick (Float.min 0.25 (now -. last))) model in let next = p.view model in write (Curses.refresh ~before:shown next); loop model next now end end in loop p.init screen (Unix.gettimeofday ()))
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>