#common #ui #terminal #elements #rapid #definition

prototty_common

Definition of common ui elements and views for use with prototty

32 releases (19 breaking)

0.25.0 Mar 1, 2019
0.23.0 Feb 3, 2019
0.20.0 Apr 3, 2018
0.19.4 Mar 6, 2018
Download history 26/week @ 2018-11-17 163/week @ 2018-11-24 62/week @ 2018-12-01 52/week @ 2018-12-08 5/week @ 2018-12-15 177/week @ 2018-12-22 26/week @ 2018-12-29 42/week @ 2019-01-05 44/week @ 2019-01-12 2/week @ 2019-01-19 3/week @ 2019-01-26 46/week @ 2019-02-02 18/week @ 2019-02-09 1/week @ 2019-02-16 65/week @ 2019-02-23

181 downloads per month
Used in 2 crates (1 directly)

MIT license

53KB
1.5K SLoC

prototty_common

Version Documentation

A collection of common elements and decorators.

Decorators Example

Let's continue the title example started here:

This will extend the unix frontend to draw a border around its output using the Border decorator defined in this crate.

extern crate prototty;
extern crate prototty_unix;
extern crate prototty_common;

// Assuming the title and its views were defined here
extern crate prototty_title;

use prototty::{Renderer, View, ViewSize, ViewGrid, Coord, Size};
use prototty_title::*;

// The `Border` decorator in prototty_common requires that the
// view which it decorates implements `ViewSize`, defined in
// prototty. Since neither `ViewSize` nor `Title` are defined
// in this crate, we need to define a new type, and implement
// `View` and `ViewSize` here in this crate.
struct SizedDemoTitleView;
impl View<Title> for SizedDemoTitleView {
    fn view<G: ViewGrid>(&self, title: &Title, coord: Coord, depth: i32, grid: &mut G) {
        // behave identically to `DemoTitleView`
        DemoTitleView.view(title, coord, depth, grid);
    }
}
impl ViewSize<Title> for SizedDemoTitleView {
    fn size(&self, title: &Title) -> Size {
        // 3 high, since the title is rendered on
        // line 0 and 2
        Size::new(title.width, 3)
    }
}

fn main() {

    let mut context = prototty_unix::Context::new().unwrap();

    let title = Title {
        width: 20,
        text: "My Title".to_string(),
    };

    // create and configure the border
    let mut border = prototty_common::Border::new();
    border.title = Some("Border Title".to_string());
    border.underline_title = true;

    // create a decorated view
    let decorated_view = prototty_common::Decorated::new(&SizedDemoTitleView, &border);

    // render the title using the view
    context.render(&decorated_view, &title).unwrap();

    // exit after a key is pressed
    context.wait_input().unwrap();
}

Running this will produce the following output in your terminal:

Example

Dependencies

~239KB