A collection of common elements and decorators.
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.
```rust extern crate prototty; extern crate protottyunix; extern crate protottycommon;
// 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
DemoTitleView
DemoTitleView.view(title, coord, depth, grid);
}
}
impl ViewSizefn 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: