tbl

Crates.iotbl
lib.rstbl
version1.1.0
sourcesrc
created_at2020-05-25 20:13:41.938526
updated_at2021-03-20 13:25:14.421114
descriptiondisplay timelines in terminal
homepage
repositoryhttps://github.com/PicoJr/tbl
max_upload_size
id245842
size62,476
(PicoJr)

documentation

README

tbl crate tbl documentation GitHub license

TBL

Terminal Bar (time)Line (WIP)

cargo run --example datetime

Example

use tbl::Renderer;

let data = vec![(0., 2.), (3., 4.)];
let rendered = Renderer::new(data.as_slice(), &|&e| e, &|_| None::<String>) // explicit type for Option<Label>
    .with_length(42)
    .render()
    .unwrap();
for line in rendered.iter().flatten() {
    assert_eq!(line, "=====================          ===========");
}

Custom Data and Renderer

use tbl::{Block, RenderBlock, Renderer, TBLError, Bound};

struct CustomData {
   bounds: (usize, usize),
   label: String // must be Clone + Debug
}

fn bounds(cd: &CustomData)-> Bound {
    let (a, b) = cd.bounds;
    (a as f64, b as f64)
}

fn label(cd: &CustomData)-> Option<String> {
   Some(cd.label.clone())
}

fn render(b: &Block<String>) -> RenderBlock {
   match b {
       Block::Space(length) => RenderBlock::Space("\u{2606}".repeat(*length)),
       Block::Segment(length, label) => {
           let mut truncated = label.clone().unwrap_or_default();
           truncated.truncate(*length);
           RenderBlock::Block(format!(
               "{}{}",
               truncated,
               "\u{2605}".repeat(*length - truncated.len())
           ))
       }
   }
}

let data = vec![CustomData{bounds: (0, 2), label: "hello".to_string()}, CustomData{bounds: (3, 4), label: "world!".to_string()}];
let rendered = Renderer::new(data.as_slice(), &bounds, &label)
       .with_length(60)
       .with_renderer(&render)
       .render().unwrap();
for line in rendered.iter().flatten() {
    assert_eq!(line, "hello★★★★★★★★★★★★★★★★★★★★★★★★★☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆world!★★★★★★★★★");
}

See examples folder for more examples.

Changelog

Please see the CHANGELOG for a release history.

TODO

  • support overlapping intervals e.g. [(0,2), (1,3)]
  • prepare for release on crate.io
  • add doc
  • add test
  • split build_blocks into several parts
Commit count: 21

cargo fmt