Skip to content

Documentation

Andy Best edited this page Jun 20, 2017 · 1 revision

Class: LineNoise

Contents

init

Default initializer, using STDIN for input and STDOUT for output

public init()

init(inputFile: Int32, outputFile: Int32)

public init(inputFile: Int32, outputFile: Int32)
  • Parameters:
    • inputFile: a POSIX file handle for the input
    • outputFile: a POSIX file handle for the output

addHistory

Adds a string to the history buffer

public func addHistory(_ item: String)
  • Parameters
    • item: Item to add

setCompletionCallback

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'

setHintsCallback

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

loadHistory

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

saveHistory

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

setHistoryMaxLength

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

clearScreen

public func clearScreen() throws

Clears the screen.

  • Throws: Can throw an error if the terminal cannot be written to.

getLine

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.