Giter Site home page Giter Site logo

facebookincubator / superconsole Goto Github PK

View Code? Open in Web Editor NEW
456.0 24.0 14.0 6.57 MB

The superconsole crate provides a handler and building blocks for powerful, yet minimally intrusive TUIs. It is cross platform, supporting Windows 7+, Linux, and MacOS. Rustaceans who want to create non-interactive TUIs can use the component composition building block system to quickly deploy their code.

License: Apache License 2.0

Rust 100.00%

superconsole's Introduction

A component-based framework for building Rust Text-based User Interfaces (TUIs)

There are several copies of this repo on GitHub, facebookincubator/superconsole is the canonical one.

The superconsole framework provides a powerful line based abstraction over text based rendering to the terminal. It also provides basic building blocks like line manipulation, and a higher level of composable components. A base set of "batteries" components are included to help developers create Text-based User Interfaces (TUIs) as quickly as possible.

The design choices that underly superconsole are selected to prioritize testability, ease of composition, and flexibility.

Superconsole also offers stylization, including italics, underlining, bolding, and coloring text. Furthermore, relying on crossterm ensures that it is compatible with Windows, Unix, and MacOS.

Finally, superconsole delineates between rendering logic and program state - each render call accepts an immutable reference to state, which components may use to inject state into their otherwise immutable rendering logic.

Demo

Superconsole running some buck2 tests

Examples

use std::convert::TryInto;
use superconsole::components::bordering::{Bordered, BorderedSpec};
use superconsole::{Component, Dimensions, DrawMode, Lines, SuperConsole};

#[derive(Debug)]
struct HelloWorld;

impl Component for HelloWorld {
    fn draw_unchecked(&self, _dimensions: Dimensions, _mode: DrawMode) -> anyhow::Result<Lines> {
        Ok(Lines(vec![
            vec!["Hello world!".to_owned()].try_into().unwrap(),
        ]))
    }
}

pub fn main() -> anyhow::Result<()> {
    let bordering = BorderedSpec::default();
    let mut superconsole = SuperConsole::new().ok_or_else(|| anyhow::anyhow!("Not a TTY"))?;
    let component = Bordered::new(HelloWorld, bordering);
    superconsole.render(&component)?;
    superconsole.finalize(&component)?;
    Ok(())
}

See the CONTRIBUTING file for how to help out.

License

Superconsole is both MIT and Apache License, Version 2.0 licensed, as found in the LICENSE-MIT and LICENSE-APACHE files.

superconsole's People

Contributors

stepancheg avatar ndmitchell avatar krallin avatar zertosh avatar facebook-github-bot avatar jakobdegen avatar lmvasquezg avatar artempyanykh avatar bobyangyf avatar cjhopman avatar davidbarsky avatar themarwhal avatar muirdm avatar philipcraig avatar kapji avatar

Stargazers

Lalo avatar  avatar Lucas Forato avatar Luckas avatar Tsiry Sandratraina avatar Emil Harvey avatar Hiroki Noda avatar Jasha Sommer-Simpson avatar Junyi Mei avatar  avatar  avatar Mason Ginter avatar B3NNY avatar Narain  avatar Sam Bristow avatar Wasawat Somno avatar t avatar Johnson Masilla Vino avatar Erik Mjaaland Skår avatar hiyori avatar Sreedev Kodichath avatar  avatar Carlos L. Torres avatar Grégoire Geis avatar Moheshwar Amarnath Biswas avatar Valentin Vareskic avatar Artur Sagitov avatar cdesch avatar Trung avatar Aatif Syed avatar  avatar Arvid Gerstmann avatar Venky Venkatakrishnan avatar Thomas Gale avatar  avatar trogdor avatar Jake W avatar Dirk Gadsden avatar Dariusz Adamczyk avatar Edwin Kofler avatar Luca Muscat avatar  avatar Sung Gon Kim avatar Vasily Kondratyev avatar Spencer Gilbert avatar TrashCan avatar Syi avatar Weasel avatar 0xYYY avatar sam bacha avatar Ian Stanton avatar Tyler Kruer avatar Azerpas avatar Jordan Ellis Coppard avatar  avatar f avatar garming avatar Yi Rong avatar mhx avatar Alex Hampu avatar am elemara avatar Jason Skrzypek avatar Ryan Scott Brown avatar Rahul Butani avatar Akarsh avatar Raymond Dang avatar Alraj Kabeer avatar Tim Marx avatar  avatar Rahul Ballal avatar Software Nerd avatar Ross Delinger avatar Jag Chadha avatar  avatar Diana avatar WANG avatar Leo Dutra avatar Mike avatar Jin Long avatar Yerkebulan Tulibergenov avatar Kevin Mark avatar Maxwell Koo avatar Thomas Kosiewski avatar Henil avatar LIU JIE avatar Huang Chen-Yi avatar Ravi Teja avatar Fujiwara Takumi avatar Alex avatar Thomas Cameron avatar Weihang Lo avatar Dalton Walker avatar xu0o0 avatar Peter Výboch avatar Bear avatar Tyler Fisher avatar  avatar Eric Crosson avatar Tim Lingard avatar Christian Hudon avatar

Watchers

 avatar Jake W avatar  avatar Chat avatar  avatar  avatar  avatar  avatar David Tolnay avatar Yipu Miao avatar  avatar  avatar  avatar Sean Karlage avatar Cami Williams avatar Natalie Jameson avatar Mykola Semko avatar Suraj avatar  avatar Will Li avatar  avatar  avatar Lie Albert Januar Linarco avatar  avatar

superconsole's Issues

State is not very type safe

As i stated in my other issue [#5] I'm very much enjoying using this library. Thanks again!

I would love to have some more type safety around state. If I decide to change the type of some piece of state, the compiler isn't going to complain and I will hit runtime errors. If state were instead a generic type then I could fill that in with the state type for my app and run into these errors at compile time.

Interfaces for languages beyond Rust

This is exactly the library I've been looking for. However, I'd need to include it in a C++ project.

I don't have a lot of experience with Rust, so I'm not sure how viable it would be to make the superconsole interface available to languages like C++ or Python without having to re-write large parts of the core.

Any feedback on the viability would be appreciated.

Consider not using anyhow::Error

I recently started using superconsole and I really like it. Thanks for making this! 🙏

The use of anyhow presents a bit of an ergonomics problem however. For example, in my application I use eyre and I have to manually map_err your anyhow errors to eyre::Reports. It seems that under the hood you are using thiserror to define errors. Perhaps these could be brought up to the surface instead of wrapping them in anyhow::Error?

Remove `rust-toolchain` file

I do understand that using superconsole strictly as a dependency, I'm not really affected by the toolchain file.

My grumble is more on the QA side of things. Looks like the requirement for a pinned nightly version comes from some Meta internal CI or something. That rust-toolchain file kind of indicates, that superconsole is basically never build with current stable, no?

So, for the public superconsole repo, I think, the toolchain file should either be removed or use the stable channel.

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.