Make interactive text-based user-interfaces in OCaml
Module Inuit_cursor
type 'flags cursor

A cursor is very like an Inuit_region.t with a default set of flags. This is a convenient type to expose to higher-level code.

Since it is just a wrapper, you can refer to Inuit_region.t for the documentation of most functions.

type 'flags clickable = [> `Clickable | `Clicked ] as 'flags

The set of flags for buffers with the capability to mark areas as clickable and to receive clicks.

val null : _ cursor

A dummy cursor that is always closed. Useful as a placeholder.

val text : 'flags cursor -> ?flags:'flags list -> string -> unit

text cursor ?flags str append the text str at the right of cursor while moving it to right. If flags is not provided, default set of flags is applied.

val clear : 'flags cursor -> unit

clear cursor erase the content of the region containing the cursor. New content can still be added, using text for instance.

val kill : 'flags cursor -> unit

Erase the content and close the cursor. No content can be added anymore.

val sub : 'flags cursor -> 'flags cursor

sub cursor creates an empty sub-cursor at the right end of cursor. Clearing the sub-cursor will not affect other content, but clearing cursor will kill the sub-cursor.

val observe : 'flags cursor -> ( 'flags cursor -> [ `Local | `Remote ] -> 'flags Inuit_base.patch -> 'flags list * ( unit -> unit ) option ) -> 'flags cursor

Create a sub-cursor and associate an observer call-back. See and Inuit_region.observe for more information.

val is_closed : 'flags cursor -> bool

A cursor is closed if it has no observers, all changes will be ignored. This can happen when using kill, or clear on a parent cursor, and when the root socket is closed.

val region : 'flags cursor -> 'flags Inuit_region.t

The region affected by this cursor

Manipulating flags

A cursor is nothing but a region with a default set of flags. The following functions allow to manipulate this set.

val add_flag : 'flags -> 'flags cursor -> 'flags cursor

Add a flag, mem_flag flag (add_flag flag c) = true.

val rem_flag : 'flags -> 'flags cursor -> 'flags cursor

Remove a flag, mem_flag flag (rem_flag flag c) = false.

val mem_flag : 'flags -> 'flags cursor -> bool

Check if a flag is in the set of flags of the cursor.

val get_flags : 'flags cursor -> 'flags list

Direct access to the list of flags.

val with_flags : 'flags list -> 'flags cursor -> 'flags cursor

Replace the set of flags with a new one.

Manipulating indentation

val get_indent : 'flags cursor -> int

Get indentation level of cursor

val with_indent : 'flags cursor -> int -> 'flags cursor

Set indentation level of cursor

val shift_indent : 'flags cursor -> int -> 'flags cursor

Add the argument to indentation level, clamp negative values to 0. shift_ident t n = with_indent t (max 0 (get_indent t + n))

Creating content (convenience functions)

val clickable : 'flags clickable cursor -> ( 'flags cursor -> unit ) -> 'flags cursor

Create a sub-cursor that can be clicked. The call-back provided as argument is invoked during a click.

val printf : 'flags cursor -> ?flags:'flags list -> ( 'a, unit, string, unit ) format4 -> 'a

Append formatted text to the cursor

A mix of printf and clickable: append formatted text that can be clicked. The callback is provided last, for instance: link cursor "Click to visit %s" "" (fun _ -> ...)

val cursor_of_region : ?flags:'flags list -> ?indent:int -> 'flags Inuit_region.t -> 'flags cursor

Make a cursor from a region.

val make : unit -> 'flags cursor * 'flags Inuit_base.patch Inuit_base.socket

Inuit_region.make wrapper: return a root cursor and a pending socket. Socket must be connected prior to changing the cursor.