This chapter describes some functions which are useful if you want to interact with the user.
Integer get_response (String choices, String prompt)
This function will prompt the user for a single character using the prompt as specifed by the second parameter. The first parameter, choices, specified the characters that will be accepted. Any character in the prompt string that is preceeded by \001 will be given the `response_char' color.
The following:
rsp = get_response ("yYnN", "Are you hungry? \001Yes, \001No");
will return one of the four characters y
, Y
, n
,
or N
to the variable rsp
.
get_yes_no_cancel, set_color, get_select_box_response
Integer get_select_box_response (title, item_1, ..., n_items)
This function pops a selection box and queries the user for a response. An integer is returned which indicates the user's choice.
variable rsp = get_select_box_response (
"Pick a number:",
"one", "two", "three", "four",
4);
message (sprintf ("You chose %d", rsp));
read_mini, message, get_yes_no_cancel, get_response, select_list_box
Integer get_yes_no_cancel (str)
This function displays str
in the minibuffer after concatenating
"? [Y]-es, N-o, C-ancel"
to it. It then awaits user input and
returns:
1 if yes
0 if no
-1 if cancel
If a %
character is to appear, it must be doubled.
get_select_box_response, getkey, read_mini, select_list_box
Void message_now (String_Type s)
This function displays the string s
to the message area
immediately.
message, vmessage, error
Int popup_window (String title, String text)
This function creates a popup window which contains the given text
and uses title
as its title. It returns the key that was used to
exit the window.
Since slrn 0.9.7.4, this function expands TABs in the text
correctly. TABs in title
are not expanded and should be avoided.
select_list_box
String read_mini (String p, String dflt, String init)
This function will prompt the user for a string value using prompt
p
. The second parameter dfl
is used to specify the
default value. If the final parameter is not the empty string
(""
), it will be made available to the user for editing.
read_mini_filename, read_mini_no_echo, read_mini_integer, read_mini_variable, getkey, set_input_string, set_input_chars
String read_mini_filename (String p, String dflt, String init)
This function works like read_mini
, but allows the user to tab
complete filenames.
read_mini, read_mini_variable, getkey, set_input_string, set_input_chars
Integer read_mini_integer (String p, Integer dflt)
This function will prompt the user for an integer value using prompt
p
and taking dflt
as the default.
read_mini
String read_mini_no_echo (String p, String dflt, String init)
This function performs the same purpose as read_mini
except it
does not echo the entered text to the screen.
read_mini, getkey, set_input_string, set_input_chars
String read_mini_variable (String p, String dflt, String init)
This function works like read_mini
, but allows the user to tab
complete the names of slrn's configuration variables.
read_mini, read_mini_filename, getkey, set_input_string, set_input_chars
String_Type select_list_box (title, s_1, ... s_n, n, active_n)
String_Type title, s_1, ... s_n
Int_Type n, active_n
This purpose of this function is to present a list of n
strings,
specified by the s_1
, ... s_n
parameters to the user and have
the user select one. The user interface for this operation is that
of a box of strings. The title of the box is specified by the
title
parameter. The active_n
parameter specifies which string
is to be the default selection. It returns the string selected by
the user.
get_select_box_response, get_response
Void set_input_chars (String val)
This function may be used to set the character that will be returned
by the next prompt for single character input in the minibuffer.
This is the type of input that get_response
solicits.
set_input_chars ("y");
if ('y' == get_yes_no_cancel ("Really Quit"))
quit (0);
set_input_string, get_response, get_yes_no_cancel
Void set_input_string (String val)
This function may be used to set the string that will be returned by the next prompt for input in the minibuffer. One can set the value returned for the next n prompts by separating the values by \n characters.
The code
variable a, b;
set_input_string ("Apple\nOrange");
a = read_mini ("Enter Fruit", "", "");
b = read_mini ("Enter another Fruit", "", "");
will result in a
having the value Apple
and b
having the
value Orange
.
read_mini, set_input_chars