MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 2 | #include <input_to.h> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 3 | |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 4 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 7 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 8 | DESCRIPTION |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 17 | Note that fun is not called immediately but after pressing the |
| 18 | RETURN key. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 19 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 20 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 25 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 26 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 30 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 31 | The optional argument <flag> may be a binary-OR ('|') of the |
| 32 | following option values: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 33 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 34 | INPUT_NOECHO (1): |
| 35 | The line given by the player will not be echoed, and is |
| 36 | not seen if snooped. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 37 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 38 | A change of this mode not possible with telnet disabled. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 39 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 40 | INPUT_CHARMODE (2): |
| 41 | The connection is switched from line- into charmode to |
| 42 | retrieve a single character(!) from the player. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 43 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 44 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 47 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 48 | After execution of <fun>, the connection is switched |
| 49 | back into linemode unless a subsequent input_to( , 2) |
| 50 | has been issued. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 51 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 52 | Lineends are received exactly as the client sent them: |
| 53 | "\n", "\r" followed by "\n", or just "\r". |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 54 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 55 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 61 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 62 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 67 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 68 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 72 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 73 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 77 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 78 | INPUT_APPEND (16): |
| 79 | Append the input_to to the list of currently pending input_tos |
| 80 | (if any). |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 81 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 82 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 87 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 88 | The optional trailing args will be passed as second and |
| 89 | subsequent args to the function fun. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 90 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 91 | EXAMPLES |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 92 | void func() { |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 93 | ... |
| 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 106 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 111 | |
| 112 | |
| 113 | void func() { |
| 114 | .. |
| 115 | input_to("enter_firstname"); |
| 116 | input_to("enter_lastname, INPUT_APPEND); |
| 117 | ... |
| 118 | } |
| 119 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 120 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 124 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 125 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 126 | Note that the list of input_to-s is treated as a flat list: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 127 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 128 | 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 | |
| 147 | BUGS |
| 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 | |
| 152 | HISTORY |
| 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 | |
| 166 | SEE 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) |