Custom build Input Loop for windows with better features
use nimble install http://github.com/JessaTehCrow/NimSuperInput
to install directly with nim.
- Per character input callback. Useful for custom syntax highlighting.
- Suggestions with tab-complete
- Hinting
- Special key handling (home & end, ctrl+[arrow / backspace], etc)
import NimSuperInput
var inp:Input = input("Input: ")
while inp.handleInput():
discard
echo inp.text
const suggestions = @["suggestion", "otherSuggestion"]
var inp:Input = input("Input: ")
inp.suggestions = suggestions
while inp.handleInput():
discard
echo inp
# Password example
while inp.handleInput():
inp.displayText = ""
inp.hint = " - Hint"
while inp.handleInput():
discard
Input* = object
suggestions*:seq[string]
suggestionIndex*:int
displayText*:string
hint*:string
text*:string
oldText*:string
lastKey*:int
position*:Position
prompt*:string
index*:int
returnKey:int
Input.suggestions
Sequence of strings of all possible suggestions. This is also what will be filled in as auto-complete
Suggestions are only for the last word (seperated by spaces)
Input.suggestionIndex
What index of the Input.suggestions
is currently being displayed
Input.displayText
What string is being displayed
Input.hint
What string is being displayed as a hint (does not work with auto complete)
Input.text
The current text being displayed
Input.oldText
The text before the latest character was pressed
Input.lastKey
Last key pressed
Input.position
The Input
's position within the terminal window
Input.prompt
The prompt being displayed
Input.index
Cursor index related to Input.text
Input.returnKey
What key will be used to return the input text
Default: keys.Enter
Input.handleInput ( display : bool ) : bool
Returns boolean
Returns true if the return key has not been pressed. Returns false if return key has been presesd.
Intended use case:
import NimSuperInput
var inp:Input = input()
while inp.handleInput():
discard
echo inp.text
The display
argument makes it so it automatically displays, corrects and does everything for you.
Can be disabled for a custom interface but is not recommended for non-advanced users.