Giter VIP home page Giter VIP logo

inquire's Introduction

Inquire

Actions Status

🎨 Create beautiful interactive command line interface in OCaml

Installation

Using Opam

opam install inquire

Using Esy

esy add @opam/inquire

Usage

Confirm

Prompt the user to answer the given message with "y" or "n".

Inquire.confirm "Are you sure?"

Raw List

Prompt the user to chose a value from the given options.

Inquire.raw_select "What's your favorite movie?" ~options:[ "Choice 1" ; "Choice 2" ]

Password

Prompt the user to enter a password that will be hidden with stars (*).

Inquire.password "Enter your password:"

Input

Prompt the user to input a string.

Inquire.input "Enter a value:"

Limitations

Inquire is dead simple. The prompt implementations are ~100 line of code each and manage the terminal control flow themselves. This simplicity comes at a price though:

  • No support for UTF8. This would in principle be relatively easy to implement with a buffer that accumulates the input bytes until it matches an UTF8 value, up to a certain number of bytes. A PR for this would be more than welcome.

Contributing

Take a look at our Contributing Guide.

inquire's People

Contributors

citizen428 avatar tmattio 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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

inquire's Issues

Fatal error with ocaml multicore

With the ocaml-variants.4.12.0+domains switch, I get the following error:

$ dune exec example/confirm.exe ? Are you sure? [y/n] Fatal error: exception Unix.Unix_error(Unix.EINVAL, "tcsetattr", "")

Rawlist.exe errors on option 4 and 5

Built and ran the example. Getting Fatal error: exception (Invalid_argument "List.nth_exn 5 called on list of length 5") when you pass options 4 and 5. FYI.

~/Downloads/inquire-example master
❯ dune exec ./raw_list.exe
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: 4
Fatal error: exception (Invalid_argument "List.nth_exn 5 called on list of length 5")
Raised at file "stdlib.ml", line 30, characters 20-45
Called from file "lib/prompts/raw_list.ml", line 50, characters 15-39
Called from file "src/core/lwt.ml", line 1867, characters 23-26
Re-raised at file "src/core/lwt.ml", line 3027, characters 20-29
Called from file "src/unix/lwt_main.ml", line 27, characters 10-20
Called from file "src/unix/lwt_main.ml", line 114, characters 8-13
Re-raised at file "src/unix/lwt_main.ml", line 120, characters 4-13
Called from file "raw_list.ml", line 16, characters 2-21

~/Downloads/inquire-example master
❯ dune exec ./raw_list.exe
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: e
>> Enter a number between 1 and 5
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: 3
Indeed, "Star Wars: The Force Awakens" is a great movie!

~/Downloads/inquire-example master 7s
❯ dune exec ./raw_list.exe
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: 4
Fatal error: exception (Invalid_argument "List.nth_exn 5 called on list of length 5")
Raised at file "stdlib.ml", line 30, characters 20-45
Called from file "lib/prompts/raw_list.ml", line 50, characters 15-39
Called from file "src/core/lwt.ml", line 1867, characters 23-26
Re-raised at file "src/core/lwt.ml", line 3027, characters 20-29
Called from file "src/unix/lwt_main.ml", line 27, characters 10-20
Called from file "src/unix/lwt_main.ml", line 114, characters 8-13
Re-raised at file "src/unix/lwt_main.ml", line 120, characters 4-13
Called from file "raw_list.ml", line 16, characters 2-21

~/Downloads/inquire-example master
❯ dune exec ./raw_list.exe
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: 5
Fatal error: exception (Invalid_argument "List.nth_exn 6 called on list of length 5")
Raised at file "stdlib.ml", line 30, characters 20-45
Called from file "lib/prompts/raw_list.ml", line 50, characters 15-39
Called from file "src/core/lwt.ml", line 1867, characters 23-26
Re-raised at file "src/core/lwt.ml", line 3027, characters 20-29
Called from file "src/unix/lwt_main.ml", line 27, characters 10-20
Called from file "src/unix/lwt_main.ml", line 114, characters 8-13
Re-raised at file "src/unix/lwt_main.ml", line 120, characters 4-13
Called from file "raw_list.ml", line 16, characters 2-21

~/Downloads/inquire-example master
❯ dune exec ./raw_list.exe
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: 3
Indeed, "Star Wars: The Force Awakens" is a great movie!

~/Downloads/inquire-example master
❯ dune exec ./raw_list.exe
? What's your favorite movie? 
  1) Star Wars: The Rise of Skywalker
  2) Solo: A Star Wars Story
  3) Star Wars: The Last Jedi
  4) Rogue One: A Star Wars Story
  5) Star Wars: The Force Awakens
  Answer: 2
Indeed, "Rogue One: A Star Wars Story" is a great movie!

~/Downloads/inquire-example master
❯ 

OpenBSD compat

Here's a report of me trying to get this working on OpenBSD. It mostly worked but I had to fill in some gaps :)

The README says I need make (which I assume is GNU make) and opam so

$ doas pkg_add gmake opam

But gmake fails trying to run dune. Okay, so

$ doas pkg_add dune

Now

$ gmake
dune build @install
File "lib/dune", line 5, characters 12-16:
5 |  (libraries base lwt lambda-term)
                ^^^^
Error: Library "base" not found.
Hint: try: dune external-lib-deps --missing @install
gmake: *** [Makefile:4: all] Error 1

Is dune supposed to come with opam? And is gmake supposed to auto-install the opam dependencies? They don't seem to, at least on OpenBSD.

And then I'm stumped because https://github.com/yoriyuki/Camomile/ isn't currently building on OpenBSD:

$ opam init
$ opam install base lwt lambda-term
[ mostly works ...until ]
#=== ERROR while compiling camomile.1.0.2 =====================================#
# context     2.0.5 | openbsd/x86_64 | ocaml-system.4.09.0 | https://opam.ocaml.org#0825e2d9
# path        ~/.opam/default/.opam-switch/build/camomile.1.0.2
# command     ~/.opam/default/bin/dune build -p camomile -j 1 @install
# exit-code   1
# env-file    ~/.opam/log/camomile-70159-335865.env
# output-file ~/.opam/log/camomile-70159-335865.out
### output ###
# [...]
# camomilelocaledef Camomile/locales/zh_MO.mar (exit 2)
# (cd _build/default/Camomile && tools/camomilelocaledef.exe --file locales/zh_MO.txt locales)
# Fatal error: exception Stack overflow
# camomilelocaledef Camomile/locales/zh_TW.mar (exit 2)
# (cd _build/default/Camomile && tools/camomilelocaledef.exe --file locales/zh_TW.txt locales)
# Fatal error: exception Stack overflow
# camomilelocaledef Camomile/locales/zh_TW_STROKE.mar (exit 2)
# (cd _build/default/Camomile && tools/camomilelocaledef.exe --file locales/zh_TW_STROKE.txt locales)
# Fatal error: exception Stack overflow
# camomilelocaledef Camomile/locales/zh__PINYIN.mar (exit 2)
# (cd _build/default/Camomile && tools/camomilelocaledef.exe --file locales/zh__PINYIN.txt locales)
# Fatal error: exception Stack overflow



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build camomile 1.0.2
+- 
- No changes have been performed

Nice work otherwise though. I want to give it a run-through.

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.