@@ -17,18 +17,23 @@ var baseStyle = lipgloss.NewStyle().
1717 BorderForeground (lipgloss .Color ("240" ))
1818
1919type listVariables struct {
20- table table.Model
20+ heading []string
21+ table table.Model
2122}
2223
2324func generateRows (path string , file fs.FileInfo ) * []table.Row {
2425 rows := []table.Row {}
25- fileContent , err := util .ReadFileToString (path )
26+ fileContent , err := util .ReadFileToString (filepath . Join ( path , file . Name ()) )
2627 if err != nil {
2728 return & rows
2829 }
2930 variables , err := translation .FromFileContents (fileContent )
3031 if err == nil {
31- lang := filepath .Base (filepath .Dir (path ))
32+ lang_path := strings .Split (path , "/" )
33+ lang := ""
34+ if len (lang_path ) > 2 {
35+ lang = lang_path [len (lang_path )- 2 ]
36+ }
3237 for _ , v := range * variables {
3338 rows = append (rows , table.Row {file .Name (), lang , v .Identifier , v .Value })
3439 }
@@ -38,18 +43,18 @@ func generateRows(path string, file fs.FileInfo) *[]table.Row {
3843
3944func NewList (path string ) listVariables {
4045 columns := []table.Column {
41- {Title : "FileName" , Width : int ( 0.2 * float64 ( width )) },
42- {Title : "Lang" , Width : int ( 0.1 * float64 ( width )) },
43- {Title : "Id" , Width : int ( 0.05 * float64 ( width )) },
44- {Title : "Value" , Width : int ( 0.55 * float64 ( width )) },
46+ {Title : "FileName" , Width : 12 },
47+ {Title : "Lang" , Width : 8 },
48+ {Title : "Id" , Width : 4 },
49+ {Title : "Value" , Width : 40 },
4550 }
4651 rows := []table.Row {}
4752 filepath .WalkDir (path , func (path string , file fs.DirEntry , err error ) error {
4853 if err != nil {
4954 return err
5055 }
5156 ext := filepath .Ext (file .Name ())
52- if ! file .IsDir () && strings . ToLower ( ext ) == ".tra" {
57+ if ! file .IsDir () && ext == ".tra" {
5358 info , _ := file .Info ()
5459 file_rows := * generateRows (path , info )
5560 rows = append (rows , file_rows ... )
@@ -62,7 +67,7 @@ func NewList(path string) listVariables {
6267 table .WithColumns (columns ),
6368 table .WithRows (rows ),
6469 table .WithFocused (true ),
65- table .WithHeight (height - 7 ),
70+ table .WithHeight (7 ),
6671 )
6772
6873 s := table .DefaultStyles ()
@@ -86,24 +91,6 @@ func (l listVariables) Init() tea.Cmd { return nil }
8691func (l listVariables ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
8792 var cmd tea.Cmd
8893 switch msg := msg .(type ) {
89- case tea.WindowSizeMsg :
90- h , w := docStyle .GetFrameSize ()
91- h1 , w1 := baseStyle .GetFrameSize ()
92- h += h1
93- w += w1
94- if msg .Height > h {
95- l .table .SetHeight (msg .Height - h )
96- }
97- if msg .Width > w {
98- ratio := float64 (msg .Width - w )
99- l .table .SetColumns ([]table.Column {
100- {Title : "FileName" , Width : int (0.2 * ratio )},
101- {Title : "Lang" , Width : int (0.1 * ratio )},
102- {Title : "Id" , Width : int (0.05 * ratio )},
103- {Title : "Value" , Width : int (0.55 * ratio )},
104- })
105- l .table .SetWidth (int (ratio ))
106- }
10794 case tea.KeyMsg :
10895 switch msg .String () {
10996 case "esc" :
@@ -112,26 +99,19 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
11299 } else {
113100 l .table .Focus ()
114101 }
115- case "q" , "ctrl+c" , "ctrl+d" :
102+ case "q" , "ctrl+c" :
116103 return l , tea .Quit
117104 case "enter" :
118- content := ""
105+ l . heading = [] string { "" }
119106 counter := 0
120- for _ , s := range strings .Split (l .table .SelectedRow ()[3 ], " " ) {
107+ for _ , s := range strings .Split (l .table .SelectedRow ()[2 ], " " ) {
121108 counter += len (s )
122109 if counter >= 42 {
123- content += "\n "
110+ l . heading = append ( l . heading , "\n " )
124111 counter = 0
125- } else if strings .Trim (content , " " ) != "" {
126- content += " "
127112 }
128- content += s
113+ l . heading = append ( l . heading , s )
129114 }
130- title := strings .Join (l .table .SelectedRow ()[:3 ], " " )
131- f := NewFileView (content , title , func () (tea.Model , tea.Cmd ) {
132- return l , cmd
133- })
134- return f , f .Init ()
135115 }
136116 }
137117 l .table , cmd = l .table .Update (msg )
@@ -140,5 +120,12 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
140120
141121func (l listVariables ) View () string {
142122 body := []string {l .table .View (), "\n \n " , l .table .HelpView (), " enter" }
143- return baseStyle .Render (body ... )
123+ if len (l .heading ) == 0 {
124+ return baseStyle .Render (body ... )
125+ } else {
126+ payload := l .heading
127+ payload = append (payload , "\n " )
128+ payload = append (payload , body ... )
129+ return baseStyle .Render (payload ... )
130+ }
144131}
0 commit comments