-
Notifications
You must be signed in to change notification settings - Fork 13
Documentation
Andy Best edited this page Jun 20, 2017
·
1 revision
- init
- init(inputFile: Int32, outputFile: Int32)
- addHistory
- setCompletionCallback
- setHintsCallback
- loadHistory
- saveHistory
- setHistoryMaxLength
- clearScreen
- getLine
Default initializer, using STDIN for input and STDOUT for output
public init()
public init(inputFile: Int32, outputFile: Int32)
- Parameters:
- inputFile: a POSIX file handle for the input
- outputFile: a POSIX file handle for the output
Adds a string to the history buffer
public func addHistory(_ item: String)
- Parameters
- item: Item to add
Adds a callback for tab completion
public func setCompletionCallback(_ callback: @escaping (String) -> ([String]) )
- Parameters
- callback: A callback taking the current text and returning an array of Strings containing possible completions'
Adds a callback for hints as you type
public func setHintsCallback(_ callback: @escaping (String) -> (String?, (Int, Int, Int)?))
- Parameters
- callback: A callback taking the current text and optionally returning the hint and a tuple of RGB colours for the hint text
Loads history from a file and appends it to the current history buffer
public func loadHistory(fromFile path: String) throws
- Parameters
- path: The path of the history file
- Throws: Can throw an error if the file cannot be found or loaded
Saves history to a file
public func saveHistory(toFile path: String) throws
- Parameters
- path: The path of the history file to save
- Throws: Can throw an error if the file cannot be written to
Sets the maximum amount of items to keep in history. If this limit is reached, the oldest item is discarded when a new item is added.
public func setHistoryMaxLength(_ historyMaxLength: UInt)
- Parameters
- historyMaxLength: The maximum length of history. Setting this to 0 (the default) will keep 'unlimited' items in history
public func clearScreen() throws
Clears the screen.
- Throws: Can throw an error if the terminal cannot be written to.
The main function of Linenoise. Gets a line of input from the user.
public func getLine(prompt: String) throws -> String
- Parameters
- prompt: The prompt to be shown to the user at the beginning of the line.]
- Returns: The input from the user
- Throws: Can throw an error if the terminal cannot be written to.