package miaou-driver-term

  1. Overview
  2. Docs
Miaou terminal driver

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6

doc/src/miaou-driver-term.driver/term_test_runner.ml.html

Source file term_test_runner.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(*****************************************************************************)
(*                                                                           *)
(* SPDX-License-Identifier: MIT                                              *)
(* Copyright (c) 2025 Nomadic Labs <contact@nomadic-labs.com>                *)
(*                                                                           *)
(*****************************************************************************)

open Miaou_core.Tui_page
module Modal_manager = Miaou_core.Modal_manager
module Navigation = Miaou_core.Navigation

type driver_key = Term_events.driver_key =
  | Quit
  | Refresh
  | Enter
  | NextPage
  | PrevPage
  | Up
  | Down
  | Left
  | Right
  | Other of string

let run_with_key_source ~read_key (module Page : PAGE_SIG) :
    [`Quit | `Back | `SwitchTo of string] =
  let default_size = {LTerm_geom.rows = 24; cols = 80} in
  (* Helper: apply any pending navigation from modal callbacks *)
  let apply_pending_modal_nav ps =
    match Modal_manager.take_pending_navigation () with
    | Some (Navigation.Goto page) -> Navigation.goto page ps
    | Some Navigation.Back -> Navigation.back ps
    | Some Navigation.Quit -> Navigation.quit ps
    | None -> ps
  in
  let check_nav ps =
    let ps = apply_pending_modal_nav ps in
    match Navigation.pending ps with
    | Some Navigation.Quit -> `Quit
    | Some Navigation.Back -> `Back
    | Some (Navigation.Goto p) -> `SwitchTo p
    | None -> `Continue ps
  in
  let rec loop ps =
    match (read_key () : driver_key) with
    | Quit -> `Quit
    | Refresh -> (
        let ps' = Page.service_cycle (Page.refresh ps) 0 in
        match check_nav ps' with
        | `Continue ps'' -> loop ps''
        | (`Quit | `Back | `SwitchTo _) as r -> r)
    | Enter -> (
        if Modal_manager.has_active () then (
          Modal_manager.handle_key "Enter" ;
          let ps' = Page.refresh ps in
          if Modal_manager.take_consume_next_key () then
            if not (Modal_manager.has_active ()) then
              let ps'' = Page.service_cycle ps' 0 in
              match check_nav ps'' with
              | `Continue ps''' -> loop ps'''
              | (`Quit | `Back | `SwitchTo _) as r -> r
            else loop ps'
          else if not (Modal_manager.has_active ()) then
            let ps'' = Page.service_cycle ps' 0 in
            match check_nav ps'' with
            | `Continue ps''' -> loop ps'''
            | (`Quit | `Back | `SwitchTo _) as r -> r
          else loop ps')
        else
          match check_nav ps with
          | `Continue _ -> (
              let ps' = Page.handle_key ps "Enter" ~size:default_size in
              match check_nav ps' with
              | `Continue ps'' -> loop ps''
              | (`Quit | `Back | `SwitchTo _) as r -> r)
          | (`Quit | `Back | `SwitchTo _) as r -> r)
    | Up | Down | Left | Right | NextPage | PrevPage -> loop ps
    | Other key -> (
        let ps' = Page.handle_key ps key ~size:default_size in
        match check_nav ps' with
        | `Continue ps'' -> loop ps''
        | (`Quit | `Back | `SwitchTo _) as r -> r)
  in
  Modal_manager.clear () ;
  let ps0 = Page.init () in
  match check_nav ps0 with
  | `Continue ps0' -> loop ps0'
  | (`Quit | `Back | `SwitchTo _) as r -> r