13 个版本 (稳定版)

1.3.3 2023年10月10日
1.3.2 2023年1月28日
1.3.1 2020年2月29日
1.1.3 2019年12月15日
0.1.1 2019年9月8日

#147 in 文本处理


用于 jobrog

MIT 许可证

275KB
961

colonnade

表格文本

         Colonnade lets     As you can see, it supports text     If you want to 
        you format text      alignment, viewport width, and      colorize your  
            in columns.              column widths.              table, you'll  
                                                                 need to use the
                                                                 macerate       
                                                                 method.        

                           Two or more rows of columns makes                    
                                        a table.                                

用法

extern crate colonnade;
use colonnade::{Alignment, Colonnade};

#[allow(unused_must_use)]
fn main() {
    // text to put in tabular form
    let text = vec![
        vec![
            "Colonnade lets you format text in columns.",
            "As you can see, it supports text alignment, viewport width, and column widths.",
            "If you want to colorize your table, you'll need to use the macerate method.",
        ],
        vec!["", "Two or more rows of columns makes a table.", ""],
    ];
    let mut colonnade = Colonnade::new(3, 80).unwrap(); // 3 columns of text in an 80-character viewport

    // configure the table a bit
    colonnade.left_margin(4);
    colonnade.columns[0].left_margin(8); // the first column should have a left margin 8 spaces wide
    colonnade.fixed_width(15);
    colonnade.columns[0].clear_limits(); // the central column has no fixed size limits
    colonnade.columns[0].alignment(Alignment::Right);
    colonnade.columns[1].alignment(Alignment::Center);
    colonnade.spaces_between_rows(1);    // add a blank link between rows

    // now print out the table
    for line in colonnade.tabulate(&text).unwrap() {
        println!("{}", line);
    }
}

这会产生页面顶部的文本。

有关详细信息,请参阅 docs.rs 上的文档

依赖项

~0.7–1.3MB
~20K SLoC