Coder Social home page Coder Social logo

tui-selector's Introduction

TUI selector

Copyright (c) 2020-2021 Antmicro

This is a simple TUI menu that lists and runs applications based on rules written in the JSON format.

Building the project

The project requires ncurses library and a C++ compiler with C++17 support. In order to build it, run:

mkdir build && cd build
cmake ..
make -j24

Usage

The tui-selector requires the path to the directory with JSON files that describe filters and run commands.

There can be multiple JSON files in the rules_directory directory.

The JSON files should have the following structure:

[
    {
        "searchdirectory" : "path/to/directory/with/files",
        "regex" : "<file-regex>",
        "command" : "<command-to-run>",
        "entryformat" : "<how-entry-should-be-displayed"
    },
    ...
]

The root of the JSON file is the list of rules. Each rule is a dictionary with four attributes where:

  • searchdirectory says where the files or executables to be used as the menu entries are located,
  • regex holds the regular expression by which the files in searchdirectory should be filtered,
  • command describes how the file or executable should be executed,
  • entryformat describes how the entry for a given file and rule should be displayed in the TUI menu.

Both command and entryformat are regex substitutions for the regex attribute. This means that regex groups formed in regex can be accessed in command and entryformat by $i, where i is the ID of the group.

For example, for regex "(^.*)\\/(.*)\\.pdf$" and string /directory/lab1-presentation.pdf the entryformat with value Open document $2 (okular) will create entry Open document lab1-presentation (okular) in the menu.

Examples of JSON rules

The examples of JSON files with rules are in the json-samples directory.

Let's assume there are some images, videos, .txt or .pdf files in the Desktop directory.

Create a rules/ directory and a rules/multimedia.json file with the following content (replace user with your user name):

[
    {
        "searchdirectory" : "/home/user/Desktop",
        "regex" : "(^.*)\\/(.*\\.(mp4|avi))$",
        "command" : "vlc $1/$2",
        "entryformat" : "Video $2"
    },
    {
        "searchdirectory" : "/home/user/Desktop",
        "regex" : "(^.*)\\/(.*\\.(jpg|png))$",
        "command" : "gwenview $1/$2",
        "entryformat" : "Image $2"
    }
]

Then, add a document.json file:

[
    {
        "searchdirectory" : "/home/user/Desktop",
        "regex" : "(^.*)\\/(.*)\\.pdf$",
        "command" : "okular $1/$2.pdf",
        "entryformat" : "Document $2"
    }
]

Running tui-selector

Assuming the current directory is the root directory of the project, run:

tui-selector ./json-samples

(if tui-selector is not installed but built, run ./build/tui-selector)

The view should look something like this:

tui-example

The tui-selector also has a --timeout <numseconds> flag - with this flag the tool will select the default (first) option once the timeout specified in <numseconds> seconds is reached.

Licensing

The sources are published under the Apache 2.0 License, except for files located in the third-party/ directory. For those files the license is either enclosed in the file header or in a separate LICENSE file.

tui-selector's People

Contributors

glatosinski avatar pzurawski1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.