Giter Site home page Giter Site logo

chrisnevers / ocamline Goto Github PK

View Code? Open in Web Editor NEW
36.0 3.0 1.0 82 KB

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Command line interface for user input

Home Page: https://chrisnevers.github.io/ocamline/

License: BSD 3-Clause "New" or "Revised" License

OCaml 100.00%
ocaml ocaml-library cli read-line repl

ocamline's Introduction

ocamline

This library provides a simple interface for reading user input in OCaml programs. The goal of this project is to reduce the burden of reading user input for programming language REPLs.

The feature that makes this library particularly useful is its handling of brackets. Any brackets that are opened must be closed before input is accepted. This library uses ocaml-linenoise to provide rlwrap like functionality, including command history, arrow navigation, etc.

Example

Source Code:

read ~brackets:['(',')'] ~prompt:"lisp>" ()

Command Line:

lisp> (lambda
          (x)
          (+ x 1))
lisp>

API

val read :  ?trim_delim:bool ->
            ?brackets:(char * char) list ->
            ?prompt:string ->
            ?strings:char list ->
            ?history_loc:string ->
            ?hints_callback:(string -> (string * LNoise.hint_color * bool) option) ->
            ?completion_callback:(string -> LNoise.completions -> unit) ->
            ?delim:string ->
            unit ->
            string
Parameter Description Default Value
trim_delim Whether or not to remove the line delimiter from the return value. false
brackets Any characters that once opened must be closed before the line is accepted []
prompt Customizes the prompt displayed to the user. ">"
strings String delimiters. If brackets are in strings, they won't have to be closed. []
history_loc Where to store the history for the user commands ".ocamline_history.txt"
hints_callback Linenoise's hints callback. See here No op
completion_callback Linenoise's completion callback. See here No op
delim The string that, when found, halts scanning and returns the input. "" (* newlines *)

Contributions

Contributions to ocamline are greatly appreciated! โค๏ธ

Please try to keep its implementation unassuming and configurable. ๐Ÿ™‚

ocamline's People

Contributors

0x0f0f0f avatar chrisnevers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

0x0f0f0f

ocamline's Issues

Should a list of keywords be passed to ocamline such that they are hinted and completed if at the end of the line?

I'm implementing variable/module keyword hinting and completion in the gobba REPL.
A problem may emerge (as it just did) when completion keywords have sub-keywords that depend on data structures external to linenoise/ocamline and previous sections/words in the current line. Parsing and evaluating the whole line at every keystroke is not preferable.
See 0x0f0f0f/gobba#17. Adding a function similar to the gobba keyword lookup function (currently broken) to ocamline and generalizing it for lists of strings (and adding a recursion capable keyword-finding callback as an Ocamline.read argument) would be time saving for future projects using ocamline that may try to implement the same functionality.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.