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 ):
@@ -2027,7 +2041,7 @@ def __init__(
2027
2041
search_box = urwid .Pile (
2028
2042
[self .emoji_search , urwid .Divider (SECTION_DIVIDER_LINE )]
2029
2043
)
2030
- self .empty_search = False
2044
+ self .search_status = SearchStatus . DEFAULT
2031
2045
self .search_lock = threading .Lock ()
2032
2046
super ().__init__ (
2033
2047
controller ,
@@ -2073,10 +2087,14 @@ def update_emoji_list(
2073
2087
else :
2074
2088
self .emojis_display = self .emoji_buttons
2075
2089
2076
- self .empty_search = len (self .emojis_display ) == 0
2090
+ self .search_status = (
2091
+ SearchStatus .EMPTY
2092
+ if len (self .emojis_display ) == 0
2093
+ else SearchStatus .FILTERED
2094
+ )
2077
2095
2078
2096
body_content = self .emojis_display
2079
- if self .empty_search :
2097
+ if self .search_status == SearchStatus . EMPTY :
2080
2098
body_content = [self .emoji_search .search_error ]
2081
2099
2082
2100
self .contents ["body" ] = (
@@ -2150,5 +2168,6 @@ def keypress(self, size: urwid_Size, key: str) -> str:
2150
2168
self .emoji_search .reset_search_text ()
2151
2169
self .controller .exit_editor_mode ()
2152
2170
self .controller .exit_popup ()
2171
+ self .search_status = SearchStatus .DEFAULT
2153
2172
return key
2154
2173
return super ().keypress (size , key )
0 commit comments