Giter Club home page Giter Club logo

termular's Introduction

Termular

Termular is a toolkit for the development of terminal user interfaces that aims to increase the readability and expressiveness of the code. Both goals are achieved by exposing a lazy fluent interface, the latter brings another benefit: greater control over buffers flushing.

Examples

use termular::nio::ReadNonblock;
use termular::printer::{Color, FontWeight, Styled};
use termular::screen::Buffer;
use termular::{Mode, Term};

use std::{io, time::Duration};

fn main() -> io::Result<()> {
    let (stdout, stderr) = (io::stdout(), io::stderr());

    let mut term = Term::open(stdout.lock(), stderr.lock())?;
    let center = term.size()? / 2;

    term.flow()
        .set_mode(Mode::Raw)
        .screen()
        .set_buffer(Buffer::Alternate)
        .clear()
        .cursor()
        .hide()
        .set_position(center - [5, 4])
        .printer()
        .print(
            "Hello world"
                .with_foreground(Color::Green)
                .with_weight(FontWeight::Bold),
        )
        .cursor()
        .set_position(center - [2, 2])
        .printer()
        .print("press")
        .cursor()
        .set_position(center - [5, 1])
        .printer()
        .print("- <SPACE> -")
        .cursor()
        .set_position(center - [3, 0])
        .printer()
        .print("to exit")
        .flush()?;

    term.stdin_mut()
        .read_timeout_until(b' ', &mut Vec::new(), Duration::from_secs(30))
        .map(|_| ())
}

Check out more examples in this folder.

Alternatives

There are a lot of amazing crates around that try to perform the same task (or a very similar one) as Termular.
Here is a list, in no particular order, of those from which I drew inspiration:

Building

Termular relies on the deadline_api feature that has not been stabilized yet, so nightly channel is required in order to build the crate.

Portability

Currently, only UNIX systems are supported, and very few terminals have been tested.

Stability

Termular is in a early development stage so expect it to break compatibility at any time.
Consider this project unstable and not backward compatible.

Safety

Internally, some unsafe blocks are used, mainly to interface with the C language.

License

MIT

termular's People

Contributors

daddinuz avatar

Stargazers

 avatar  avatar

Watchers

 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.