<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://wiki.lostsouls.org/w/skins/common/feed.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Man input core - Revision history</title>
		<link>http://wiki.lostsouls.org/w/index.php?title=Man_input_core&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.8.2</generator>
		<lastBuildDate>Sun, 03 May 2026 11:38:54 GMT</lastBuildDate>
		<item>
			<title>Laine at 22:10, 11 June 2007</title>
			<link>http://wiki.lostsouls.org/w/index.php?title=Man_input_core&amp;diff=3995&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Files==&lt;br /&gt;
&lt;br /&gt;
 /daemon/input.c&lt;br /&gt;
 /lib/input.h&lt;br /&gt;
 /std/def/input.c&lt;br /&gt;
 /def/input&lt;br /&gt;
&lt;br /&gt;
==Description==&lt;br /&gt;
&lt;br /&gt;
This document describes the internal workings of the input system for core&lt;br /&gt;
systems developers who need to maintain or create input types.  You will want&lt;br /&gt;
to be familiar with the user-level perspective on the input system as described&lt;br /&gt;
in 'man input' and 'man dialog'.&lt;br /&gt;
&lt;br /&gt;
As typical of definition-based mechanisms, the input system has a broker&lt;br /&gt;
daemon, /daemon/input.c, a header file, /lib/input.h, a definition base,&lt;br /&gt;
/std/def/input.c, and a definition directory, /def/input.  The input type&lt;br /&gt;
definitions are heavily relied upon to determine the behavior of the input&lt;br /&gt;
types.  An excellent way to learn about the system is to study the existing&lt;br /&gt;
input type definitions in /def/input.&lt;br /&gt;
&lt;br /&gt;
===Adding an Input Type===&lt;br /&gt;
&lt;br /&gt;
Input types each have a macro in input.h, so adding one requires creating&lt;br /&gt;
the appropriate macro.  Add the new macro to the list at the top of input.h&lt;br /&gt;
according to alphabetical order and either make its value equal to Inputs_Count&lt;br /&gt;
plus one (easy way) or renumber all the input types (hard way).  Then increment&lt;br /&gt;
Inputs_Count and Inputs_Array_Size by one.  Since input type codes are not&lt;br /&gt;
saved, you can renumber the input types if you wish, but the MUD does need to&lt;br /&gt;
be immediately shut down if you do this, or potentially very troublesome errors&lt;br /&gt;
will arise from older code with the previous values compiled in.&lt;br /&gt;
&lt;br /&gt;
Once your macro exists, create your input type definition in /def/input and&lt;br /&gt;
configure it appropriately.&lt;br /&gt;
&lt;br /&gt;
===Input Type Configuration===&lt;br /&gt;
&lt;br /&gt;
Input types define the following configuration functions:&lt;br /&gt;
&lt;br /&gt;
void set_input(int code)&lt;br /&gt;
&lt;br /&gt;
Sets the input type's macro code.&lt;br /&gt;
&lt;br /&gt;
void set_input_name(string name)&lt;br /&gt;
&lt;br /&gt;
Sets the input type's name.  The name should match the filename of the&lt;br /&gt;
input definition; if it doesn't, a warning will be issued.&lt;br /&gt;
&lt;br /&gt;
void set_input_inherent_flags(int flags)&lt;br /&gt;
&lt;br /&gt;
Specifies one or more dialog flags which are automatically applied to&lt;br /&gt;
dialogs of this input type.&lt;br /&gt;
&lt;br /&gt;
void set_input_unsupported_fields(int array fields)&lt;br /&gt;
&lt;br /&gt;
Sets an array of dialog fields which are not supported by dialogs of this&lt;br /&gt;
input type.&lt;br /&gt;
&lt;br /&gt;
void set_input_handler(closure proc)&lt;br /&gt;
&lt;br /&gt;
Sets, as a closure, the procedure the input type uses to process raw input&lt;br /&gt;
received from the user.  When input is received, this closure is called with&lt;br /&gt;
arguments of 1) the string input received 2) the dialog descriptor.  This&lt;br /&gt;
procedure is completely responsible for everything to be done with the input,&lt;br /&gt;
with the help of the support functions described below.  At the beginning of&lt;br /&gt;
the function, the input should be processed with check_newline() and&lt;br /&gt;
strip_newlines() if appropriate.  Any handling of defaults should be performed&lt;br /&gt;
using input_empty(), check_flag(), and input_default().  The function may&lt;br /&gt;
reprompt the user if appropriate for the input by giving feedback with&lt;br /&gt;
input_feedback() and then calling Dialog_Process(dialog, True).  Otherwise,&lt;br /&gt;
the function should set the dialog's Dialog_Input field as appropriate and then&lt;br /&gt;
process the dialog's action using perform_input_action().  The function's&lt;br /&gt;
return value is ignored.&lt;br /&gt;
&lt;br /&gt;
void set_input_prompt_add(closure proc)&lt;br /&gt;
&lt;br /&gt;
Sets a closure that provides additions to the prompts of dialogs using the&lt;br /&gt;
input type.  The closure receives the dialog descriptor as argument and is&lt;br /&gt;
expected to return zero, a string, or a dialog message array as described in&lt;br /&gt;
the Dialog Colorization section of 'man dialog'; dialog colorization will, of&lt;br /&gt;
course, be applied to the result.&lt;br /&gt;
&lt;br /&gt;
void set_input_desc_add(closure proc)&lt;br /&gt;
&lt;br /&gt;
Sets a closure that provides additions to the descriptive content of&lt;br /&gt;
dialogs using the input type.  The closure receives the dialog descriptor as&lt;br /&gt;
argument; its return value is handled in the same way as for prompt adds.&lt;br /&gt;
&lt;br /&gt;
void set_input_dialog_initialize(closure proc)&lt;br /&gt;
&lt;br /&gt;
Sets a closure that will be called when dialogs of this input type are&lt;br /&gt;
being set up.  The closure will be called with the dialog descriptor as&lt;br /&gt;
argument; its return value is ignored.&lt;br /&gt;
&lt;br /&gt;
===Support Functions===&lt;br /&gt;
&lt;br /&gt;
void check_newline(string line, descriptor dialog)&lt;br /&gt;
&lt;br /&gt;
Attempts to determine whether a newline should be displayed to the user,&lt;br /&gt;
and displays it if so.  The logic currently implemented for determining that a&lt;br /&gt;
newline should be displayed are: if the dialog is in single character mode and&lt;br /&gt;
the input line is less than 2 characters long, display newline; otherwise, if&lt;br /&gt;
the dialog is in hidden mode, display a newline.  The idea behind this is to&lt;br /&gt;
supply newlines when the user's local terminal is likely not to have, to&lt;br /&gt;
prevent subsequent output from appearing on the same line as a prompt and/or&lt;br /&gt;
response.&lt;br /&gt;
&lt;br /&gt;
string strip_newlines(string line, descriptor dialog)&lt;br /&gt;
&lt;br /&gt;
Strips any ++n and ++r characters off the end of the line and returns the&lt;br /&gt;
result.&lt;br /&gt;
&lt;br /&gt;
status input_empty(string line)&lt;br /&gt;
&lt;br /&gt;
Returns true if the input line passed as argument should be considered an&lt;br /&gt;
empty response, e.g. for purposes of invoking a default.&lt;br /&gt;
&lt;br /&gt;
status check_flag(descriptor dialog, int flag)&lt;br /&gt;
&lt;br /&gt;
Return true if the specified flag is set in the dialog passed.&lt;br /&gt;
&lt;br /&gt;
void input_feedback(mixed feedback, descriptor dialog)&lt;br /&gt;
&lt;br /&gt;
Displays the specified feedback, which can be any of the output forms&lt;br /&gt;
described in the Dialog Colorization section of 'man dialog', by setting&lt;br /&gt;
the dialog's Dialog_Feedback field to the value specified and immediately&lt;br /&gt;
displaying the feedback to the user.  If you are going to be calling&lt;br /&gt;
perform_input_action(), give feedback simply by setting the Dialog_Feedback&lt;br /&gt;
field; this function is intended for use when you will not be calling&lt;br /&gt;
perform_input_action().&lt;br /&gt;
&lt;br /&gt;
mixed input_default(descriptor dialog)&lt;br /&gt;
&lt;br /&gt;
Retrieves the default value from the specified dialog, evaluating closures&lt;br /&gt;
as necessary.&lt;br /&gt;
&lt;br /&gt;
varargs void perform_input_action(descriptor dialog, mixed action)&lt;br /&gt;
&lt;br /&gt;
Retrieves the specified dialog's input action, evaluates and performs&lt;br /&gt;
it as appropriate.  The descriptor's Dialog_Input field should be set as&lt;br /&gt;
appropriate before calling this function.  The second argument is optional&lt;br /&gt;
and, if specified, overrides the normal action setting for the dialog.&lt;br /&gt;
&lt;br /&gt;
int input_output_length(mixed output, descriptor dialog)&lt;br /&gt;
&lt;br /&gt;
Retrieves the effective display width, in characters, of the output&lt;br /&gt;
specified, which can be a string or a dialog message array.&lt;br /&gt;
&lt;br /&gt;
string input_colorize_output(mixed output, descriptor dialog)&lt;br /&gt;
&lt;br /&gt;
Takes any of the output forms described in the Dialog Colorization&lt;br /&gt;
section of 'man dialog' and returns the final output string, with the&lt;br /&gt;
specified dialog's color settings applied.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
[[man input|input(mechanisms)]], [[man dialog|dialog(descriptors)]], [[man input to|input_to(efun)]]&lt;/div&gt;</description>
			<pubDate>Mon, 11 Jun 2007 22:10:57 GMT</pubDate>			<dc:creator>Laine</dc:creator>			<comments>http://wiki.lostsouls.org/Talk:Man_input_core</comments>		</item>
	</channel>
</rss>