Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/gh-pages.yml

This file was deleted.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["cli-table", "cli-table-derive", "test-suite"]
resolver = "3"
12 changes: 8 additions & 4 deletions cli-table-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ categories = ["command-line-interface"]
keywords = ["table", "cli", "format"]
readme = "README.md"
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-*"]
edition = "2018"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
doc = []

[dependencies]
proc-macro2 = "1.0.86"
syn = "1.0.109"
quote = "1.0.36"
proc-macro2 = "1.0.94"
syn = "2.0.100"
quote = "1.0.40"

[lib]
proc-macro = true
4 changes: 2 additions & 2 deletions cli-table-derive/src/context/fields.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use syn::{
spanned::Spanned, Data, DeriveInput, Error, Expr, Field as SynField, Fields as SynFields,
Ident, Index, Lit, LitBool, LitStr, Result,
Data, DeriveInput, Error, Expr, Field as SynField, Fields as SynFields, Ident, Index, Lit,
LitBool, LitStr, Result, spanned::Spanned,
};

use crate::utils::get_attributes;
Expand Down
2 changes: 1 addition & 1 deletion cli-table-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod table;
mod utils;

use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};
use syn::{DeriveInput, parse_macro_input};

#[proc_macro_derive(Table, attributes(table))]
/// Derive macro to implementing `cli_table` traits
Expand Down
59 changes: 23 additions & 36 deletions cli-table-derive/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,36 @@
use syn::{spanned::Spanned, Attribute, Error, Lit, LitBool, Meta, NestedMeta, Path, Result};
use syn::{Attribute, Error, Lit, LitBool, Path, Result, spanned::Spanned};

pub fn get_attributes(attrs: &[Attribute]) -> Result<Vec<(Path, Lit)>> {
let mut attributes = Vec::new();

for attribute in attrs {
if !attribute.path.is_ident("table") {
if !attribute.path().is_ident("table") {
continue;
}

let meta = attribute.parse_meta()?;

let meta_list = match meta {
Meta::List(meta_list) => Ok(meta_list),
bad => Err(Error::new_spanned(
bad,
"Attributes should be of type: #[table(key = \"value\", ..)]",
)),
}?;

for nested_meta in meta_list.nested.into_iter() {
let meta = match nested_meta {
NestedMeta::Meta(meta) => Ok(meta),
bad => Err(Error::new_spanned(
bad,
"Attributes should be of type: #[table(key = \"value\", ..)]",
)),
}?;

match meta {
Meta::Path(path) => {
let lit = LitBool {
if attribute
.parse_nested_meta(|meta| {
let path = meta.path.clone();
let lit = meta
.value()
.ok()
.map(|v| v.parse())
.transpose()?
.unwrap_or(Lit::from(LitBool {
value: true,
span: path.span(),
}
.into();
attributes.push((path, lit));
}
Meta::NameValue(meta_name_value) => {
attributes.push((meta_name_value.path, meta_name_value.lit));
}
bad => return Err(Error::new_spanned(
bad,
"Attributes should be of type: #[table(key = \"value\", ..)] or #[table(bool)]",
)),
}
}));

attributes.push((path, lit));

Ok(())
})
.is_err()
{
return Err(Error::new_spanned(
attribute,
"Attributes should be of type: #[table(key = \"value\", ..)] or #[table(bool)]",
));
}
}

Expand Down
6 changes: 3 additions & 3 deletions cli-table/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ categories = ["command-line-interface"]
keywords = ["table", "cli", "format"]
readme = "README.md"
include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-*"]
edition = "2018"
edition = "2024"

[lib]
name = "cli_table"
Expand All @@ -20,9 +20,9 @@ path = "src/lib.rs"

[dependencies]
cli-table-derive = { version = "0.4.6", path = "../cli-table-derive", optional = true }
csv = { version = "1.3.0", optional = true }
csv = { version = "1.3.1", optional = true }
termcolor = "1.4.1"
unicode-width = "0.1.13"
unicode-width = "0.2.0"

[features]
default = ["csv", "derive"]
Expand Down
2 changes: 1 addition & 1 deletion cli-table/examples/csv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{convert::TryFrom, io::Result};

use cli_table::{print_stdout, TableStruct};
use cli_table::{TableStruct, print_stdout};
use csv::ReaderBuilder;

fn main() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion cli-table/examples/nested.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::Result;

use cli_table::{format::Justify, Cell, Style, Table};
use cli_table::{Cell, Style, Table, format::Justify};

fn main() -> Result<()> {
let nested_table = vec![vec![20.cell()]].table();
Expand Down
2 changes: 1 addition & 1 deletion cli-table/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::Result;

use cli_table::{format::Justify, print_stdout, Cell, Style, Table};
use cli_table::{Cell, Style, Table, format::Justify, print_stdout};

fn main() -> Result<()> {
let table = vec![
Expand Down
3 changes: 2 additions & 1 deletion cli-table/examples/struct.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::io::Result;

use cli_table::{
Color, Table, WithTitle,
format::{Align, Justify},
print_stdout, Color, Table, WithTitle,
print_stdout,
};

#[derive(Debug, Table)]
Expand Down
3 changes: 2 additions & 1 deletion cli-table/examples/tuple_struct.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::io::Result;

use cli_table::{
Table, WithTitle,
format::{HorizontalLine, Justify::Right, Separator},
print_stdout, Table, WithTitle,
print_stdout,
};

#[derive(Debug, Table)]
Expand Down
4 changes: 2 additions & 2 deletions cli-table/src/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> Buffers<'a> {
}
}

impl<'a> Write for Buffers<'a> {
impl Write for Buffers<'_> {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
if let Some(ref mut current_buffer) = self.current_buffer {
current_buffer.write(buf)
Expand All @@ -73,7 +73,7 @@ impl<'a> Write for Buffers<'a> {
}
}

impl<'a> WriteColor for Buffers<'a> {
impl WriteColor for Buffers<'_> {
fn supports_color(&self) -> bool {
match self.current_buffer {
Some(ref buffer) => buffer.supports_color(),
Expand Down
4 changes: 1 addition & 3 deletions cli-table/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ pub(crate) fn print_horizontal_line(
let mut widths = table_dimension.widths.iter().peekable();

while let Some(width) = widths.next() {
let s = std::iter::repeat(line.filler)
.take(width + 2)
.collect::<String>();
let s = std::iter::repeat_n(line.filler, width + 2).collect::<String>();
print_str(buffers, &s, color_spec)?;

match widths.peek() {
Expand Down
8 changes: 4 additions & 4 deletions test-suite/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "test-suite"
version = "0.1.0"
authors = ["devashishdixit"]
edition = "2018"
authors = ["Devashish Dixit <devashishdxt@gmail.com>"]
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cli-table = { path = "../cli-table" }

[dev-dependencies]
rustversion = "1.0.9"
trybuild = { version = "1.0.71", features = ["diff"] }
rustversion = "1.0.20"
trybuild = { version = "1.0.104", features = ["diff"] }
2 changes: 1 addition & 1 deletion test-suite/tests/ui/non-display-member.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ error[E0277]: the trait bound `&Vec<u8>: cli_table::Cell` is not satisfied
5 | struct Test {
6 | / #[table(title = "a")]
7 | | a: Vec<u8>,
| |_____^ the trait `std::fmt::Display` is not implemented for `&Vec<u8>`, which is required by `&Vec<u8>: cli_table::Cell`
| |______________^ the trait `std::fmt::Display` is not implemented for `Vec<u8>`
|
= help: the trait `cli_table::Cell` is implemented for `CellStruct`
= note: required for `&Vec<u8>` to implement `std::fmt::Display`
Expand Down
Loading