Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calvinmclean/survey
A Gleam library to easily create rich and interactive prompts in the terminal for user input
https://github.com/calvinmclean/survey
cli gleam gleam-lang prompt terminal user-input
Last synced: about 1 month ago
JSON representation
A Gleam library to easily create rich and interactive prompts in the terminal for user input
- Host: GitHub
- URL: https://github.com/calvinmclean/survey
- Owner: calvinmclean
- License: apache-2.0
- Created: 2024-03-23T06:47:39.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-03-24T00:21:17.000Z (8 months ago)
- Last Synced: 2024-10-14T12:48:36.930Z (about 1 month ago)
- Topics: cli, gleam, gleam-lang, prompt, terminal, user-input
- Language: Gleam
- Homepage:
- Size: 16.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# survey
[![Package Version](https://img.shields.io/hexpm/v/survey)](https://hex.pm/packages/survey)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/survey/)A library to easily create rich and interactive prompts in the terminal.
Inpired by [`AlecAivazis/survey`](https://github.com/AlecAivazis/survey)
Use `survey.Question` for `String` input and `survey.Confirmation` for `Bool` input.
```sh
gleam add survey
```
```gleam
import survey
import gleam/option.{type Option, None, Some}pub fn main() {
let assert [
#("first_name", survey.StringAnswer(first_name)),
#("last_name", survey.StringAnswer(last_name)),
#("survey_fan", survey.BoolAnswer(survey_fan)),
] =
[
#(
"first_name",
survey.new_question(
prompt: "First Name:",
help: Some("Please enter your first name"),
default: None,
validate: None,
transform: None,
),
),
#(
"last_name",
survey.new_question(
prompt: "Last Name:",
help: Some("Please enter your last name"),
default: None,
validate: None,
transform: None,
),
),
#(
"survey_fan",
survey.new_confirmation(
prompt: "Are you a survey fan?:",
help: Some("It's a great library"),
default: Some(True),
transform: Some(fn(_: Bool) -> Bool { True }),
),
),
]
|> survey.ask_many(help: False)case survey_fan {
True -> io.println("Hello, " <> first_name <> " " <> last_name <> "!")
False -> io.println("I don't believe you")
}
}
``````sh
⟩ gleam run
Compiled in 0.02s
Running survey.main
First Name: Survey
Last Name: User
Are you a survey fan?: [Y/n]
Hello, Survey User!
```Further documentation can be found at .
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell
```