6 个版本 (1 个稳定版)
1.1.0 | 2021年3月20日 |
---|---|
1.1.0-alpha.1 | 2020年7月13日 |
1.1.0-alpha | 2020年6月19日 |
0.1.1 | 2020年5月27日 |
#355 in 图形 API
在 rtw 中使用
31KB
560 行
TBL
Terminal Bar (时间)Line (工作进行中)
cargorun --示例datetime
示例
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, "===================== ===========");
}
自定义数据和渲染器
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!★★★★★★★★★");
}
更多示例请参阅 示例文件夹。
变更日志
请参阅 变更日志 了解发布历史。
待办事项
- 支持重叠的时间间隔,例如
[(0,2), (1,3)]
- 为 crate.io 上的发布做准备
- 添加文档
- 添加测试
- 将
build_blocks
分成几个部分
依赖项
~0.7–1.2MB
~26K SLoC