File: border_text.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (44 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! This example demonstrates inserting text into the borders
//! of a [`Table`] with [`BorderText`]; a powerful labeling tool.
//!
//! * [`BorderText`] currently supports:
//!     * Horizontal border placement
//!     * Placement starting column offset
//!     * Text colorization
//!
//! * Note how the flexibility of [`Style`] is utilized
//! to remove horizontal borders from the table entirely,
//! and then granularly reinserts one for a highly customized
//! visualization.
//!
//! * Note how the [`Rows`] utility object is used to idiomatically
//! reference the first and last rows of a [`Table`] without writing
//! the necessary logic by hand.
//!
//! * 🚀 Combining several easy-to-use tools,
//! to create unique data representations is what makes [`tabled`] great!

use tabled::{
    settings::{
        object::Rows,
        style::{HorizontalLine, LineText, Style, VerticalLine},
    },
    Table,
};

fn main() {
    let data = [[5, 6, 7, 8, 9], [10, 11, 12, 13, 14]];

    let line = HorizontalLine::inherit(Style::modern())
        .left(VerticalLine::inherit_left(Style::modern()).get_vertical());
    let style = Style::modern().remove_horizontal().horizontals([(1, line)]);

    let table = Table::new(data)
        .with(style)
        .with(LineText::new("Numbers", Rows::first()).offset(1))
        .with(LineText::new("More numbers", Rows::single(1)).offset(1))
        .with(LineText::new("end.", Rows::last()).offset(1))
        .to_string();

    println!("{table}");
}