Crystal bindings for the lightweight Linenoise line editor library written in C. It is a minimal alternative to readline and libedit.
Linenoise is written in C code that supports most distributions of the Linux, macOS and BSD operating systems. We compile the library on install so linking should not be a problem and the library is lightwieght (less than 1500 lines of code) so the resulting binary should be small.
As of v0.4.0
, UTF-8 support has been added. This means that the cursor won't have problems when writing in languages with non-Latin alphabets or emoji.
Add the dependency to your shard.yml
:
dependencies:
linenoise:
github: apainintheneck/crystal-linenoise
Run shards install
require "linenoise"
COMPLETIONS = [
...
]
# Enable tab completions.
Linenoise::Completion.add(COMPLETIONS)
# Enable completion hints to the right of the cursor.
Linenoise::Completion.enable_hints!
HISTORY_FILE = "..."
Linenoise.load_history(HISTORY_FILE)
# A simple REPL.
loop do
line = Linenoise.prompt("> ")
break if line.nil?
# Process line here.
Linenoise.add_history(line)
Linenoise.save_history(HISTORY_FILE)
end
For more information look at the files in the example/
directory and the documentation website.
These projects use this library as a dependency and can be used as a guide when setting things up. Let me know if you'd like your project to be added to the list.
git
There is no high-level wrapper around the multiplexing API but the Crystal bindings have been added for it. See src/lib/lib_linenoise.cr
for more details.
There are a few other line editing libraries available for Crystal.
Development setup is mostly managed by the Makefile.
Other than that there is the Linenoise extension in ext/
that can be built with make extension
. Keep in mind that this also gets installed automatically in a postinstall step when this shard is included as a dependency and shard install
is run.
Interactive testing is available using the example/example.cr
program which allows you to check on different line editing features. It can be run with make example
. The make specs
command runs the Crystal specs. The make expect
command runs tests on this example program using an expect
script so expect
will need to be installed to run them.
The make lint
command checks for linting errors and the make fix
command fixes them automatically.
The crystal docs
command can be used to build the docs locally or you can visit the documentation website that gets generated automatically by the .github/workflows/docs.yml
workflow.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)I have pulled in a few PRs from upstream that haven't been merged into the main Linenoise project yet.
Check out the extension changes file for more information.
This library is released under the MIT license.
The Linenoise library is included in this shard and uses the BSD-2-Clause license which allows code to be used freely as long as the license is included in derivative works.