support colour reinsert after resets, switch to intrinsics by default
This commit is contained in:
parent
a4bf011cb0
commit
7146615e04
6 changed files with 54 additions and 33 deletions
|
@ -11,7 +11,8 @@ let write_ansi a =
|
|||
and string_of_colour ?(bg = false) c =
|
||||
let prefix = if bg then "4" else "3" and si = string_of_int in
|
||||
c |> function
|
||||
| Intrinsic i -> prefix ^ si i
|
||||
| Intrinsic i ->
|
||||
if i <= 8 then prefix ^ si i else (if bg then "10" else "9") ^ si (i - 8)
|
||||
| Simple i -> prefix ^ "8;5;" ^ si i
|
||||
| RGB (r, g, b) -> prefix ^ "8;2;" ^ si r ^ ";" ^ si g ^ ";" ^ si b
|
||||
in
|
||||
|
@ -35,18 +36,21 @@ let flush t =
|
|||
t.pos <- 0)
|
||||
|
||||
let serialise t chunk =
|
||||
let input =
|
||||
match chunk with
|
||||
| Text s -> s
|
||||
| Separator s -> s
|
||||
| Delimiter s -> s
|
||||
| Ansi a -> write_ansi a
|
||||
and sz = Bytes.length t.buf in
|
||||
let input_sz = String.length input in
|
||||
if t.pos + input_sz > sz then flush t;
|
||||
if input_sz > sz then print_string input
|
||||
else (
|
||||
Bytes.blit_string input 0 t.buf t.pos input_sz;
|
||||
t.pos <- t.pos + input_sz)
|
||||
if chunk != Empty then (
|
||||
let input =
|
||||
match chunk with
|
||||
| Text s -> s
|
||||
| Separator s -> s
|
||||
| Delimiter s -> s
|
||||
| Ansi a -> write_ansi a
|
||||
| Empty -> assert false
|
||||
and sz = Bytes.length t.buf in
|
||||
let input_sz = String.length input in
|
||||
if t.pos + input_sz > sz then flush t;
|
||||
if input_sz > sz then print_string input
|
||||
else (
|
||||
Bytes.blit_string input 0 t.buf t.pos input_sz;
|
||||
t.pos <- t.pos + input_sz))
|
||||
else ()
|
||||
|
||||
let create = { buf = Bytes.create 4096; pos = 0 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue