Chamo.Commands
Commands management
type command_desc = {
com_name : string;
com_args : string array;
com_more_args : string option;
com_f : command;
}
val register :
?table:(string, command_desc) Stdlib.Hashtbl.t ->
?replace:bool ->
command_desc ->
unit
register command
registers the given command. Optional arguments:
table
can be used to specify a different command table than the default one.replace
is false
by default and means that when registering a command, if a command with the same name is alerady register, a Failure
exception is raised. If set to true
, the given command replaces the previous one (if any).val register_before :
?table:(string, command_desc) Stdlib.Hashtbl.t ->
command_desc ->
unit
register_before command
replace the previous command with the same name (if any) by a function calling the given command (with the same name) then the function assciated to the previous command. The same arguments are passed to the two functions. If the first command fails, the second is not called. If there is no previous command registered with the same name, the function is similar to register
.
val register_after :
?table:(string, command_desc) Stdlib.Hashtbl.t ->
command_desc ->
unit
Same as register_before
but the function of the given command is called after the previous command registered with the same name (if any).
val get_com :
?table:(string, command_desc) Stdlib.Hashtbl.t ->
string ->
command_desc
Get the command with the given name.
val get_com_or_fail :
?table:(string, command_desc) Stdlib.Hashtbl.t ->
string ->
command_desc
Same as get_com
but raise a Failure exception with a comprehensive message when the command is not found.
val launch_command :
?history:bool ->
?table:(string, command_desc) Stdlib.Hashtbl.t ->
string ->
string array ->
unit Lwt.t
val async_launch_command :
?history:bool ->
?table:(string, command_desc) Stdlib.Hashtbl.t ->
string ->
string array ->
unit
Return true
if is currently executed command is the same as the previous command one. This can be used in commands to have a different behaviour when the same command is triggered mutliple time.
val ask_launch_command :
?history:bool ->
?table:(string, command_desc) Stdlib.Hashtbl.t ->
?width:int ->
string ->
string array ->
unit
val eval_command :
?history:bool ->
?table:(string, command_desc) Stdlib.Hashtbl.t ->
string ->
unit Lwt.t
val async_command :
?history:bool ->
?table:(string, command_desc) Stdlib.Hashtbl.t ->
string ->
unit
val available_command_names :
?table:(string, command_desc) Stdlib.Hashtbl.t ->
unit ->
string list
val unit_com : string -> (unit -> unit) -> command_desc
Create a simple command with a function taking no argument.
val unit_com_lwt : string -> (unit -> unit Lwt.t) -> command_desc
Create a simple lwtized command with a function taking no argument.
val create_com :
string ->
?more:string ->
string array ->
command ->
command_desc
Convenient function to create a command.
set_global name value
associates the given value
to the given name
.
safe_get_global name
works as get_global
but returns an empty string ""
if no value is associated to the given name
.
trees_for_window bindings
adds the given bindings
to the ones of the windows (that is window_key_bindings#get
) and return a handler tree to set has handler tree of a window. See the Stk
.Wkey library for details about using such trees.
val create_add_binding_commands :
(Stk.Key.keystate list * string) list Ocf.conf_option ->
string ->
(Stk.Key.keystate list -> string -> unit) * (string -> string -> unit)
create_add_bindings_commands option name
return two functions to add key bindings to the given option, given a key state as OCaml value of as a string. It also create and register a add_<name>_key_binding
command which can be used to add a key binding to the given option.
These two functions add a key binding to the window_key_bindings
option. The first takes a Stk
.Key.keystatelist and the command name, while the second one takes a string representing a Stk
.Key.keystatelist and a command name.