Skip to content

Commit

Permalink
fix: show cursor on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
leostera committed Jan 11, 2024
1 parent 5d0f5c9 commit 3ebe778
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 11 deletions.
Binary file modified examples/altscreen-toggle/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/basic/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/counter/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/emoji/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/fps/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/fullscreen/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/progress/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions examples/progress/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 12,7 @@ type model = {
let initial_model =
let width = 50 in
{
gray_bar = Progress.make ~width ~color:(`Plain (Spices.color "#3f22a3")) ();
gray_bar = Progress.make ~width ~color:(`Plain (Spices.color "#3fa2a3")) ();
color_bar =
Progress.make ~width
~color:(`Gradient (Spices.color "#b14fff", Spices.color "#00ffa3"))
Expand All @@ -27,9 27,9 @@ let update event m =
match event with
| Event.KeyDown (Key "q" | Escape) -> (m, Command.Quit)
| Event.Frame _now ->
let gray_bar = Progress.increment m.gray_bar 0.01 in
let color_bar = Progress.increment m.color_bar (Random.float 0.01) in
let emoji_bar = Progress.increment m.emoji_bar 0.005 in
let gray_bar = Progress.increment m.gray_bar 0.001 in
let color_bar = Progress.increment m.color_bar (Random.float 0.0001) in
let emoji_bar = Progress.increment m.emoji_bar 0.00005 in
({ gray_bar; color_bar; emoji_bar }, Command.Noop)
| _ -> (m, Command.Noop)

Expand Down
Binary file modified examples/spinner/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/spinner/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,7 @@ let initial_model =
];
}

let init _ = Command.Noop
let init _ = Command.Hide_cursor

let update event model =
match event with
Expand Down
Binary file modified examples/stopwatch/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/text-input/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/views/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion minttea/program.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 22,7 @@ and handle_input renderer app model event =
match handle_cmd cmd renderer with
| exception Exit ->
Renderer.render renderer view;
Renderer.show_cursor renderer;
Renderer.exit_alt_screen renderer;
Renderer.shutdown renderer;
wait_pids [ renderer ]
Expand Down Expand Up @@ -57,7 58,8 @@ let run ({ fps; _ } as t) initial_model =
let renderer =
spawn (fun () ->
process_flag (Priority High);
Renderer.run ~fps)
let runner = Process.await_name "Minttea.runner" in
Renderer.run ~fps ~runner)
in
let runner =
spawn (fun () ->
Expand Down
9 changes: 5 additions & 4 deletions minttea/renderer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 10,7 @@ type Message.t =
| Set_cursor_visibility of [ `hidden | `visible ]

type t = {
runner : Pid.t;
ticker : Timer.timer;
width : int;
height : int;
Expand Down Expand Up @@ -53,7 54,7 @@ and restore t =
and tick t =
let now = Ptime_clock.now () in
if is_empty t || same_as_last_flush t then () else flush t;
send_by_name ~name:"Minttea.runner" (Io_loop.Input (Event.Frame now))
send t.runner (Io_loop.Input (Event.Frame now))

and flush t =
let new_lines = lines t in
Expand All @@ -77,7 78,7 @@ and flush t =
t.lines_rendered <- new_lines_this_flush;
t.buffer <- ""

and handle_render t output = t.buffer <- output
and handle_render t output = t.buffer <- output ^ "\n"

and handle_enter_alt_screen t =
if t.is_altscreen_active then ()
Expand Down Expand Up @@ -106,14 107,14 @@ let max_fps = 120
let cap fps = Int.max 1 (Int.min fps max_fps) |> Int.to_float
let fps_to_float fps = 1. /. cap fps *. 1_000. |> Int64.of_float

let run ~fps =
let _ = Process.await_name "Minttea.runner" in
let run ~fps ~runner =
let ticker =
Riot.Timer.send_interval ~every:(fps_to_float fps) (self ()) Tick
|> Result.get_ok
in
loop
{
runner;
ticker;
buffer = "";
width = 0;
Expand Down
2 changes: 1 addition & 1 deletion minttea/renderer.mli
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
open Riot

val run : fps:int -> unit
val run : fps:int -> runner:Pid.t -> unit
val render : Pid.t -> string -> unit
val enter_alt_screen : Pid.t -> unit
val exit_alt_screen : Pid.t -> unit
Expand Down

0 comments on commit 3ebe778

Please sign in to comment.