Giter VIP home page Giter VIP logo

txtputizer's Introduction

TxtPutizer is a lightweight, interactive textual UI library. It provides various menu options for different types and representations of user interactions, allowing the selection of options and capturing user input in a straightforward and convenient manner.

Features

The menus are controlled via:

  • arrow keys - for navigation between presented options.
  • spacebar - for selecting the option pointed by the cursor.
  • enter - save current state and exit the menu.

Currently, TxtPutizer supports 3 types of menus:

  • checkbox menu - Allows the user to select any number of options from a vertical list.

Checkbox Menu Example

  • radio menu - Allows the user to choose one option from a vertical list of options. Selecting an option deselects any previously selected option.

Radio Menu Example

  • prompt menu - A single-line prompt for selecting one option from a horizontal list, ideal for short questions such as yes/no.

Prompt Menu Example

*Note: More menu variations may be added in the future.

Any further requests, ideas, and conributions are very welcome.

Integration

TxtPutizer is designed with as easiest integration into any project as possible in mind. The entire library is contained within a single header file: TxtPutizer.hpp, requiring no modifications to your project settings.

Basic usage guide

First and foremost, inlcude the header file by placing it in a known location. Example:

#include "single_include\TxtPutizer\TxtPutizer.hpp"

Then, to present a menu to a terminal window -

  1. Create a Menu object of the desired type, passing just a title for the menu.
CheckboxMenu cbm(L"CHECKBOX_MENU_TITLE");
  1. Add as meny options as you like. Optionally, add description to each option to be displayed below the menu, when the option is hovered.
cbm.addOption(L"option 1", L"Description for option 1");
cbm.addOption(L"option 2", L"Description for option 1");
cbm.addOption(L"option 3"); // description is not mandatory
  1. Execute the menu - running until 'Enter' key is pressed, which saves the current state.
cbm.execute();
  1. Acquire state of the menu upon exit. The returned value is a custom struct, describing the state upon exit.
MenuState mState = cbm.getState();
  1. Interpret and react to user's selections, represented as custom Option objects.
// VERY BASIC DECLARATION OF `OPTION`
class Option
{
public:
	BOOL IsSelected() const;

	// displayed in menu
	const std::wstring _displayName;
	const std::wstring _description;
private:	
	BOOL _selected;	
protected:
};

For interpreting menu state, 2 approaches can be applied -

/* 
APPROACH 1: 
acquire only the selected options
*/

//  EITHER -
Option sel = cbmState.getSelectedOptions()[0] // for singular option menus
//  OR -
std::vector<Option> sel = cbmState.getSelectedOptions() // for multiple option menus

// print display name of selected option
std::wcout << "\r\nSELECTED OPTION: " << sel._displayName << std::endl;
/*
APPROACH 2: 
iterate and check all options
*/

for (Option opt : cbmState.options) {

    // print all properties of each option
    std::wcout << opt._displayName << L"\t " 
    std::wcout << opt._description << L"\t " 
    std::wcout << opt.IsSelected() << std::endl;
}

** For more complete usage examples, refer to this file in this repository.


Feel free to reach out with any questions or suggestions!

txtputizer's People

Contributors

rubublik avatar

Stargazers

 avatar Max Zabuty avatar Barak Aharoni avatar  avatar Itay Migdal avatar

Watchers

 avatar

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.