module Newt:Interface to the newt text window system.sig
..end
There is not a large amount of documentation for newt. The best documentation is probably Eric Troan's newt tutorial.
OCaml functions are derived using a predictable naming scheme. So
for example the C function newtPopWindow
becomes
Newt.pop_window
.
There are plenty of OCaml examples in the examples/
subdirectory.
The OCaml bindings attempt to be as type and memory safe as possible. However newt itself makes this difficult. Newt code has many arbitrary limits, no checks on memory allocation, and inherent confusion about types.
Do not use functions from the unsafe Newt_int
(internal)
module unless you know what you're doing.
exception NewtFailure of string
typecolor_set =
Newt_int.newtColorSet
typecolors =
Newt_int.newtColors
typeflags_sense =
Newt_int.newtFlagsSense
type
flag =
| |
RETURNEXIT |
| |
HIDDEN |
| |
SCROLL |
| |
DISABLED |
| |
BORDER |
| |
WRAP |
| |
NOF12 |
| |
MULTIPLE |
| |
SELECTED |
| |
CHECKBOX |
| |
PASSWORD |
| |
SHOWCURSOR |
type
fd_flag =
| |
FD_READ |
| |
FD_WRITE |
| |
FD_EXCEPT |
val init : unit -> unit
val finished : unit -> unit
val init_and_finish : (unit -> 'a) -> 'a
init_and_finish f
calls Newt.init
, then runs the function f ()
,
then finishes (cleans up) the terminal.
It does the right thing even if f
throws an exception.
val cls : unit -> unit
val resize_screen : int -> unit
val wait_for_key : unit -> unit
val clear_key_buffer : unit -> unit
val delay : int -> unit
val open_window : int -> int -> int -> int -> string -> unit
val centered_window : int -> int -> string -> unit
val pop_window : unit -> unit
val pop_window_no_refresh : unit -> unit
val set_colors : Newt_int.newtColors -> unit
val set_color : Newt_int.newtColorSet -> string -> string -> unit
val refresh : unit -> unit
val suspend : unit -> unit
val resume : unit -> int
val push_help_line : string -> unit
val redraw_help_line : unit -> unit
val pop_help_line : unit -> unit
val draw_root_text : int -> int -> string -> unit
val bell : unit -> unit
val cursor_on : unit -> unit
val cursor_off : unit -> unit
val get_screen_size : unit -> int * int
We use phantom types here to add some type safety around
components. All components have a type of at least [>
`Component] component
. Specific types of components have an
extra variant indicating the type and limiting what functions you
can safely call. Thus for example buttons have type
[`Button|`Component] component
.
A component_ptr
is a special type of component that may
only be compared against other components, but not used in
any way. It is returned by certain functions that get the
"current" subcomponent from a form or component.
type'a
component =Newt._component
type
_component
type
component_ptr
val component_equals : component_ptr -> [> `Component ] component -> bool
val compact_button : int -> int -> string -> [ `Button | `Component ] component
val button : int -> int -> string -> [ `Button | `Component ] component
val checkbox : int ->
int ->
string -> char -> string option -> [ `Checkbox | `Component ] component
val checkbox_get_value : [> `Checkbox ] component -> char
val checkbox_set_value : [> `Checkbox ] component -> char -> unit
val checkbox_set_flags : [> `Checkbox ] component ->
flag list -> Newt_int.newtFlagsSense -> unit
val radio_button : int ->
int ->
string ->
bool ->
[> `Radio ] component option -> [ `Component | `Radio ] component
val radio_get_current : [> `Radio ] component -> component_ptr
val label : int -> int -> string -> [ `Component | `Label ] component
val label_set_text : [> `Label ] component -> string -> unit
val vertical_scrollbar : int ->
int ->
int ->
color_set ->
color_set -> [ `Component | `VerticalScrollbar ] component
val scrollbar_set : [> `VerticalScrollbar ] component -> int -> int -> unit
Newt lets you store arbitrary data for each row in a listbox. We can't let you do that, but instead we let you store values of a single type in the listbox (if you really want to store arbitrary values, use a variant).
The newt documentation confuses the terms 'key' and 'data'
as if they refer to something different. In fact they are
the same thing and we refer to it as 'data' everywhere.
type 'a
listbox
val listbox : int -> int -> int -> flag list -> 'a listbox
val listbox_get_current : 'a listbox -> 'a option
data
field from the current item, for listboxes
which only allow single selection.
If nothing is selected, None
is returned.
val listbox_set_current : 'a listbox -> int -> unit
val listbox_set_current_by_key : 'a listbox -> 'a -> unit
data
.Not_found
if data is not found.val listbox_set_entry : 'a listbox -> int -> string -> unit
val listbox_set_width : 'a listbox -> int -> unit
val listbox_set_data : 'a listbox -> int -> 'a -> unit
val listbox_append_entry : 'a listbox -> string -> 'a -> unit
listbox_append_entry lb text data
appends a new listbox
entry consisting of the text string text
and data data
to the end of the listbox.val listbox_insert_entry : 'a listbox -> string -> 'a -> 'a option -> unit
listbox_insert_entry lb text data after
inserts a new listbox
entry consisting of the text string text
and data data
after the current listbox entry with data field after
.
It returns the position of the new entry.Not_found
if after
is not found.val listbox_delete_entry : 'a listbox -> 'a -> unit
listbox_delete_entry lb data
deletes the listbox entry
which contains data
.Not_found
if data
is not found.val listbox_clear : 'a listbox -> unit
val listbox_get_entry : 'a listbox -> int -> string * 'a
val listbox_get_selection : 'a listbox -> 'a array
listbox_get_selection lb
return an array of
data
from the items selected.val listbox_clear_selection : 'a listbox -> unit
val listbox_select_item : 'a listbox -> 'a -> flags_sense -> unit
data
.Not_found
if data is not found.val listbox_item_count : 'a listbox -> int
val component_of_listbox : 'a listbox -> [ `Component | `Listbox ] component
val textbox_reflowed : int ->
int ->
string ->
int ->
int -> int -> flag list -> [ `Component | `Textbox ] component
val textbox : int ->
int ->
int -> int -> flag list -> [ `Component | `Textbox ] component
val textbox_set_text : [> `Textbox ] component -> string -> unit
val textbox_set_height : [> `Textbox ] component -> int -> unit
val textbox_get_num_lines : [> `Textbox ] component -> int
val reflow_text : string -> int -> int -> int -> string * int * int
val entry : int ->
int ->
string option ->
int -> flag list -> [ `Component | `Entry ] component
val entry_set : [> `Entry ] component -> string -> bool -> unit
val entry_get_value : [> `Entry ] component -> string
val entry_set_flags : [> `Entry ] component -> flag list -> flags_sense -> unit
val scale : int -> int -> int -> int64 -> [ `Component | `Scale ] component
val scale_set : [> `Scale ] component -> int64 -> unit
val form : [> `VerticalScrollbar ] component option ->
string option -> flag list -> [ `Component | `Form ] component
val form_set_timer : [> `Form ] component -> int -> unit
val form_watch_fd : [> `Form ] component -> Unix.file_descr -> fd_flag list -> unit
val form_set_size : [> `Form ] component -> unit
val form_get_current : [> `Form ] component -> component_ptr
val form_set_background : [> `Form ] component -> int -> unit
val form_set_current : [> `Form ] component -> [> `Component ] component -> unit
val form_add_component : [> `Form ] component -> [> `Component ] component -> unit
val form_add_components : [> `Form ] component -> [> `Component ] component list -> unit
val form_set_height : [> `Form ] component -> int -> unit
val form_set_width : [> `Form ] component -> int -> unit
val run_form : [> `Form ] component -> component_ptr option
val form_run : [> `Form ] component -> Newt_int.newtExitStruct
val form_add_hot_key : [> `Form ] component -> int -> unit
val component_takes_focus : [> `Component ] component -> bool -> unit
component_takes_focus co bool
enables or disables
a component.val component_add_callback : [> `Component ] component -> (unit -> unit) -> unit
component_add_callback co f
adds a general callback function f
to a component. This is only available for certain types
of component -- see the Newt documentation for more information.