/CLI-Autocomplete

Cross-platform flexible autocomplete library for your CLI applications.

Primary LanguageC++MIT LicenseMIT

logo

version

About

Cross-platform flexible autocomplete library for your CLI applications

example gif

Features

  • Cross-platform: macOS, Linux, Windows
  • Write your own autocomplete rules
  • Setup your own highlight colors
  • Required C++17
  • single header version of the library
  • static and dynamic versions of the library

Config Example

  1. After git may follow: config, init, clone
  2. After config may follow: --global, user.name, user.email
  3. After --global may follow: user.name, user.email
  4. After user.name may follow optional value: "[name]"
  5. ...
git
    config
        --global
            user.name
                "[name]"
            user.email
                "[email]"
        user.name
            "[name]"
        user.email
            "[email]"
    init
        [repository name]
    clone
        [url]

Simple Example

More complex example with: color settings, handling optional values and line title configuration you will find here

#include <iostream>
#include <string>

#include "../include/autocomplete.h"

int main() {
    std::string config_file_path = "../config.txt";
  
    auto [dict, status, message] = parse_config_file(config_file_path);

    if (status) {
        while (true) {
            std::cerr << "Attention! Please run the executable file only" << std::endl
                      << "through the command line!\n\n";
            
            std::cerr << "- To switch the prompts press UP or DOWN arrow." << std::endl;
            std::cerr << "- To move cursor press LEFT or RIGHT arrow." << std::endl;
            std::cerr << "- To edit input press DELETE or BACKSPACE key." << std::endl;
            std::cerr << "- To apply current prompt press TAB key.\n\n";

            std::string command = input(dict);
            std::cout << std::endl << command << std::endl << std::endl;
        }
    }
    else {
        std::cerr << message << std::endl;
    }

    return 0;
}

How to start

git clone https://github.com/DieTime/CLI-AutoComplete.git
cd CLI-AutoComplete/

cmake -DCMAKE_BUILD_TYPE=Release -S . -B ./cmake-build 
cmake --build ./cmake-build --config Release

----------------------- RUN EXAMPLE ---------------------

cd example/Release/
./example            # Posix
example.exe          # Windows

---------------------- OR RUN TESTS ---------------------

cd tests/Release/
./tests              # Posix
tests.exe            # Windows

Linking a dynamic library [Releases]

Posix
g++ -std=c++17 -o <executable> <paths/of/source/files> -L<path/to/shared/lib/link(.a)/folder> -I<path/to/include/folder> -lcliac -Wl,-rpath,<path/to/shared/lib/folder>
Windows MSVC from VS Command Prompt
cl /EHsc /std:c++17 <paths/of/source/files> /Fe<executable>.exe /I <path/to/include> /link <path/to/shared/lib>
Windows MinGW
g++ -std=c++17 -o <executable>.exe <paths/of/source/files> -L<path/to/shared/lib/link(.a)> -I<path/to/include> -lcliac

Linking a static library [Releases]

Posix
g++ -std=c++17 -o <executable> <paths/of/source/files> -L<path/to/static/lib/folder> -I<path/to/include> -lcliac
Windows MSVC from VS Command Prompt
cl /EHsc /std:c++17 /DBUILD_STATIC <paths/of/source/files> /Fe<executable>.exe /I <path/to/include/folder> /link <path/to/static/lib/foleder>
Windows MinGW
g++ -std=c++17 -DBUILD_STATIC -o <executable>.exe <paths/of/source/files> -L<path/to/static/lib/folder> -I<path/to/include/folder> -lcliac

About changes

A detailed description of the changes can be found in CHANGELOG.md