36
36
)
37
37
from zulipterminal .config .ui_sizes import LEFT_WIDTH
38
38
from zulipterminal .helper import (
39
+ SearchStatus ,
39
40
TidiedUserInfo ,
40
41
asynch ,
41
42
match_emoji ,
@@ -335,7 +336,7 @@ def __init__(self, streams_btn_list: List[Any], view: Any) -> None:
335
336
),
336
337
)
337
338
self .search_lock = threading .Lock ()
338
- self .empty_search = False
339
+ self .search_status = SearchStatus . DEFAULT
339
340
340
341
@asynch
341
342
def update_streams (self , search_box : Any , new_text : str ) -> None :
@@ -352,7 +353,11 @@ def update_streams(self, search_box: Any, new_text: str) -> None:
352
353
)[0 ]
353
354
354
355
streams_display_num = len (streams_display )
355
- self .empty_search = streams_display_num == 0
356
+ self .search_status = (
357
+ SearchStatus .EMPTY
358
+ if streams_display_num == 0
359
+ else SearchStatus .FILTERED
360
+ )
356
361
357
362
# Add a divider to separate pinned streams from the rest.
358
363
pinned_stream_names = [
@@ -371,7 +376,7 @@ def update_streams(self, search_box: Any, new_text: str) -> None:
371
376
streams_display .insert (first_unpinned_index , StreamsViewDivider ())
372
377
373
378
self .log .clear ()
374
- if not self .empty_search :
379
+ if self .search_status == SearchStatus . FILTERED :
375
380
self .log .extend (streams_display )
376
381
else :
377
382
self .log .extend ([self .stream_search_box .search_error ])
@@ -404,6 +409,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
404
409
self .log .extend (self .streams_btn_list )
405
410
self .set_focus ("body" )
406
411
self .log .set_focus (self .focus_index_before_search )
412
+ self .search_status = SearchStatus .DEFAULT
407
413
self .view .controller .update_screen ()
408
414
return key
409
415
return super ().keypress (size , key )
@@ -436,7 +442,7 @@ def __init__(
436
442
header = self .header_list ,
437
443
)
438
444
self .search_lock = threading .Lock ()
439
- self .empty_search = False
445
+ self .search_status = SearchStatus . DEFAULT
440
446
441
447
def _focus_position_for_topic_name (self ) -> int :
442
448
saved_topic_state = self .view .saved_topic_in_stream_id (
@@ -461,10 +467,14 @@ def update_topics(self, search_box: Any, new_text: str) -> None:
461
467
for topic in self .topics_btn_list .copy ()
462
468
if new_text in topic .topic_name .lower ()
463
469
]
464
- self .empty_search = len (topics_to_display ) == 0
470
+ self .search_status = (
471
+ SearchStatus .EMPTY
472
+ if len (topics_to_display ) == 0
473
+ else SearchStatus .FILTERED
474
+ )
465
475
466
476
self .log .clear ()
467
- if not self .empty_search :
477
+ if self .search_status == SearchStatus . FILTERED :
468
478
self .log .extend (topics_to_display )
469
479
else :
470
480
self .log .extend ([self .topic_search_box .search_error ])
@@ -524,6 +534,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
524
534
self .log .extend (self .topics_btn_list )
525
535
self .set_focus ("body" )
526
536
self .log .set_focus (self .focus_index_before_search )
537
+ self .search_status = SearchStatus .DEFAULT
527
538
self .view .controller .update_screen ()
528
539
return key
529
540
return super ().keypress (size , key )
@@ -665,7 +676,7 @@ def __init__(self, view: Any) -> None:
665
676
666
677
self .allow_update_user_list = True
667
678
self .search_lock = threading .Lock ()
668
- self .empty_search = False
679
+ self .search_status = SearchStatus . DEFAULT
669
680
super ().__init__ (self .users_view (), header = search_box )
670
681
671
682
@asynch
@@ -706,10 +717,12 @@ def update_user_list(
706
717
else :
707
718
users_display = users
708
719
709
- self .empty_search = len (users_display ) == 0
720
+ self .search_status = (
721
+ SearchStatus .EMPTY if len (users_display ) == 0 else SearchStatus .FILTERED
722
+ )
710
723
711
724
# FIXME Update log directly?
712
- if not self .empty_search :
725
+ if self .search_status != SearchStatus . EMPTY :
713
726
self .body = self .users_view (users_display )
714
727
else :
715
728
self .body = UsersView (
@@ -765,6 +778,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
765
778
self .body = UsersView (self .view .controller , self .users_btn_list )
766
779
self .set_body (self .body )
767
780
self .set_focus ("body" )
781
+ self .search_status = SearchStatus .DEFAULT
768
782
self .view .controller .update_screen ()
769
783
return key
770
784
elif is_command_key ("GO_LEFT" , key ):
@@ -2007,7 +2021,7 @@ def __init__(
2007
2021
search_box = urwid .Pile (
2008
2022
[self .emoji_search , urwid .Divider (SECTION_DIVIDER_LINE )]
2009
2023
)
2010
- self .empty_search = False
2024
+ self .search_status = SearchStatus . DEFAULT
2011
2025
self .search_lock = threading .Lock ()
2012
2026
super ().__init__ (
2013
2027
controller ,
@@ -2053,10 +2067,14 @@ def update_emoji_list(
2053
2067
else :
2054
2068
self .emojis_display = self .emoji_buttons
2055
2069
2056
- self .empty_search = len (self .emojis_display ) == 0
2070
+ self .search_status = (
2071
+ SearchStatus .EMPTY
2072
+ if len (self .emojis_display ) == 0
2073
+ else SearchStatus .FILTERED
2074
+ )
2057
2075
2058
2076
body_content = self .emojis_display
2059
- if self .empty_search :
2077
+ if self .search_status == SearchStatus . EMPTY :
2060
2078
body_content = [self .emoji_search .search_error ]
2061
2079
2062
2080
self .contents ["body" ] = (
@@ -2130,5 +2148,6 @@ def keypress(self, size: urwid_Size, key: str) -> str:
2130
2148
self .emoji_search .reset_search_text ()
2131
2149
self .controller .exit_editor_mode ()
2132
2150
self .controller .exit_popup ()
2151
+ self .search_status = SearchStatus .DEFAULT
2133
2152
return key
2134
2153
return super ().keypress (size , key )
0 commit comments