Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/giann/sirocco
š¦ A collection of interactive command line prompts for Lua
https://github.com/giann/sirocco
cli command-line lua prompt terminal
Last synced: 3 months ago
JSON representation
š¦ A collection of interactive command line prompts for Lua
- Host: GitHub
- URL: https://github.com/giann/sirocco
- Owner: giann
- License: mit
- Created: 2019-02-13T03:56:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-31T12:58:04.000Z (almost 5 years ago)
- Last Synced: 2024-08-07T18:39:28.795Z (6 months ago)
- Topics: cli, command-line, lua, prompt, terminal
- Language: Lua
- Homepage:
- Size: 609 KB
- Stars: 105
- Watchers: 8
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sirocco
A collection of interactive command line prompts for Lua
**Note:** Sirocco is in active development.
## Installing
Requirements:
- Lua 5.1/JIT/5.2/5.3
- luarocks >= 3.0 (_Note: `hererocks -rlatest` will install 2.4, you need to specify it with `-r3.0`_)```bash
luarocks install sirocco
```## Quickstart
See [`example.lua`](https://github.com/giann/sirocco/blob/master/example.lua) for an exhaustive snippet of all sirocco's features.
### Text prompt
Basic text prompt. Every prompt inherits from it so most of its options apply to them.
```lua
Prompt {
-- The prompt
prompt = "A simple question\nā± ",
-- A placeholder that will dissappear once the user types something
placeholder = "A simple answer",
-- Whether the answer is required or not
required = true,
-- The default answer
default = "A default answer",
-- When hitting `tab`, will try to autocomplete based on those values
possibleValues = {
"some",
"possible",
"values",
},
-- Must return whether the current text is valid + a message in case it's not
validator = function(text)
return text:match("[a-zA-Z]*"), "Message when not valid"
end,
-- If returns false, input will not appear at all
filter = function(input)
return input:match("[a-zA-Z]*")
end
}:ask() -- Returns the answer
```### Password
Obfuscates the input.
```lua
Password {
prompt = "Enter your secret (hidden answer)\nā± ",
-- When false *** are printed otherwise nothing
hidden = false
}:ask() -- Returns the actual answer
```### Confirm
A simple yes/no prompt.
```lua
Confirm {
prompt = "All finished?"
}:ask() -- Returns the answer
```### List
Will choose the appropriate list (check list or radio list).
```lua
List {
prompt = "Where are you from?",
-- If true can select multiple choices (check list) otherwise one (radio list)
multiple = false,
-- List of choices
items = {
{
-- The actual value returned if selected
value = "New York",
-- The value displayed to the user
label = "New York"
},
{
value = "Paris",
label = "Paris"
},
{
value = "Rome",
label = "Rome"
}
},
-- Indexes of already selected choices
default = { 2, 4 },
}:ask() -- Returns a table of the selected choices
```### Composite
Will jump from field to field when appropriate.
**TODO:** field's length should be optional
```lua
Composite {
prompt = "What's your birthday? ",
-- Separator between each fields
separator = " / ",
-- Fields definition
fields = {
{
placeholder = "YYYY",
filter = function(input)
return input:match("%d")
and input
or ""
end,
-- Required
length = 4,
},
{
placeholder = "mm",
filter = function(input)
return input:match("%d")
and input
or ""
end,
length = 2,
},
{
placeholder = "dd",
filter = function(input)
return input:match("%d")
and input
or ""
end,
length = 2,
},
}
}:ask() -- Returns a table of each field's answer
```