Skip to content

Commit 806dbb9

Browse files
committed
feat: add table formatting for commit message display 📊
- add tabled dependency for structured output formatting - implement print_table function with rounded styling and text wrapping - add print_table CLI flag with default true value - include comprehensive test case for table display functionality - set table width limit to 120 characters with left alignment Signed-off-by: mingcheng <[email protected]>
1 parent bb07821 commit 806dbb9

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

Cargo.lock

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies = [
2121
"git2",
2222
"log",
2323
"reqwest",
24+
"tabled",
2425
"tokio",
2526
"tracing",
2627
"tracing-subscriber",
@@ -224,6 +225,12 @@ version = "3.19.0"
224225
source = "registry+https://github.com/rust-lang/crates.io-index"
225226
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
226227

228+
[[package]]
229+
name = "bytecount"
230+
version = "0.6.9"
231+
source = "registry+https://github.com/rust-lang/crates.io-index"
232+
checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e"
233+
227234
[[package]]
228235
name = "bytemuck"
229236
version = "1.24.0"
@@ -1450,6 +1457,17 @@ dependencies = [
14501457
"vcpkg",
14511458
]
14521459

1460+
[[package]]
1461+
name = "papergrid"
1462+
version = "0.17.0"
1463+
source = "registry+https://github.com/rust-lang/crates.io-index"
1464+
checksum = "6978128c8b51d8f4080631ceb2302ab51e32cc6e8615f735ee2f83fd269ae3f1"
1465+
dependencies = [
1466+
"bytecount",
1467+
"fnv",
1468+
"unicode-width",
1469+
]
1470+
14531471
[[package]]
14541472
name = "parking_lot"
14551473
version = "0.12.5"
@@ -1528,6 +1546,28 @@ dependencies = [
15281546
"zerocopy",
15291547
]
15301548

1549+
[[package]]
1550+
name = "proc-macro-error-attr2"
1551+
version = "2.0.0"
1552+
source = "registry+https://github.com/rust-lang/crates.io-index"
1553+
checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5"
1554+
dependencies = [
1555+
"proc-macro2",
1556+
"quote",
1557+
]
1558+
1559+
[[package]]
1560+
name = "proc-macro-error2"
1561+
version = "2.0.1"
1562+
source = "registry+https://github.com/rust-lang/crates.io-index"
1563+
checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802"
1564+
dependencies = [
1565+
"proc-macro-error-attr2",
1566+
"proc-macro2",
1567+
"quote",
1568+
"syn",
1569+
]
1570+
15311571
[[package]]
15321572
name = "proc-macro2"
15331573
version = "1.0.101"
@@ -2091,6 +2131,30 @@ dependencies = [
20912131
"libc",
20922132
]
20932133

2134+
[[package]]
2135+
name = "tabled"
2136+
version = "0.20.0"
2137+
source = "registry+https://github.com/rust-lang/crates.io-index"
2138+
checksum = "e39a2ee1fbcd360805a771e1b300f78cc88fec7b8d3e2f71cd37bbf23e725c7d"
2139+
dependencies = [
2140+
"papergrid",
2141+
"tabled_derive",
2142+
"testing_table",
2143+
]
2144+
2145+
[[package]]
2146+
name = "tabled_derive"
2147+
version = "0.11.0"
2148+
source = "registry+https://github.com/rust-lang/crates.io-index"
2149+
checksum = "0ea5d1b13ca6cff1f9231ffd62f15eefd72543dab5e468735f1a456728a02846"
2150+
dependencies = [
2151+
"heck",
2152+
"proc-macro-error2",
2153+
"proc-macro2",
2154+
"quote",
2155+
"syn",
2156+
]
2157+
20942158
[[package]]
20952159
name = "tempfile"
20962160
version = "3.23.0"
@@ -2104,6 +2168,15 @@ dependencies = [
21042168
"windows-sys 0.61.2",
21052169
]
21062170

2171+
[[package]]
2172+
name = "testing_table"
2173+
version = "0.3.0"
2174+
source = "registry+https://github.com/rust-lang/crates.io-index"
2175+
checksum = "0f8daae29995a24f65619e19d8d31dea5b389f3d853d8bf297bbf607cd0014cc"
2176+
dependencies = [
2177+
"unicode-width",
2178+
]
2179+
21072180
[[package]]
21082181
name = "thiserror"
21092182
version = "1.0.69"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ clap = { version = "4.5", features = ["derive", "env"] }
3737
tracing = "0.1"
3838
tracing-subscriber = "0.3"
3939
arboard = "3.4"
40+
tabled = "0.20.0"
4041

4142
[[bin]]
4243
name = "aigitcommit"

src/cli.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414

1515
use clap::Parser;
16-
// Include the generated-file as a separate module
1716
mod built_info {
1817
include!(concat!(env!("OUT_DIR"), "/built.rs"));
1918
}
@@ -79,6 +78,14 @@ If not specified, the current directory will be used"#,
7978
)]
8079
pub copy: bool,
8180

81+
#[arg(
82+
long,
83+
help = "Print the commit message in a table format",
84+
default_value_t = true,
85+
required = false
86+
)]
87+
pub print_table: bool,
88+
8289
#[arg(
8390
long,
8491
short,
@@ -88,3 +95,35 @@ If not specified, the current directory will be used"#,
8895
)]
8996
pub save: String,
9097
}
98+
99+
pub fn print_table(title: &str, content: &str) {
100+
let mut binding =
101+
tabled::builder::Builder::from_iter([["Title", title.trim()], ["Content", content.trim()]])
102+
.build();
103+
let table = binding
104+
.with(tabled::settings::Style::rounded())
105+
.with(tabled::settings::Width::wrap(120))
106+
.with(tabled::settings::Alignment::left());
107+
108+
print!("{}\n", table);
109+
}
110+
111+
#[cfg(test)]
112+
mod tests {
113+
use super::*;
114+
115+
#[test]
116+
fn test_print_table() {
117+
const TITLE: &str = r#"feat: bump version to 1.4.0 and update system template 🚀"#;
118+
const CONTENT: &str = r#"
119+
- Update version from 1.3.3 to 1.4.0 in Cargo.toml
120+
- Enhance system template with additional instructions
121+
- Simplify and clarify template content for better usability
122+
- Remove redundant information to streamline template
123+
- Ensure template aligns with latest commit message standards
124+
125+
Signed-off-by: mingcheng <[email protected]>
126+
"#;
127+
print_table(TITLE, CONTENT);
128+
}
129+
}

0 commit comments

Comments
 (0)