Detect when we’re running from within Xcode and mark terminal type as unsupported (#17)
- Detect when we’re running from within Xcode and mark terminal type as unsupported.
Fixes https://github.com/andybest/linenoise-swift/issues/16
- rewrite Xcode detection
Linenoise-Swift
A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement.
Supports
Pure Swift
Implemented in pure Swift, with a Swifty API, this library is easy to embed in projects using Swift Package Manager, and requires no additional dependencies.
Contents
API
Quick Start
Linenoise-Swift is easy to use, and can be used as a replacement for
Swift.readLine
. Here is a simple example:Basics
Simply creating a new
LineNoise
object is all that is necessary in most cases, with STDIN used for input and STDOUT used for output by default. However, it is possible to supply different files for input and output if you wish:History
Adding to History
Adding to the history is easy:
Limit the Number of Items in History
You can optionally set the maximum amount of items to keep in history. Setting this to
0
(the default) will keep an unlimited amount of items in history.Saving the History to a File
Loading History From a File
This will add all of the items from the file to the current history
History Editing Behavior
By default, any edits by the user to a line in the history will be discarded if the user moves forward or back in the history without pressing Enter. If you prefer to have all edits preserved, then use the following:
Completion
Linenoise supports completion with
tab
. You can provide a callback to return an array of possible completions:The completion callback gives you whatever has been typed before
tab
is pressed. Simply return an array of Strings for possible completions. These can be cycled through by pressingtab
multiple times.Hints
Linenoise supports providing hints as you type. These will appear to the right of the current input, and can be selected by pressing
Return
.The hints callback has the contents of the current line as input, and returns a tuple consisting of an optional hint string and an optional color for the hint text, e.g.:
Acknowledgements
Linenoise-Swift is heavily based on the original linenoise library by Salvatore Sanfilippo (antirez)