88from textual .widget import Widget
99from textual .widgets import Footer , Header , Input , Label , Static , Tree
1010
11- from alpacloud .promls .filter import MetricsTree , filter_any
11+ from alpacloud .promls .filter import MetricsTree , Predicate , filter_any , filter_ish , filter_name
1212from alpacloud .promls .metrics import Metric
1313from alpacloud .promls .util import paths_to_tree
1414
@@ -56,14 +56,17 @@ class PromlsVisApp(App):
5656
5757 BINDINGS = [
5858 Binding ("ctrl+f" , "find" , "find" , priority = True ),
59+ Binding ("ctrl+g" , "goto" , "goto" , priority = True ),
60+ Binding ("ctrl+z" , "fuzzy_find" , "fuzzy find" , priority = True ),
5961 Binding ("greater_than_sign" , "expand_all" , "Expand all" , show = False ),
6062 Binding ("less_than_sign" , "collapse_all" , "Collapse all" , show = False ),
6163 ]
6264
63- def __init__ (self , metrics : MetricsTree , query : str , * args , ** kwargs ):
65+ def __init__ (self , metrics : MetricsTree , query : str , predicate : Predicate , * args , ** kwargs ):
6466 super ().__init__ (* args , ** kwargs )
6567 self .metrics = metrics
6668 self .query = query
69+ self .predicate = predicate
6770
6871 def compose (self ) -> ComposeResult :
6972 yield Header ()
@@ -80,6 +83,16 @@ async def do_find(self, s: str):
8083 self .load_metrics (self .metrics )
8184
8285 async def action_find (self ) -> None :
86+ self .handle_find_mode_change (filter_any (re .compile (self .query )))
87+
88+ async def action_fuzzy_find (self ) -> None :
89+ self .handle_find_mode_change (filter_ish (self .query ))
90+
91+ async def action_goto (self ):
92+ self .handle_find_mode_change (filter_name (re .compile (self .query )))
93+
94+ def handle_find_mode_change (self , predicate : Predicate ):
95+ self .predicate = predicate
8396 findbox = self .query_one (FindBox )
8497 findbox .focus ()
8598
@@ -117,7 +130,7 @@ def load_metrics(self, metrics: MetricsTree):
117130 tree .clear ()
118131 root = tree .root
119132
120- filtered = metrics .filter (filter_any ( re . compile ( self .query )) )
133+ filtered = metrics .filter (self .predicate )
121134 self ._add_node (root , paths_to_tree (filtered .metrics , sep = "_" ))
122135
123136 root .expand_all ()
0 commit comments