#input #term #terminal #cli-input #ui #command-line #cli

proceed

A simple rust cli abstraction for accepting user-input

1 unstable release

0.1.0 Sep 11, 2020
0.0.1 Jul 30, 2018

#985 in Command-line interface

Download history 27/week @ 2024-07-20 76/week @ 2024-07-27 51/week @ 2024-08-03 45/week @ 2024-08-10 19/week @ 2024-08-17 40/week @ 2024-08-24 121/week @ 2024-08-31 10/week @ 2024-09-07 14/week @ 2024-09-14 18/week @ 2024-09-21 41/week @ 2024-09-28 28/week @ 2024-10-05 64/week @ 2024-10-12 25/week @ 2024-10-19 3/week @ 2024-10-26 5/week @ 2024-11-02

102 downloads per month
Used in bhop

MIT license

14KB
216 lines

Proceed

Current Release: v0.1.0

License builds.sr.ht status Latest version Documentation

A simple set of common utility functions for checking with the user of your command line application.

  • proceed(bool) - Y/N with default.
  • any_or_quit_with(char) - Any key unless char for quit.

These are wrappers around a flexible user-input checker, so you can customize as needed.

Out-of-Scope:

  • no_std - We need std I/O.
  • Translations or handling string output in general. Use any of the i18n packages.

Examples:

Just check yes or no, with a default of either YES or NO.

use proceed::{proceed, NO};

fn main() {
    print!("Are you sure? [y/N]");
    if !proceed(NO) {
       return;
    }
    // Do things now that we got confirmation.
}

Continue on any user input (but 'q' for quit). Needs term feature enabled, otherwise user will need to press "Enter" afterwards.

use proceed::any_or_quit;

fn main() {
    println!("We are about to do something expensive.");
    print!("Press any key to continue, or 'q' to quit.");
    if !any_or_quit_with('q') {
        println!("Quitting.");
        return;
    }
    // Do expensive operation.
}

Dependencies

~26KB