@@ -36,31 +36,16 @@ func generateRows(path string, file fs.FileInfo) *[]table.Row {
3636 return & rows
3737}
3838
39- func NewList (path string ) listVariables {
39+ func NewList () listVariables {
4040 columns := []table.Column {
4141 {Title : "FileName" , Width : int (0.2 * float64 (width ))},
4242 {Title : "Lang" , Width : int (0.1 * float64 (width ))},
4343 {Title : "Id" , Width : int (0.05 * float64 (width ))},
4444 {Title : "Value" , Width : int (0.55 * float64 (width ))},
4545 }
46- rows := []table.Row {}
47- filepath .WalkDir (path , func (path string , file fs.DirEntry , err error ) error {
48- if err != nil {
49- return err
50- }
51- ext := filepath .Ext (file .Name ())
52- if ! file .IsDir () && strings .ToLower (ext ) == ".tra" {
53- info , _ := file .Info ()
54- file_rows := * generateRows (path , info )
55- rows = append (rows , file_rows ... )
56- }
57-
58- return nil
59- })
6046
6147 t := table .New (
6248 table .WithColumns (columns ),
63- table .WithRows (rows ),
6449 table .WithFocused (true ),
6550 table .WithHeight (height - 7 ),
6651 )
@@ -81,11 +66,32 @@ func NewList(path string) listVariables {
8166 return listVariables {table : t }
8267}
8368
69+ func (l listVariables ) readPath (path string ) * []table.Row {
70+ rows := []table.Row {}
71+ filepath .WalkDir (path , func (path string , file fs.DirEntry , err error ) error {
72+ if err != nil {
73+ return err
74+ }
75+ ext := filepath .Ext (file .Name ())
76+ if ! file .IsDir () && strings .ToLower (ext ) == ".tra" {
77+ info , _ := file .Info ()
78+ file_rows := * generateRows (path , info )
79+ rows = append (rows , file_rows ... )
80+ }
81+
82+ return nil
83+ })
84+ return & rows
85+ }
86+
8487func (l listVariables ) Init () tea.Cmd { return nil }
8588
8689func (l listVariables ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
87- var cmd tea.Cmd
8890 switch msg := msg .(type ) {
91+ case SelectedFilePath :
92+ rows := l .readPath (string (msg ))
93+ l .table .SetRows (* rows )
94+ return l , nil
8995 case tea.WindowSizeMsg :
9096 h , w := docStyle .GetFrameSize ()
9197 h1 , w1 := baseStyle .GetFrameSize ()
@@ -106,13 +112,9 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
106112 }
107113 case tea.KeyMsg :
108114 switch msg .String () {
109- case "esc" :
110- if l .table .Focused () {
111- l .table .Blur ()
112- } else {
113- l .table .Focus ()
114- }
115- case "q" , "ctrl+c" , "ctrl+d" :
115+ case "q" , "esc" :
116+ return state .PreviousCommand (), nil
117+ case "ctrl+c" , "ctrl+d" :
116118 return l , tea .Quit
117119 case "enter" :
118120 content := ""
@@ -128,12 +130,11 @@ func (l listVariables) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
128130 content += s
129131 }
130132 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 ()
133+ state .setCurrentCommand (l )
134+ return state .NextCommand (), tea .Batch (sendTitleCmd (title ), sendContentCmd (content ))
135135 }
136136 }
137+ var cmd tea.Cmd
137138 l .table , cmd = l .table .Update (msg )
138139 return l , cmd
139140}
0 commit comments