package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

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

doc/miaou-core.core/Miaou_core/Navigation/index.html

Module Miaou_core.NavigationSource

Page state wrapper with navigation support.

Instead of pages manually managing a next_page field, the framework wraps page state in 'a t and provides navigation helpers.

Usage in pages

  let handle_key ps key ~size =
    match key with
    | "Esc" -> Navigation.back ps
    | "q" -> Navigation.quit ps
    | "Enter" -> Navigation.goto "other_page" ps
    | "j" -> Navigation.update (fun s -> {s with cursor = s.cursor + 1}) ps
    | _ -> ps

Type-safe navigation

Navigation uses a variant type to prevent common mistakes:

  • Goto "page" pushes the current page onto the history stack and navigates to the named page.
  • Back pops the previous page from the history stack.
  • Quit exits the application.

Using a variant instead of magic strings makes it impossible to accidentally use goto "parent_page" when back is intended, which previously caused infinite navigation loops.

Sourcetype nav =
  1. | Goto of string
    (*

    Navigate to the named page (pushes current to stack)

    *)
  2. | Back
    (*

    Return to the previous page in the history stack

    *)
  3. | Quit
    (*

    Exit the application

    *)

Navigation target.

Sourcetype 'a t = {
  1. s : 'a;
    (*

    The page's own state

    *)
  2. nav : nav option;
    (*

    Pending navigation target, if any

    *)
}
Sourceval make : 'a -> 'a t

make s wraps a page state with no pending navigation.

Sourceval goto : string -> 'a t -> 'a t

goto page ps sets navigation to the named page.

Sourceval back : 'a t -> 'a t

back ps navigates to the previous page in the stack.

Sourceval quit : 'a t -> 'a t

quit ps exits the application.

Sourceval pending : 'a t -> nav option

pending ps returns the pending navigation target, if any. Used by the framework after handlers return.

Sourceval update : ('a -> 'a) -> 'a t -> 'a t

update f ps applies f to the inner state. Shorthand for {ps with s = f ps.s}.