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 -> unitval finished : unit -> unitval init_and_finish : (unit -> 'a) -> 'ainit_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 -> unitval resize_screen : int -> unitval wait_for_key : unit -> unitval clear_key_buffer : unit -> unitval delay : int -> unitval open_window : int -> int -> int -> int -> string -> unitval centered_window : int -> int -> string -> unitval pop_window : unit -> unitval pop_window_no_refresh : unit -> unitval set_colors : Newt_int.newtColors -> unitval set_color : Newt_int.newtColorSet -> string -> string -> unitval refresh : unit -> unitval suspend : unit -> unitval resume : unit -> intval push_help_line : string -> unitval redraw_help_line : unit -> unitval pop_help_line : unit -> unitval draw_root_text : int -> int -> string -> unitval bell : unit -> unitval cursor_on : unit -> unitval cursor_off : unit -> unitval 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'acomponent =Newt._component
type _component
type component_ptr
val component_equals : component_ptr -> [> `Component ] component -> boolval compact_button : int -> int -> string -> [ `Button | `Component ] componentval button : int -> int -> string -> [ `Button | `Component ] componentval checkbox : int ->
int ->
string -> char -> string option -> [ `Checkbox | `Component ] componentval checkbox_get_value : [> `Checkbox ] component -> charval checkbox_set_value : [> `Checkbox ] component -> char -> unitval checkbox_set_flags : [> `Checkbox ] component ->
flag list -> Newt_int.newtFlagsSense -> unitval radio_button : int ->
int ->
string ->
bool ->
[> `Radio ] component option -> [ `Component | `Radio ] componentval radio_get_current : [> `Radio ] component -> component_ptrval label : int -> int -> string -> [ `Component | `Label ] componentval label_set_text : [> `Label ] component -> string -> unitval vertical_scrollbar : int ->
int ->
int ->
color_set ->
color_set -> [ `Component | `VerticalScrollbar ] componentval scrollbar_set : [> `VerticalScrollbar ] component -> int -> int -> unitNewt 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 listboxval listbox_get_current : 'a listbox -> 'a optiondata 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 -> unitval listbox_set_current_by_key : 'a listbox -> 'a -> unitdata.Not_found if data is not found.val listbox_set_entry : 'a listbox -> int -> string -> unitval listbox_set_width : 'a listbox -> int -> unitval listbox_set_data : 'a listbox -> int -> 'a -> unitval listbox_append_entry : 'a listbox -> string -> 'a -> unitlistbox_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 -> unitlistbox_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 -> unitlistbox_delete_entry lb data deletes the listbox entry
which contains data.Not_found if data is not found.val listbox_clear : 'a listbox -> unitval listbox_get_entry : 'a listbox -> int -> string * 'aval listbox_get_selection : 'a listbox -> 'a arraylistbox_get_selection lb return an array of
data from the items selected.val listbox_clear_selection : 'a listbox -> unitval listbox_select_item : 'a listbox -> 'a -> flags_sense -> unitdata.Not_found if data is not found.val listbox_item_count : 'a listbox -> intval component_of_listbox : 'a listbox -> [ `Component | `Listbox ] componentval textbox_reflowed : int ->
int ->
string ->
int ->
int -> int -> flag list -> [ `Component | `Textbox ] componentval textbox : int ->
int ->
int -> int -> flag list -> [ `Component | `Textbox ] componentval textbox_set_text : [> `Textbox ] component -> string -> unitval textbox_set_height : [> `Textbox ] component -> int -> unitval textbox_get_num_lines : [> `Textbox ] component -> intval reflow_text : string -> int -> int -> int -> string * int * intval entry : int ->
int ->
string option ->
int -> flag list -> [ `Component | `Entry ] componentval entry_set : [> `Entry ] component -> string -> bool -> unitval entry_get_value : [> `Entry ] component -> stringval entry_set_flags : [> `Entry ] component -> flag list -> flags_sense -> unitval scale : int -> int -> int -> int64 -> [ `Component | `Scale ] componentval scale_set : [> `Scale ] component -> int64 -> unitval form : [> `VerticalScrollbar ] component option ->
string option -> flag list -> [ `Component | `Form ] componentval form_set_timer : [> `Form ] component -> int -> unitval form_watch_fd : [> `Form ] component -> Unix.file_descr -> fd_flag list -> unitval form_set_size : [> `Form ] component -> unitval form_get_current : [> `Form ] component -> component_ptrval form_set_background : [> `Form ] component -> int -> unitval form_set_current : [> `Form ] component -> [> `Component ] component -> unitval form_add_component : [> `Form ] component -> [> `Component ] component -> unitval form_add_components : [> `Form ] component -> [> `Component ] component list -> unitval form_set_height : [> `Form ] component -> int -> unitval form_set_width : [> `Form ] component -> int -> unitval run_form : [> `Form ] component -> component_ptr optionval form_run : [> `Form ] component -> Newt_int.newtExitStructval form_add_hot_key : [> `Form ] component -> int -> unitval component_takes_focus : [> `Component ] component -> bool -> unitcomponent_takes_focus co bool enables or disables
a component.val component_add_callback : [> `Component ] component -> (unit -> unit) -> unitcomponent_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.