File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 99 "github.com/CosmicPredator/chibi/internal"
1010 "github.com/charmbracelet/lipgloss"
1111 "github.com/charmbracelet/lipgloss/table"
12+ "github.com/charmbracelet/x/term"
1213 "github.com/spf13/cobra"
1314)
1415
@@ -38,19 +39,30 @@ func getMediaSearch(searchQuery string) {
3839 })
3940 }
4041
42+ // get size of terminal
43+ tw , _ , err := term .GetSize ((os .Stdin .Fd ()))
44+ if err != nil {
45+ ErrorMessage (err .Error ())
46+ }
47+
4148 t := table .New ().
4249 Border (lipgloss .NormalBorder ()).
4350 BorderStyle (lipgloss .NewStyle ().Foreground (lipgloss .Color ("99" ))).
4451 StyleFunc (func (row , col int ) lipgloss.Style {
45- switch {
46- case row == - 1 :
52+ // style for table header row
53+ if row == - 1 {
4754 return lipgloss .NewStyle ().Foreground (lipgloss .Color ("99" )).Bold (true ).Align (lipgloss .Center )
48- default :
49- return lipgloss .NewStyle ().Align (lipgloss .Center ).PaddingLeft (2 ).PaddingRight (2 )
5055 }
56+
57+ // force title column to wrap by specifying terminal width
58+ if col == 1 {
59+ return lipgloss .NewStyle ().Align (lipgloss .Center ).PaddingLeft (2 ).PaddingRight (2 ).Width (tw )
60+ }
61+
62+ return lipgloss .NewStyle ().Align (lipgloss .Center ).PaddingLeft (2 ).PaddingRight (2 )
5163 }).
5264 Headers ("ID" , "TITLE" , "SCORE" ).
53- Rows (rows ... )
65+ Rows (rows ... ). Width ( tw )
5466
5567 fmt .Println (t )
5668}
You can’t perform that action at this time.
0 commit comments