1+ use std:: path:: Path ;
2+
13use anyhow:: Result ;
24use chrono:: { DateTime , Local , Utc } ;
3- use tabled:: { Table , Tabled } ;
5+ use crossterm:: terminal;
6+ use tabled:: {
7+ settings:: { peaker:: PriorityMax , Width } ,
8+ Table , Tabled ,
9+ } ;
410
511use crate :: projects:: ProjectStore ;
612
@@ -18,6 +24,15 @@ struct ProjectRow {
1824 status : String ,
1925}
2026
27+ fn shorten_path ( path : & Path ) -> String {
28+ if let Some ( home) = dirs:: home_dir ( ) {
29+ if let Ok ( stripped) = path. strip_prefix ( & home) {
30+ return format ! ( "~/{}" , stripped. display( ) ) ;
31+ }
32+ }
33+ path. display ( ) . to_string ( )
34+ }
35+
2136pub fn run ( ) -> Result < ( ) > {
2237 let store = ProjectStore :: load ( ) ?;
2338
@@ -36,7 +51,7 @@ pub fn run() -> Result<()> {
3651 . unwrap_or_else ( || "Unknown" . to_string ( ) ) ;
3752
3853 ProjectRow {
39- path : p. path . display ( ) . to_string ( ) ,
54+ path : shorten_path ( & p. path ) ,
4055 tags : p. tags . join ( ", " ) ,
4156 access_count : p. access_count ,
4257 last_accessed : dt,
@@ -49,7 +64,16 @@ pub fn run() -> Result<()> {
4964 } )
5065 . collect ( ) ;
5166
52- let table = Table :: new ( rows) . to_string ( ) ;
67+ let mut table = Table :: new ( rows) ;
68+
69+ if let Ok ( ( width, _) ) = terminal:: size ( ) {
70+ table. with (
71+ Width :: truncate ( width as usize )
72+ . suffix ( ".." )
73+ . priority ( PriorityMax :: right ( ) ) ,
74+ ) ;
75+ }
76+
5377 println ! ( "{}" , table) ;
5478
5579 Ok ( ( ) )
0 commit comments