
Here's the fun part: Input supports a lot more than stock read() does. That includes everything read() can do, in addition to:
- Max length (it goes to the right edge by default, just like regular read(), but you can finally change it!)
- Option to disable print() (useful for reading at the bottom of the screen, where stock read()'s forced print() moves the entire screen down!)
- Define where the cursor starts at as well as the default text
- Colors! Input can do syntax highlighting (self promo, and example program here), or whatever colored text you like. There's an example program here that highlights pairs of parenthesis (or square brackets, or curly brackets)
- Mouse support
- Selections! Click and drag, or hold shift and move the cursor
- Censor: a one-character long string specifying which character each character of the entered text will be replaced with. Default: nil
- History: a numerically indexed table specifying the past inputs, the last index being the most recent. Default: empty table
- Autocomplete: a function taking a single argument, the current line, that returns a numerically indexed table of all possible strings that could be used to complete the text, assuming the cursor is always at the end of the line. Default: empty function
- Default: text that will appear as if the user typed it. Default: empty string
- Max length: a number that specifies the number of characters horizontally the input can take up. Default: distance from the current cursor position to the right edge of the screen.
- Print after: a boolean that specifies whether or not the input() function will print a newline after enter is pressed. Default: true
- Start position: a number that specifies where in the default text the cursor will be placed. NOTE: This is ZERO-indexed, not ONE-indexed like most of Lua! Default: the length of the current line (0 if default is not specified)
- Colorizer: a function that should return two strings to be used with term.blit, in order of foreground and then background. Default: just returns white on black, with the completion being black on (not light) gray.
- The current line: string.
- The cursor position: number.
- The current scroll position (number of characters starting from the left that are not shown): number.
- Whether this is the last draw (when Enter is pressed, the function is immediately called one last time): boolean.
- The current completion: string. This will be in the blit, so you are expected to provide (concatenate at the end) foreground/background information for it as well.
Any suggestions to improve this post are appreciated.
Edited by LoganDark2, 19 February 2018 - 11:13 PM.












