blob: 973d470d091eaf6e669874dd0d64966b81d8e3bb [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstrad59c3892019-11-28 20:53:39 +01002 #include <input_to.h>
MG Mud User88f12472016-06-24 23:31:02 +02003
Zesstrad59c3892019-11-28 20:53:39 +01004 void input_to(string|closure fun)
5 void input_to(string|closure fun, int flag, ...)
6 void input_to(string|closure fun, int flag, string|closure prompt, ...)
MG Mud User88f12472016-06-24 23:31:02 +02007
Zesstra715ec202025-07-09 22:18:31 +02008DESCRIPTION
9 Enable next line of user input to be sent to the function <fun>
10 as an argument. Exception: if the next input
11 line starts with a "!", it will be parsed as a command resp.
12 passed to the most recent input_to() given with the
13 INPUT_IGNORE_BANG flag.
14 The function <fun> may be static, but must not be private (or
15 it won't be found).
MG Mud User88f12472016-06-24 23:31:02 +020016
Zesstra715ec202025-07-09 22:18:31 +020017 Note that fun is not called immediately but after pressing the
18 RETURN key.
MG Mud User88f12472016-06-24 23:31:02 +020019
Zesstra715ec202025-07-09 22:18:31 +020020 Usually, if input_to() is called more than once in the same execution,
21 only the first call has any effect. This behaviour can be
22 modified by specifying the INPUT_APPEND flag which will append
23 the given input_to to the already existing input_tos (see
24 EXAMPLES).
MG Mud User88f12472016-06-24 23:31:02 +020025
Zesstra715ec202025-07-09 22:18:31 +020026 Also, if a command given during an input_to() (using the "!"
27 escape) issues its own input_to(), the previous input_to() is
28 suspended until the new input_to() has been handled, then the
29 previous one becomes active again.
MG Mud User88f12472016-06-24 23:31:02 +020030
Zesstra715ec202025-07-09 22:18:31 +020031 The optional argument <flag> may be a binary-OR ('|') of the
32 following option values:
MG Mud User88f12472016-06-24 23:31:02 +020033
Zesstra715ec202025-07-09 22:18:31 +020034 INPUT_NOECHO (1):
35 The line given by the player will not be echoed, and is
36 not seen if snooped.
MG Mud User88f12472016-06-24 23:31:02 +020037
Zesstra715ec202025-07-09 22:18:31 +020038 A change of this mode not possible with telnet disabled.
MG Mud User88f12472016-06-24 23:31:02 +020039
Zesstra715ec202025-07-09 22:18:31 +020040 INPUT_CHARMODE (2):
41 The connection is switched from line- into charmode to
42 retrieve a single character(!) from the player.
MG Mud User88f12472016-06-24 23:31:02 +020043
Zesstra715ec202025-07-09 22:18:31 +020044 Is telnet disabled, then only the handling of the
45 incoming data by the driver is changed - the client
46 program of the player will remain in its current mode.
MG Mud User88f12472016-06-24 23:31:02 +020047
Zesstra715ec202025-07-09 22:18:31 +020048 After execution of <fun>, the connection is switched
49 back into linemode unless a subsequent input_to( , 2)
50 has been issued.
MG Mud User88f12472016-06-24 23:31:02 +020051
Zesstra715ec202025-07-09 22:18:31 +020052 Lineends are received exactly as the client sent them:
53 "\n", "\r" followed by "\n", or just "\r".
MG Mud User88f12472016-06-24 23:31:02 +020054
Zesstra715ec202025-07-09 22:18:31 +020055 Note that the players frontend is free to stay in
56 linemode all the time: even if you request a single
57 character, the player might be forced to type (and send)
58 that character plus the return key. Usually your function
59 will then receive the complete input line (including the
60 newline character sequence!) in one call.
MG Mud User88f12472016-06-24 23:31:02 +020061
Zesstra715ec202025-07-09 22:18:31 +020062 If you plan to stay in charmode a longer time , you can
63 reduce the call overhead by using set_combine_charset()
64 to retrieve sequences of certain characters as one string
65 instead of one-by-one. In a screen-oriented editor for
66 example this would be most of the printable characters.
MG Mud User88f12472016-06-24 23:31:02 +020067
Zesstra715ec202025-07-09 22:18:31 +020068 INPUT_PROMPT (4):
69 The argument following the <flag> argument is used as
70 prompt for the input. If this flag is not given, and thus
71 no prompt specified, nothing will be printed.
MG Mud User88f12472016-06-24 23:31:02 +020072
Zesstra715ec202025-07-09 22:18:31 +020073 INPUT_NO_TELNET (8):
74 Modifies the INPUT_CHARMODE flag: the driver will switch
75 it's internal handling of incoming data, but not send out
76 any telnet commands to switch the client's behaviour.
MG Mud User88f12472016-06-24 23:31:02 +020077
Zesstra715ec202025-07-09 22:18:31 +020078 INPUT_APPEND (16):
79 Append the input_to to the list of currently pending input_tos
80 (if any).
MG Mud User88f12472016-06-24 23:31:02 +020081
Zesstra715ec202025-07-09 22:18:31 +020082 INPUT_IGNORE_BANG (128):
83 Input lines starting with '!' (or whatever the input
84 escape character was configured to be) will _not_ be parsed as
85 commands, but are given to the function as well. Usage
86 of this option is privileged.
MG Mud User88f12472016-06-24 23:31:02 +020087
Zesstra715ec202025-07-09 22:18:31 +020088 The optional trailing args will be passed as second and
89 subsequent args to the function fun.
MG Mud User88f12472016-06-24 23:31:02 +020090
Zesstra715ec202025-07-09 22:18:31 +020091EXAMPLES
Zesstrad59c3892019-11-28 20:53:39 +010092 void func() {
Zesstra715ec202025-07-09 22:18:31 +020093 ...
94 input_to("enter_name", INPUT_PROMPT, "Please enter your name:");
95 /* The traditional way of doing this was:
96 * write("Please enter your name:");
97 * input_to("enter_name");
98 */
99 ...
100 }
101 enter_name(string str) {
102 write("Is '"+str+"' really your name?? *giggle*\n");
103 ...
MG Mud User88f12472016-06-24 23:31:02 +0200104 }
105
Zesstra715ec202025-07-09 22:18:31 +0200106 When reaching the input_to() statement the driver
107 continues the function func() but also asks the user for
108 input. If you entered whatever is asked and press RETURN the
109 driver will invoke the enter_name() function with the
110 string you entered as argument to it.
MG Mud User88f12472016-06-24 23:31:02 +0200111
112
113 void func() {
114 ..
115 input_to("enter_firstname");
116 input_to("enter_lastname, INPUT_APPEND);
117 ...
118 }
119
Zesstra715ec202025-07-09 22:18:31 +0200120 This sequence will queue two input_tos: the input first goes
121 to enter_firstname(); and when this function is done
122 (including any non-INPUT_APPEND input_to()s on its own), the next
123 input will go to enter_lastname().
MG Mud User88f12472016-06-24 23:31:02 +0200124
MG Mud User88f12472016-06-24 23:31:02 +0200125
Zesstra715ec202025-07-09 22:18:31 +0200126 Note that the list of input_to-s is treated as a flat list:
MG Mud User88f12472016-06-24 23:31:02 +0200127
Zesstra715ec202025-07-09 22:18:31 +0200128 void func() {
129 ..
130 input_to("func1");
131 input_to("func2", INPUT_APPEND);
132 }
133
134 void func1() {
135 ..
136 input_to("func3", INPUT_APPEND);
137 }
138
139 void func2() { ... }
140 void func3() { ... }
141
142 This code will result in the functions being called in the order
143 func(), func1(), func2(), func3(); and not func(), func1(), func3(),
144 func2().
145
146
147BUGS
148 In charmode, it is not possible to receive the NUL character
149 and pass it to the mudlib: internally the NUL character has
150 magical properties.
151
152HISTORY
153 The meaning of the flag parameter was extended in 3.2.1@93.
154 The limited "stacking" of input_to()s issued from !-commands
155 was implemented in LDMud 3.2.8.
156 Since LDMud 3.2.8 the function can be given as a closure.
157 LDMud 3.2.9/3.3.125 introduced the INPUT_PROMPT flag and argument.
158 LDMud 3.2.11/3.3.593 added the INPUT_NO_TELNET flag.
159 LDMud 3.2.11/3.3.637 added the INPUT_APPEND flag.
160 LDMud 3.3 changed the handling of newline sequences in charmode
161 to verbatim passing. Earlier drivers passed an empty string
162 instead.
163 LDMud 3.3 allowed the driver to be configured to use a different
164 input escape character.
165
166SEE ALSO
167 privilege_violation(M), set_combine_charset(E),
168 query_input_pending(E), find_input_to(E), input_to_info(E),
169 remove_input_to(E), enable_telnet(E)