linenoise

linenoise line editing library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_linenoise.cC FFI wrapper
c/kit_linenoise.hC header for FFI wrapper
c/linenoise.cC FFI wrapper
c/linenoise.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/linenoise.kitKit Linenoise - Line editing library bindings
tests/linenoise.test.kitTests for linenoise

Dependencies

No Kit package dependencies. No external libraries required — linenoise is bundled.

Installation

kit add gitlab.com/kit-lang/packages/kit-linenoise.git

System Requirements

No external dependencies — linenoise source is bundled in the package.

Usage

import Kit.Linenoise as Linenoise

main = fn =>
  println "Type 'quit' to exit\n"

  # Set history size
  Linenoise.history-set-max 100

  # Load previous history
  match Linenoise.history-load "/tmp/history.txt"
    | Ok _ -> println "(History loaded)"
    | Err _ -> println "(No previous history)"

  # Read a line with prompt
  repl = fn(running) =>
    if running then
      line = Linenoise.readline "kit> "
      if line == "quit" then
        println "Goodbye!"
        match Linenoise.history-save "/tmp/history.txt"
          | Ok _ -> println "(History saved)"
          | Err e -> println ("Save error: " ++ e)
      else if line == "clear" then
        Linenoise.clear-screen
        repl true
      else
        Linenoise.history-add line
        println ("You typed: " ++ line)
        repl true
    else
      no-op

  repl true

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/linenoise/, making it available for import as Kit.Linenoise in other projects.

License

This package is released under the MIT License - see LICENSE for details.

linenoise is released under the BSD 2-Clause License.

Exported Functions & Types

readline

Read a line of input with the given prompt.

Supports line editing (arrow keys, backspace, etc.) and history navigation (up/down arrows). Returns empty string on EOF (Ctrl-D).

Parameters:

Returns:

String -> String

readline-default

Read a line with the default prompt ("> ").

String

history-add

Add a line to the history.

Parameters:

    String -> Unit

history-set-max

Set the maximum number of history entries.

Parameters:

    Int -> Unit

history-save

Save history to a file.

Parameters:

Returns:

String -> Result Unit String

history-load

Load history from a file.

Parameters:

Returns:

String -> Result Unit String

set-multiline

Enable or disable multi-line editing mode.

When enabled, long lines wrap to the next line instead of scrolling.

Parameters:

    Bool -> Unit

set-mask-mode

Enable or disable password masking mode.

When enabled, typed characters are shown as asterisks.

Parameters:

    Bool -> Unit

clear-screen

Clear the terminal screen.

Unit