Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkforest committed Dec 27, 2022
2 parents b5711df + e206f71 commit 7c50d8d
Show file tree
Hide file tree
Showing 24 changed files with 1,086 additions and 381 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: cargo
directory: "/"
schedule:
interval: daily
time: "04:00"
open-pull-requests-limit: 10
reviewers:
- phsym
assignees:
- phsym
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "prettytable-rs"
version = "0.8.0"
version = "0.9.0"
description = "A library for printing pretty formatted tables in terminal"
homepage = "https://github.com/phsym/prettytable-rs"
repository = "https://github.com/phsym/prettytable-rs"
Expand All @@ -20,6 +20,7 @@ exclude = [
appveyor = { repository = "phsym/prettytable-rs", branch = "master", service = "github" }
travis-ci = { repository = "phsym/prettytable-rs", branch = "master" }
codecov = { repository = "phsym/prettytable-rs", branch = "master", service = "github" }
maintenance = { status = "passively-maintained" }

[features]
default = ["win_crlf", "csv"]
Expand All @@ -36,8 +37,8 @@ name = "prettytable"

[dependencies]
unicode-width = "0.1"
term = "0.6"
term = "0.7"
lazy_static = "1"
atty = "0.2"
encode_unicode = "0.3"
is-terminal = "0.4"
encode_unicode = "1"
csv = { version = "1", optional = true }
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019, Pierre-Henri Symoneaux
Copyright (c) 2022, Pierre-Henri Symoneaux
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
[![Crates.io](https://img.shields.io/crates/v/prettytable-rs.svg)](https://crates.io/crates/prettytable-rs)
[![Doc.rs](https://docs.rs/prettytable-rs/badge.svg)](https://docs.rs/crate/prettytable-rs/)
[![Doc.rs](https://img.shields.io/badge/docs-master-blue.svg)](http://phsym.github.io/prettytable-rs/master)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=phsym/prettytable-rs)](https://dependabot.com)

# prettytable-rs

A formatted and aligned table printer library for [Rust](https://www.rust-lang.org).

*Copyright © 2019 Pierre-Henri Symoneaux*
*Copyright © 2022 Pierre-Henri Symoneaux*

> THIS SOFTWARE IS DISTRIBUTED WITHOUT ANY WARRANTY <br>
> Check LICENSE.txt file for more information. <br>
Expand All @@ -37,10 +37,10 @@ Include the library as a dependency to your project by adding the following line

```toml
[dependencies]
prettytable-rs = "^0.8"
prettytable-rs = "^0.9"
```

The library requires at least `rust v1.32.0`.
The library requires at least `rust v1.41`.

## Basic usage

Expand Down
24 changes: 16 additions & 8 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use prettytable::{Table, Row, Cell, row, table, ptable};
use prettytable::{ptable, row, table, Cell, Row, Table};

/*
Following main function will print :
Expand All @@ -22,19 +22,27 @@ fn main() {
let mut table = Table::new();
table.add_row(row!["ABC", "DEFG", "HIJKLMN"]);
table.add_row(row!["foobar", "bar", "foo"]);
table.add_row(Row::new(vec![Cell::new("foobar2"), Cell::new("bar2"), Cell::new("foo2")]));
table.add_row(Row::new(vec![
Cell::new("foobar2"),
Cell::new("bar2"),
Cell::new("foo2"),
]));
table.printstd();
println!("Modified : ");
table.set_element("new_foo", 2, 1).unwrap();
table.printstd();

// The same table can be built the following way :
let _table = table!(["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]);
let _table = table!(
["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]
);

// Or directly print it like this
let _table = ptable!(["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]);
let _table = ptable!(
["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]
);
}
14 changes: 9 additions & 5 deletions examples/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
fn main() {
use prettytable::Table;

let table = Table::from_csv_string("ABC,DEFG,HIJKLMN\n\
let table = Table::from_csv_string(
"ABC,DEFG,HIJKLMN\n\
foobar,bar,foo\n\
foobar2,bar2,foo2")
.unwrap();
foobar2,bar2,foo2",
)
.unwrap();
table.printstd();

println!("");
println!("{}",
String::from_utf8(table.to_csv(Vec::new()).unwrap().into_inner().unwrap()).unwrap());
println!(
"{}",
String::from_utf8(table.to_csv(Vec::new()).unwrap().into_inner().unwrap()).unwrap()
);
}

#[cfg(not(feature = "csv"))]
Expand Down
51 changes: 31 additions & 20 deletions examples/formatting.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use prettytable::{format, table, row};
use prettytable::{format, row, table};

fn main() {
let mut table = table!(["Value 1", "Value 2"], ["Value three", "Value four"]);
Expand Down Expand Up @@ -59,14 +59,17 @@ fn main() {
// | Value three | Value four |
// +-------------+------------+
println!("Custom :");
table.set_format(format::FormatBuilder::new()
.column_separator('|')
.borders('|')
.separators(&[format::LinePosition::Top,
format::LinePosition::Bottom],
format::LineSeparator::new('-', '+', '+', '+'))
.padding(1, 1)
.build());
table.set_format(
format::FormatBuilder::new()
.column_separator('|')
.borders('|')
.separators(
&[format::LinePosition::Top, format::LinePosition::Bottom],
format::LineSeparator::new('-', '+', '+', '+'),
)
.padding(1, 1)
.build(),
);
table.printstd();

// Customized format with unicode
Expand All @@ -79,17 +82,25 @@ fn main() {
// │ Value three │ Value four │
// └─────────────┴────────────┘
println!("With unicode:");
table.set_format(format::FormatBuilder::new()
.column_separator('│')
.borders('│')
.separators(&[format::LinePosition::Top],
format::LineSeparator::new('─', '┬', '┌', '┐'))
.separators(&[format::LinePosition::Intern],
format::LineSeparator::new('─', '┼', '├', '┤'))
.separators(&[format::LinePosition::Bottom],
format::LineSeparator::new('─', '┴', '└', '┘'))
.padding(1, 1)
.build());
table.set_format(
format::FormatBuilder::new()
.column_separator('│')
.borders('│')
.separators(
&[format::LinePosition::Top],
format::LineSeparator::new('─', '┬', '┌', '┐'),
)
.separators(
&[format::LinePosition::Intern],
format::LineSeparator::new('─', '┼', '├', '┤'),
)
.separators(
&[format::LinePosition::Bottom],
format::LineSeparator::new('─', '┴', '└', '┘'),
)
.padding(1, 1)
.build(),
);
table.printstd();

// Customized format with unicode and different padding
Expand Down
16 changes: 10 additions & 6 deletions examples/multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ use prettytable::table;
+-------------------------+------------------------------+
*/
fn main() {
let table1 = table!(["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]);
let table2 = table!(["Title 1", "Title 2"],
["This is\na multiline\ncell", "foo"],
["Yo dawg ;) You can even\nprint tables\ninto tables", table1]);
let table1 = table!(
["ABC", "DEFG", "HIJKLMN"],
["foobar", "bar", "foo"],
["foobar2", "bar2", "foo2"]
);
let table2 = table!(
["Title 1", "Title 2"],
["This is\na multiline\ncell", "foo"],
["Yo dawg ;) You can even\nprint tables\ninto tables", table1]
);
table2.printstd();
}
11 changes: 9 additions & 2 deletions examples/slices.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use prettytable::{Slice, table, row};
use prettytable::{row, table, Slice};

fn main() {
let mut table = table![[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]];
let mut table = table![
[0, 0, 0],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5]
];
table.set_titles(row!["t1", "t2", "t3"]);

let slice = table.slice(..);
Expand Down
22 changes: 11 additions & 11 deletions examples/span.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use prettytable::{Row, Cell, format::Alignment, table};

use prettytable::{format::Alignment, table, Cell, Row};

fn main() {

/*
The following code will output
Expand All @@ -18,12 +16,14 @@ fn main() {
*/

let mut table: prettytable::Table = table![
[H2 -> "This is a cell with span of 2", "span of 1"],
["span of 1", "span of 1", "span of 1"],
[H03c -> "This cell with a span of 3 is centered"]
];
table.set_titles(Row::new(vec![
Cell::new_align("A table with horizontal span", Alignment::CENTER).with_hspan(3)
]));
[H2 -> "This is a cell with span of 2", "span of 1"],
["span of 1", "span of 1", "span of 1"],
[H03c -> "This cell with a span of 3 is centered"]
];
table.set_titles(Row::new(vec![Cell::new_align(
"A table with horizontal span",
Alignment::CENTER,
)
.with_hspan(3)]));
table.printstd();
}
}
22 changes: 11 additions & 11 deletions examples/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use prettytable::{Table, Row, Cell};
use prettytable::{Attr, color};
use prettytable::{table, row, cell, ptable};
use prettytable::{cell, ptable, row, table};
use prettytable::{color, Attr};
use prettytable::{Cell, Row, Table};

#[allow(dead_code)]
fn main() {
Expand All @@ -11,14 +11,14 @@ fn main() {
// Add style to a full row
table.add_row(row![FY => "styled", "bar", "foo"]);
table.add_row(Row::new(vec![
Cell::new("foobar2"),
// Create a cell with a red foreground color
Cell::new("bar2").with_style(Attr::ForegroundColor(color::RED)),
// Create a cell with red foreground color, yellow background color, with bold characters
Cell::new("foo2").style_spec("FrByb"),
// Using the cell! macro
cell!(Fr->"red")])
);
Cell::new("foobar2"),
// Create a cell with a red foreground color
Cell::new("bar2").with_style(Attr::ForegroundColor(color::RED)),
// Create a cell with red foreground color, yellow background color, with bold characters
Cell::new("foo2").style_spec("FrByb"),
// Using the cell! macro
cell!(Fr->"red"),
]));

table.printstd();

Expand Down
2 changes: 1 addition & 1 deletion examples/tictactoe.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use prettytable::{Table, table, cell};
use prettytable::{cell, table, Table};

use std::io;
use std::io::Write;
Expand Down
3 changes: 3 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
corpus
artifacts

0 comments on commit 7c50d8d

Please sign in to comment.