WIP layout engine

This commit is contained in:
2024-10-10 12:54:53 -06:00
commit 13c8a36ba7
17 changed files with 685 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
open Unix
open Ansi
open Widgets
let write_out line =
ignore (write stdout (String.to_bytes line) 0 (String.length line))
let set_raw_mode fd =
let original_attrs = tcgetattr fd in
let raw_attrs = original_attrs in
raw_attrs.c_ignbrk <- false; (* Do not ignore break conditions *)
raw_attrs.c_icanon <- false; (* Disable canonical mode *)
raw_attrs.c_echo <- false; (* Disable echo mode *)
tcsetattr fd TCSAFLUSH raw_attrs;
(* Hide cursor *)
write_out "\027[?25l";
original_attrs (* Return original attributes *)
let restore_terminal fd original_attrs =
(* Show cursor *)
write_out "\027[?25h";
tcsetattr fd TCSADRAIN original_attrs
let setup_terminal () =
let fd = stdin in
let original_attrs = set_raw_mode fd in
let off: offset = {x = 1000; y = 1000;} in
let color = red in
let {x = term_x; y = term_y} = termsize in
(* let out_channel = out_channel_of_descr stdout in *)
write_out "Raw mode enabled.\n";
(* flush out_channel; *)
sleepf 0.5;
let cursor = Cursor (Move {x = term_x; y = term_y}) |> string_of_ansi in
(* Printf.sprintf "\027[%d;%dH" (term_y - 10) (termsize.x - 10) in *)
(* clear screen cursor to pos text *)
let line = "\027[2J" ^ cursor ^ "Test 123\n" in
let screen = Column(
default_column_opts,
[
Text "Testing 123";
Row(
default_row_opts,
[
Padding(
default_padding_opts,
Text "Padded child"
)
]
)
])
|> string_of_widget in
write_out line;
(* flush out_channel; *)
sleep 1;
write_out screen;
sleep 1;
write_out "test this one\n";
sleep 1;
write_out (pixel_ansi off color);
write_out "and another";
sleep 1;
restore_terminal fd original_attrs