An open API service indexing awesome lists of open source software.

https://github.com/tony-go/qupp

A library for creating interactive command-line prompts in C++.
https://github.com/tony-go/qupp

Last synced: 3 months ago
JSON representation

A library for creating interactive command-line prompts in C++.

Awesome Lists containing this project

README

        

๐Ÿšง **Disclaimer:** This project is currently under development and might not be production-ready.

# qupp

**qupp** is a lightweight library designed to simplify the user input prompt process in C++ applications.

## ๐ŸŒŸ Features

- ๐ŸŽ‰ Simplified user input prompts.
- ๐ŸŒ Cross-platform (work in progress).
- ๐Ÿ› ๏ธ CMake-friendly integration (work in progress)

## ๐Ÿ“– Usage (API)

### Prompt::ask_for_input

Prompts the user for input with the provided question.

| Parameter | Type | Description |
|------------|----------------|-------------------------------|
| `question` | `std::string` | The question to present to the user. |

**Returns**: `std::optional` containing the user's input if provided, or an empty optional if the user provides no input.

```cpp
#include

int main() {
qupp::prompt::Prompt prompt;

auto result = prompt.ask_for_input("What's your name? ");
std::cout << "Hello, " << result.value() << "!" << std::endl;

return 0;
}
```

### Prompt::select

Presents a list of options to the user and allows them to select one.

| Parameter | Type | Description |
|------------|-----------------------------|------------------------------------|
| `question` | `std::string` | The question to present to the user. |
| `options` | `std::vector` | A list of options for the user to select from. |

**Returns:** `std::optional` containing the selected option or empty if no selection was made.

```cpp
#include

int main() {
qupp::prompt::Prompt prompt;

auto selected = prompt.select(
"Select an option:", {"Option 1", "Option 2", "Option 3 "});
if (selected.has_value()) {
std::cout << "You selected: " << selected.value() << "\n";
} else {
std::cout << "You did not select anything."
<< "\n";
}

return 0;
}
```

### Prompt::select_multiple

Presents a list of options to the user and allows them to select multiple.

| Parameter | Type | Description |
|------------|-----------------------------|------------------------------------|
| `question` | `std::string` | The question to present to the user. |
| `options` | `std::vector` | A list of options for the user to select from. |

**Returns:** `std::optional>` containing the selected options or empty if no selections were made.

```cpp
#include

int main() {
auto choices = prompt.select_multiple("Select multiple options:",
{"Option 1", "Option 2", "Option 3 "});
if (choices.has_value()) {
std::cout << "You selected: ";
for (const auto &choice : choices.value()) {
std::cout << choice << " ";
}
std::cout << "\n";
} else {
std::cout << "You did not select anything."
<< "\n";
}
}
```

## ๐Ÿค Contributing

### Building

1. Clone the repository:
```bash
git clone https://github.com/tony-go/qupp.git
```
2. Build
```bash
make
```

### ๐Ÿงช Testing

Tests are implemented using Google Test.

After building, run:
```bash
make test
```

## ๐Ÿ“œ License

MIT License. See `LICENSE` for more information.