Add CLI & form interface to your program

Overview

fui

docs.rs crates.io CI MIT licensed

Add CLI & form interface to your program.

Basic example

cargo.toml

[dependencies]
fui = "2.0"

Using with clap (experimental)

= env::args().collect(); if _arg_vec.len() <= 1 { _arg_vec = Fui::from(&app).get_cli_input(); } // regular clap code let matches = app.get_matches_from(_arg_vec);">
extern crate clap;
extern crate fui;

use clap::{App, Arg};
use fui::Fui;
use std::env;

// regular clap code
let app = App::new("some-app").arg(
    Arg::with_name("some-switch")
        .long("arg-long")
        .help("arg-help"),
);


// extra fui code
let mut _arg_vec: Vec<String> = env::args().collect();
if _arg_vec.len() <= 1 {
    _arg_vec = Fui::from(&app).get_cli_input();
}


// regular clap code
let matches = app.get_matches_from(_arg_vec);

asciicast

Using without clap

// Example showing imagined CLI app. with two actions

#[macro_use]
extern crate clap;
extern crate fui;

use fui::{Fui, Value};
use fui::form::FormView;
use fui::fields::Text;

fn hdlr(v: Value) {
    println!("user input (from fn) {:?}", v);
}

fn main() {
    Fui::new(crate_name!())
        .action(
            "action1",
            "help for action1",
            FormView::new().field(Text::new("action1-data").help("help for action1 data")),
            |v| {
                println!("user input (from closure) {:?}", v);
            },
        )
        .action(
            "action2",
            "help for action2",
            FormView::new().field(Text::new("action2-data").help("help for action2 data")),
            hdlr,
        )
        .version(crate_version!())
        .about(crate_description!())
        .author(crate_authors!())
        .run();
}

This will make the program automatically working in 2 modes:

  1. Ready for parsing CLI arguments, like here:

    $ ./app_basic -h
    app_basic 1.0.0
    xliiv <[email protected]>
    An Example program which has CLI & form interface (TUI)
    
    USAGE:
        app_basic [SUBCOMMAND]
    
    FLAGS:
        -h, --help       Prints help information
        -V, --version    Prints version information
    
    SUBCOMMANDS:
        action1    help for action1
        action2    help for action2
        help       Prints this message or the help of the given subcommand(s)
  2. Ready for getting user input from easy and discoverable TUI interface, like image below:

More examples

Here

Screens

app_basic.rs example app_ln_like.rs example app_tar_like.rs example

Clap support

Implemented features

  • switch arguments
  • positional arguments
  • option arguments
  • global arguments
  • subcommands (single level)

To be implemented

TODO

  • find a solution for long help messages
  • ctrl+enter submits (#151)
  • handle unwraps

Ideas

  • .validator(OneOf || Regex::new("v\d+\.\d+\.\d+")).unwrap()?
  • support user's history?
  • checkboxes: automatic toggle on char(+alt)?
  • replace views::Autocomplete & views::Multiselect with a new implementation of Autocomplete
You might also like...
Generate commands that add node_modules/.bin to PATH

npx-bin-helper Generate commands that add node_modules/.bin to PATH. Supports Linux, MacOS and Windows. Installation cargo install npx-bin-helper Usag

This is a placeholder repository for Ludum Dare 52. We'll add more soon!

Ludum Dare 52 This is a placeholder repository for Ludum Dare 52. How to play TBD Developing Only Rust (edition 2021) is required to develop and build

Install a package with e.g. `hdn add pkgs.hello`
Install a package with e.g. `hdn add pkgs.hello`

hdn: utility for updating home.nix Home Manager is great, but it's tedious to run home-manager edit, add your package to the file, and run home-manage

⚗️ Superfast CLI interface for the conventional commits commit format
⚗️ Superfast CLI interface for the conventional commits commit format

resin ⚗️ Superfast CLI interface for the conventional commits commit format ❓ What is resin? resin is a CLI (command-line interface) tool that makes i

⚗️ Superfast CLI interface for the conventional commits commit format
⚗️ Superfast CLI interface for the conventional commits commit format

resin ⚗️ Superfast CLI interface for the conventional commits commit format ❓ What is resin? resin is a CLI (command-line interface) tool that makes i

Crunch is a command-line interface (CLI) to claim staking rewards  every X hours for Substrate-based chains
Crunch is a command-line interface (CLI) to claim staking rewards every X hours for Substrate-based chains

crunch · crunch is a command-line interface (CLI) to claim staking rewards every X hours for Substrate-based chains. Why use crunch To automate payout

Railway CLI - This is the command line interface for Railway.

Railway CLI This is the command line interface for Railway. Use it to connect your code to Railways infrastructure without needing to worry about envi

Scouty is a command-line interface (CLI) to keep an eye on substrate-based chains and hook things up
Scouty is a command-line interface (CLI) to keep an eye on substrate-based chains and hook things up

scouty is a command-line interface (CLI) to keep an eye on substrate-based chains and hook things up

Gix is a command-line interface (CLI) to access git repositories

gix is a command-line interface (CLI) to access git repositories. It's written to optimize the user-experience, and perform as good or better than the

Comments
  • [Question] releases to crates.io

    [Question] releases to crates.io

    TLDR; I came across this crate a while ago and I have implemented support to it into one of the tools I built. A few days ago, you merged a PR from @gyscos for supporting cursive 0.16. Now this is nice since I am in fact able to specify a Cargo.toml dependency to this crate by specifying the repo+ref (commit). The only issue with that is that I can now not publish that crate to crates.io since it does not allow these kinds of dependencies. The current version of fui that is on crates.io is quite old from July 2019 and references cursive 0.11. I am referencing this: https://github.com/replicadse/complate/blob/master/Cargo.toml

    Question: Do you plan to release a new version of fui to crates.io anytime soon? This would enable me to update the dependencies of the packages that reference fui v1.0.1 (and transitively cursive v0.11). I was not able to find any todo or plan to do so or am I missing something obvious?

    Thanks in advance!

    PS: awesome crate!

    opened by replicadse 5
  • Fix compilation error

    Fix compilation error

    This PR fixes an issue I've had compiling this library. Also removed a few unnecessary as_ref's while I was at it.

    > rustc --version
    rustc 1.36.0 (a53f9df32 2019-07-03)
    
    > cargo check
        Checking fui v1.0.0 (/Users/davidlewis/Developer/Learning/fui)
    error[E0283]: type annotations required: cannot resolve `str: std::convert::AsRef<_>`
       --> src/lib.rs:291:34
        |
    291 |         clap::App::new(self.name.as_ref())
        |                                  ^^^^^^
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0283`.
    error: Could not compile `fui`.
    
    opened by davidarmstronglewis 3
  • Default colors are suboptimal

    Default colors are suboptimal

    I tried the examples some days ago and I really liked what I saw.

    Although, the default colors are a bit suboptimal: I was not able to understand that the color for the current selection is the same as for the input field.

    Maybe those should change.

    Or are these defaults provided by cursive? If yes, we should upstream this issue, of course.

    opened by matthiasbeyer 3
  • Fix docs.rs build

    Fix docs.rs build

    You need to update to xcb 1.0.

    and

    Oh, I see what's going on - git = is ignored when publishing, you can't publish a crate with a git dependency so cargo falls back to the version from crates.io.

    from https://github.com/rust-lang/docs.rs/issues/1744

    To Do

    Add temporary deleted the docs badge, see https://github.com/xliiv/fui/pull/134

    Potential solution

    1. migrate https://github.com/aweinstock314/rust-clipboard to one of its forks, like https://github.com/alacritty/copypasta/
      • [x] needs https://github.com/alacritty/copypasta/pull/41
    opened by xliiv 0
Owner
null
Explain semver requirements by converting them into less than, greater than, and/or equal to form.

semver-explain Convert SemVer requirements to their most-obvious equivalents. semver-explain is a CLI tool to explain Semantic Versioning requirements

Andrew Lilley Brinker 27 Oct 29, 2022
This project returns Queried value from SOAP(XML) in form of JSON.

About This is project by team SSDD for HachNUThon (TechHolding). This project stores and allows updating SOAP(xml) data and responds to various querie

Sandipsinh Rathod 3 Apr 30, 2023
Simple CLI to (add, delete, update, create) i18n translation file 🔤 🦀

, Inrs Simple CLI to (add, delete, update, create) i18n translation file Copyright (C) 2020-2022 TheAwiteb https://github.com/TheAwiteb/inrs This pr

TheAwiteb 4 Oct 4, 2022
A simple CLI utility to add rounded borders, padding, and shadows to images.

shadower a simple command-line utility to add rounded corners and shadows to images Installation From AUR paru -S shadower-git From source cargo build

Michał 5 Mar 16, 2023
A CLI tool you can pipe code and then ask for changes, add documentation, etc, using the OpenAI API.

AiBro This is your own little coding bro, immersed in the world of AI, crypto, and all other types of over hyped tech trends. You can pipe it code and

Josh Bainbridge 5 Sep 5, 2023
A silly program written in Rust to output nonsensical sentences in the command line interface.

A silly program written in Rust to output nonsensical sentences in the command line interface.

Rachael Ava 1 Dec 13, 2021
A simple program that provides DBus interface to control display temperature and brightness under wayland without flickering

wl-gammarelay-rs Like wl-gammarelay, but written in rust, runs on a single thread, has three times less SLOC and uses DBus (for simplicity). Dbus inte

Max Verevkin 33 Nov 23, 2022
A simple program for C program IO testing. Written in Rust

A simple program for C program IO testing. Written in Rust, using concurrency to speed up valgrind testing. Make sure to update settings at your first run of the program!

null 1 Feb 22, 2022
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

?? This program is designed to translate text into the correct layout when typing is incorrect. ?? Example ghbdtn -> привет Just (by default) pressing

Gest Se 5 Jan 26, 2023
Add path effects to open glyphs in a UFO file

ufostroker Add path effects to open contours in a UFO file Given a glyph with open contours: You can apply a noodle effect: ufostroker -i Open.ufo -o

Simon Cozens 5 Jun 28, 2021