All Projects → VincentFoulon80 → console_engine

VincentFoulon80 / console_engine

Licence: MIT license
A simple terminal framework to draw things and manage user input

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to console engine

Crossterm
Cross platform terminal library rust
Stars: ✭ 1,023 (+610.42%)
Mutual labels:  input, tui
dflat20
D-Flat Windowing System (SAA/CUA Interface) Version 20
Stars: ✭ 42 (-70.83%)
Mutual labels:  tui
rgb-tui
Create and get colors code from the terminal using a nice interface.
Stars: ✭ 57 (-60.42%)
Mutual labels:  tui
octotui
🐙🐱🖥️ GitHub stats in your terminal
Stars: ✭ 202 (+40.28%)
Mutual labels:  tui
vue-input-autowidth
A Vue.js directive that automatically resizes an input's width to fit its contents.
Stars: ✭ 94 (-34.72%)
Mutual labels:  input
lua-evdev
Lua module for reading Linux input events from /dev/input/eventXX nodes
Stars: ✭ 31 (-78.47%)
Mutual labels:  input
lntop
⚡ LN terminal dashboard 📊
Stars: ✭ 170 (+18.06%)
Mutual labels:  tui
rime-nushu
Nushu input method | 𛆁𛈬𛈬𛇈𛊡 | 女书输入法
Stars: ✭ 28 (-80.56%)
Mutual labels:  input
inquire
A Rust library for building interactive prompts
Stars: ✭ 419 (+190.97%)
Mutual labels:  tui
paper-chip
A chip web component made with Polymer 2 following Material Design guidelines
Stars: ✭ 30 (-79.17%)
Mutual labels:  input
international-telephone-input
Integration to Magento 2 a jQuery plugin for entering and validating international telephone numbers.
Stars: ✭ 26 (-81.94%)
Mutual labels:  input
insect
🛠 Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (-77.08%)
Mutual labels:  input
PHP-FileUpload
Simple and convenient file uploads — secure by default
Stars: ✭ 53 (-63.19%)
Mutual labels:  input
tt
Practicing touch typing, and monitor your typing speed using your own text files
Stars: ✭ 68 (-52.78%)
Mutual labels:  tui
FilterInputJs
Tiny and Powerful Library for limit an entry (text box,input) as number,string or more...
Stars: ✭ 37 (-74.31%)
Mutual labels:  input
file-input-accessor
Angular directive that provides file input functionality in Angular forms.
Stars: ✭ 32 (-77.78%)
Mutual labels:  input
vent
Vent is a light-weight platform built to automate network collection and analysis pipelines using a flexible set of popular open source tools and technologies. Vent is python-based, extensible, leverages docker containers, and provides both an API and CLI.
Stars: ✭ 73 (-49.31%)
Mutual labels:  tui
titik
A cross platform minimalistic text user interface
Stars: ✭ 112 (-22.22%)
Mutual labels:  tui
rustpad
Multi-threaded Padding Oracle attacks against any service. Written in Rust.
Stars: ✭ 75 (-47.92%)
Mutual labels:  tui
cursive-tabs
Tabs for gyscos/cursive views 🖥️
Stars: ✭ 21 (-85.42%)
Mutual labels:  tui

Console Engine

Crates.io docs.rs dependency status Crates.io Discussions

Changelog

This library provides simple features for handling user's input and display for terminal applications.
Besides the user input and display, this library also provides some tools to build standalone "screens" that can be used just for printing.

It uses Crossterm as main tool for handling the screen and inputs. You don't have to worry about initalizing anything because the lib will handle this for you.

Summary

Features

  • Build custom terminal display using shapes or text
  • Terminal handling with a target frame per seconds
  • Keyboard and mouse support
  • Terminal resizing support
  • You are not interested by keyboard/mouse handling, even terminal handling ? You can still build "screens" that will just print its content.
  • Embedding screens to one another
  • with feature event:
    • Manage inputs as they arrive
  • with feature form:
    • Build self-managed forms with a set of inputs (text, checkboxes ...)
    • Validate each input with a set of validation constraints

Platforms

Since it uses crossterm, it should work on Windows, Linux and Mac (see Tested Terminals on Crossterm's page).

Example usage

ConsoleEngine (managing input & output)

use console_engine::pixel;
use console_engine::Color;
use console_engine::KeyCode;

fn main() {
    // initializes a screen of 20x10 characters with a target of 3 frames per second
    // coordinates will range from [0,0] to [19,9]
    let mut engine = console_engine::ConsoleEngine::init(20, 10, 3).unwrap();
    let value = 14;
    // main loop, be aware that you'll have to break it because ctrl+C is captured
    loop {
        engine.wait_frame(); // wait for next frame + capture inputs
        engine.clear_screen(); // reset the screen
    
        engine.line(0, 0, 19, 9, pixel::pxl('#')); // draw a line of '#' from [0,0] to [19,9]
        engine.print(0, 4, format!("Result: {}", value).as_str()); // prints some value at [0,4]
    
        engine.set_pxl(4, 0, pixel::pxl_fg('O', Color::Cyan)); // write a majestic cyan 'O' at [4,0]

        if engine.is_key_pressed(KeyCode::Char('q')) { // if the user presses 'q' :
            break; // exits app
        }
    
        engine.draw(); // draw the screen
    }
}

Screens (generating output)

use console_engine::screen::Screen;
use console_engine::pixel;

fn main() {
    // create a screen of 20x11 characters
    let mut scr = Screen::new(20,11);

    // draw some shapes and prints some text
    scr.rect(0,0, 19,10,pixel::pxl('#'));
    scr.fill_circle(5,5, 3, pixel::pxl('*'));
    scr.print(11,4, "Hello,");
    scr.print(11,5, "World!");

    // print the screen to the terminal
    scr.draw();
}

Events (with feature event)

(see examples for complete source code implementation)

loop {
    // Poll next event
    match engine.poll() {
        // A frame has passed
        Event::Frame => {/* ... */}

        // A Key has been pressed
        Event::Key(keyevent) => {/* ... */}

        // Mouse has been moved or clicked
        Event::Mouse(mouseevent) => {/* ... */}

        // Window has been resized
        Event::Resize(w, h) => {/* ... */}
    }
}

Forms (with feature form)

(see examples for complete source code implementation)

// Define a theme for the form
let theme = FormStyle {
    border: Some(BorderStyle::new_light()),
    ..Default::default()
};
// Create a new Form
let mut form = Form::new(
    12,
    6,
    FormOptions {
        style: theme,
        ..Default::default()
    },
);
form.build_field::<Text>(
    "username",
    FormOptions {
        style: theme,
        label: Some("Username"),
        ..Default::default()
    },
);
form.build_field::<HiddenText>(
    "password",
    FormOptions {
        style: theme,
        label: Some("Password"),
        ..Default::default()
    },
);
/* ... */
while !form.is_finished() {
    match engine.poll() {
        /* ... */
        event => form.handle_event(event)
    }
}

Documentation

Take a look at the generated documentation.

Examples

See examples :

  • drag-and-drop : Move a rectangle with your mouse
  • emojis : Display an emoji on the terminal
  • events : Example usage of the event polling method.
  • form-choices : Example usage of a Checkbox and Radio FormFields
  • form-simple : Example creation and usage of a Form containing two inputs
  • form-text : Example usage of a Text FormField
  • form-validation : Example usage of Form Validation
  • graph : Display a graph being generated with some values.
  • lines : Draw random lines of random colors on the screen.
  • lines-fps : Same example as lines, but with a FPS counter.
  • mouse : Simple mouse clicking test
  • screen-embed : Example usage of Screen's print_screen function to embed one screen into another
  • screen-extract : Example usage of Screen's extract function to extract part of a screen
  • screen-simple : Example usage of Screen struct instead of ConsoleEngine
  • screen-swap : Swap between several Screen structures
  • scroll : Example for the scroll function
  • shapes : Shape's functions testing tool
  • snake : A simple game of snake.
  • styled-rect : Example of the rect_border function
  • tetris : A game of Tetris

Media

Trustworthiness

It is recommended to always use cargo-crev to verify the trustworthiness of each of your dependencies, including this one.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].