@@ -10,13 +10,13 @@ import (
1010type logsTableModel struct {
1111 helper
1212
13- table table. Model
13+ lazyTable lazyTableModel [source. LazyLogEntry ]
1414 lastWindowSize tea.WindowSizeMsg
1515
16- logEntries source.LogEntries
16+ logEntries source.LazyLogEntries
1717}
1818
19- func newLogsTableModel (application Application , logEntries source.LogEntries ) logsTableModel {
19+ func newLogsTableModel (application Application , logEntries source.LazyLogEntries ) logsTableModel {
2020 helper := helper {Application : application }
2121
2222 const cellIDLogLevel = 1
@@ -28,7 +28,6 @@ func newLogsTableModel(application Application, logEntries source.LogEntries) lo
2828 )
2929
3030 tableLogs .SetStyles (getTableStyles ())
31- tableLogs .SetRows (logEntries .Rows ())
3231
3332 tableStyles := getTableStyles ()
3433 tableStyles .RenderCell = func (_ table.Model , value string , position table.CellPosition ) string {
@@ -49,21 +48,30 @@ func newLogsTableModel(application Application, logEntries source.LogEntries) lo
4948
5049 tableLogs .SetStyles (tableStyles )
5150
51+ lazyTable := lazyTableModel [source.LazyLogEntry ]{
52+ helper : helper ,
53+ table : tableLogs ,
54+ minRenderedRows : application .Config .PrerenderRows ,
55+ allEntries : logEntries ,
56+ lastCursor : 0 ,
57+ renderedRows : make ([]table.Row , 0 , application .Config .PrerenderRows * 2 ),
58+ }.withRenderedRows ()
59+
5260 return logsTableModel {
5361 helper : helper ,
54- table : tableLogs ,
62+ lazyTable : lazyTable ,
5563 logEntries : logEntries ,
5664 }.handleWindowSizeMsg (application .LastWindowSize )
5765}
5866
5967// Init initializes component. It implements tea.Model.
6068func (m logsTableModel ) Init () tea.Cmd {
61- return nil
69+ return m . lazyTable . Init ()
6270}
6371
6472// View renders component. It implements tea.Model.
6573func (m logsTableModel ) View () string {
66- return m .table .View ()
74+ return m .lazyTable .View ()
6775}
6876
6977// Update handles events. It implements tea.Model.
@@ -76,7 +84,7 @@ func (m logsTableModel) Update(msg tea.Msg) (logsTableModel, tea.Cmd) {
7684 m = m .handleWindowSizeMsg (msg )
7785 }
7886
79- m .table , cmdBatch = batched (m .table .Update (msg ))(cmdBatch )
87+ m .lazyTable , cmdBatch = batched (m .lazyTable .Update (msg ))(cmdBatch )
8088
8189 return m , tea .Batch (cmdBatch ... )
8290}
@@ -85,15 +93,15 @@ func (m logsTableModel) handleWindowSizeMsg(msg tea.WindowSizeMsg) logsTableMode
8593 const heightOffset = 4
8694
8795 x , y := m .BaseStyle .GetFrameSize ()
88- m .table .SetWidth (msg .Width - x * 2 )
89- m .table .SetHeight (msg .Height - y * 2 - footerSize - heightOffset )
90- m .table .SetColumns (getColumns (m .table .Width ()- 10 , m .Config ))
96+ m .lazyTable . table .SetWidth (msg .Width - x * 2 )
97+ m .lazyTable . table .SetHeight (msg .Height - y * 2 - footerSize - heightOffset )
98+ m .lazyTable . table .SetColumns (getColumns (m . lazyTable .table .Width ()- 10 , m .Config ))
9199 m .lastWindowSize = msg
92100
93101 return m
94102}
95103
96104// Cursor returns the index of the selected row.
97105func (m logsTableModel ) Cursor () int {
98- return m .table .Cursor ()
106+ return m .lazyTable . table .Cursor ()
99107}
0 commit comments