Skip to content

Nim Super input with tab complete, suggestions and hints

License

Notifications You must be signed in to change notification settings

JessaTehCrow/NimSuperInput

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NimSuperInput

Custom build Input Loop for windows with better features

use nimble install http://github.com/JessaTehCrow/NimSuperInput to install directly with nim.

Functionality

  • Per character input callback. Useful for custom syntax highlighting.
  • Suggestions with tab-complete
  • Hinting
  • Special key handling (home & end, ctrl+[arrow / backspace], etc)

Examples

Barebones

import NimSuperInput

var inp:Input = input("Input: ")

while inp.handleInput():
    discard

echo inp.text

Suggestions

const suggestions = @["suggestion", "otherSuggestion"]
var inp:Input = input("Input: ")
inp.suggestions = suggestions

while inp.handleInput():
    discard

echo inp

Custom displayed text

# Password example
while inp.handleInput():
    inp.displayText = ""

Hinting

inp.hint = " - Hint"
while inp.handleInput():
    discard

Input object Docs

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

Function docs

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.

About

Nim Super input with tab complete, suggestions and hints

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages