#table #formatter #text #markdown-tables

table_formatter

用Rust编写的简单文本表格格式化工具

9个版本 (5个重大更新)

0.6.1 2023年7月1日
0.6.0 2023年6月27日
0.5.1 2023年6月10日
0.4.0 2023年6月3日
0.1.0 2023年5月13日

#95值格式化

Download history 323/week @ 2024-03-13 1163/week @ 2024-03-20 232/week @ 2024-03-27 415/week @ 2024-04-03 154/week @ 2024-04-10 172/week @ 2024-04-17 224/week @ 2024-04-24 2270/week @ 2024-05-01 1286/week @ 2024-05-08 384/week @ 2024-05-15 318/week @ 2024-05-22 103/week @ 2024-05-29 162/week @ 2024-06-05 987/week @ 2024-06-12 831/week @ 2024-06-19 641/week @ 2024-06-26

每月下载量2,634

MIT/Apache

42KB
765

表格格式化工具

Repo   Crates-io 版本   语言计数   许可证
构建状态   提交活动   近期下载

此库用于格式化纯文本表格。

示例

代码

use itertools::Itertools;
use table_formatter::{cell, table};
use table_formatter::table::{Align, Border};
let table_header = vec![
    cell!("Cell Row").with_width(Some(20)),
    cell!("Left", align = Align::Left).with_width(Some(10)),
    cell!("Center", align = Align::Center).with_width(Some(10)),
    cell!("Right", align = Align::Right).with_width(Some(10)),
];
let table_cells = {
    let mut v = (0..=3_u8)
        .map(|_| {
            vec![
                cell!("Cell Row"),
                cell!("Left", align = Align::Left),
                cell!("Center", align = Align::Center),
                cell!("Right", align = Align::Right),
            ]
        })
        .collect_vec();
    v.push(cell!("Cross Cell!", align = Align::Center).with_span(3));
    v
};
let table = table! {
    table_header
    ---
    table_cells
    with Border::ALL
};
let mut buffer = vec![];
table.render(&mut buffer).unwrap();
println!("{}", String::from_utf8(buffer).unwrap());

输出

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
┃ Cell Row              Left          Center         Right ┃
┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃
┃ Cell Row              Left          Center         Right ┃
┃ Cell Row              Left          Center         Right ┃
┃ Cell Row              Left          Center         Right ┃
┃ Cell Row              Left          Center         Right ┃
┃                       Cross Cell!                        ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

实际上表格的边框是加粗的,但在markdown中无法渲染。

未来计划

等待报告 :)

变更日志

V0.6.0

  • 更改了格式化器的API,并添加了宏包装器。
  • 添加了文档。

如果您正在使用格式化器,只需将您的 vec! 更改为 fmt!

V0.5.1

此版本已被删除。

V0.5.0

新功能

  • 添加渲染目标:Markdown。
  • 添加跨单元格支持。
  • 添加宏支持。

警告

此版本与先前版本完全不兼容。

许可证

MITApache-2.0

依赖关系

~0.8–11MB
~80K SLoC