@@ -12,7 +12,7 @@ const FIELDS = ['timestamp', 'level', 'message'];
1212
1313class MainPanel extends BaseWidget {
1414 constructor ( opts = { } ) {
15- super ( Object . assign ( { } , { handleKeys : true } , opts ) ) ;
15+ super ( Object . assign ( { } , { top : '0' , height : '99%' , handleKeys : true } , opts ) ) ;
1616
1717 this . currentPage = opts . currentPage || 1 ;
1818 this . initialRow = opts . initialRow || 0 ;
@@ -25,7 +25,8 @@ class MainPanel extends BaseWidget {
2525 this . lastSearchTerm = null ;
2626 this . levelFilter = opts . level ;
2727 this . filters = [ ] ;
28- this . sort = opts . sort || '-timestap' ;
28+ this . sort = opts . sort || '-timestamp' ;
29+ this . mode = 'normal' ;
2930
3031 this . log ( 'pageWidth' , this . pageWidth ) ;
3132 this . update ( ) ;
@@ -86,6 +87,7 @@ class MainPanel extends BaseWidget {
8687 }
8788
8889 renderLines ( ) {
90+ this . resetMode ( ) ;
8991 this . rows = this . lines . slice ( this . initialRow , this . initialRow + this . height - 2 ) ;
9092 this . update ( ) ;
9193 }
@@ -151,7 +153,7 @@ class MainPanel extends BaseWidget {
151153 return ;
152154 }
153155 if ( ch === 'f' ) {
154- if ( this . filters . length ) {
156+ if ( this . filters . length || this . levelFilter ) {
155157 return this . clearFilters ( ) ;
156158 }
157159 this . openFilter ( ) ;
@@ -186,8 +188,9 @@ class MainPanel extends BaseWidget {
186188 }
187189
188190 openSort ( ) {
191+ this . setMode ( 'sort' ) ;
189192 this . openPicker ( 'Sort by' , FIELDS , ( err , sort ) => {
190- if ( ! sort ) { return ; }
193+ if ( ! sort ) { return this . resetMode ( ) ; }
191194 if ( err ) { return ; }
192195 if ( this . sortKey === sort && this . sortAsc ) {
193196 return this . setSort ( `-${ sort } ` ) ;
@@ -196,11 +199,21 @@ class MainPanel extends BaseWidget {
196199 } ) ;
197200 }
198201
202+ setMode ( mode ) {
203+ this . log ( 'setmode' , mode ) ;
204+ this . mode = mode ;
205+ this . emit ( 'update' ) ;
206+ }
207+
208+ resetMode ( ) {
209+ this . setMode ( 'normal' ) ;
210+ }
211+
199212 openFilter ( ) {
213+ this . setMode ( 'filter' ) ;
200214 const fields = [ 'timestamp' , 'level' , 'message' , 'other' ] ;
201215 this . openPicker ( 'Filter by' , fields , ( err , field ) => {
202- if ( ! field ) { return ; }
203- if ( err ) { return ; }
216+ if ( err || ! field ) { return this . resetMode ( ) ; }
204217 if ( field === 'level' ) {
205218 return this . openLevelFilter ( ) ;
206219 }
@@ -213,7 +226,7 @@ class MainPanel extends BaseWidget {
213226
214227 openCustomFilter ( ) {
215228 this . prompt ( `Field to filter:` , '' , ( field ) => {
216- if ( ! field ) { return ; }
229+ if ( ! field ) { return this . resetMode ( ) ; }
217230 if ( field . indexOf ( ':' ) > - 1 ) {
218231 return this . setFilter ( field . split ( ':' ) [ 0 ] , field . split ( ':' ) [ 1 ] , 'contains' ) ;
219232 }
@@ -223,7 +236,7 @@ class MainPanel extends BaseWidget {
223236
224237 openFilterTerm ( field ) {
225238 this . prompt ( `Filter ${ field } by:` , '' , ( value ) => {
226- if ( ! value ) { return ; }
239+ if ( ! value ) { return this . resetMode ( ) ; }
227240 this . setFilter ( field , value , 'contains' ) ;
228241 } ) ;
229242 }
@@ -287,13 +300,15 @@ class MainPanel extends BaseWidget {
287300 }
288301
289302 openSearch ( clear = false ) {
303+ this . setMode ( 'search' ) ;
290304 if ( clear ) {
291305 this . lastSearchTerm = null ;
292306 }
293307 this . prompt ( 'Search:' , this . lastSearchTerm , ( value ) => this . search ( value ) ) ;
294308 }
295309
296310 openGoToLine ( ) {
311+ this . setMode ( 'GOTO' ) ;
297312 this . prompt ( 'Line:' , '' , ( value ) => this . moveToLine ( parseInt ( value , 10 ) - 1 ) ) ;
298313 }
299314
@@ -408,7 +423,7 @@ class MainPanel extends BaseWidget {
408423 this . setLabel ( `[{bold} ${ this . file } {/}] [{bold} ${ this . row + 1 } /${ this . lastRow + 1 } {/}]` ) ;
409424
410425 const columns = [
411- { title : 'Timestap ' , key : 'timestamp' } ,
426+ { title : 'Timestamp ' , key : 'timestamp' } ,
412427 { title : 'Level' , key : 'level' , format : v => levelColors [ v ] ( v ) } ,
413428 { title : 'D' , key : 'data' , length : 1 , format : v => _ . isEmpty ( v ) ? ' ' : '*' } ,
414429 { title : 'Message' , key : 'message' } ,
@@ -427,6 +442,8 @@ class MainPanel extends BaseWidget {
427442 const list = blessed . element ( { tags : true , content } ) ;
428443 this . append ( list ) ;
429444 this . screen . render ( ) ;
445+ this . log ( 'update...' , this . filters ) ;
446+ this . emit ( 'update' ) ;
430447 }
431448}
432449
0 commit comments