11"""Bridge for connecting a UI instance to nvim."""
22import sys
3+ import os
34from threading import Semaphore , Thread
45from traceback import format_exc
6+ from inspect import signature
57
68
79class UIBridge (object ):
@@ -20,6 +22,7 @@ def connect(self, nvim, ui, profile=None, notify=False):
2022 self ._ui = ui
2123 self ._profile = profile
2224 self ._sem = Semaphore (0 )
25+ self .debug_events = len (os .environ .get ("NVIM_PYTHON_UI_DEBUG" , "" )) > 0
2326 t = Thread (target = self ._nvim_event_loop )
2427 t .daemon = True
2528 t .start ()
@@ -42,9 +45,9 @@ def resize(self, columns, rows):
4245 """Send a resize request to nvim."""
4346 self ._call (self ._nvim .ui_try_resize , columns , rows )
4447
45- def attach (self , columns , rows , rgb ):
48+ def attach (self , columns , rows , ** options ):
4649 """Attach the UI to nvim."""
47- self ._call (self ._nvim .ui_attach , columns , rows , rgb )
50+ self ._call (self ._nvim .api . ui_attach , columns , rows , options )
4851
4952 def detach (self ):
5053 """Detach the UI from nvim."""
@@ -90,12 +93,17 @@ def apply_updates():
9093 # print >> sys.stderr, update[0], ' '.join(l)
9194 try :
9295 handler = getattr (self ._ui , '_nvim_' + update [0 ])
96+ nparam = len (signature (handler ).parameters )
97+
9398 except AttributeError :
94- pass
99+ if self .debug_events :
100+ print (repr (update ), file = sys .stderr )
95101 else :
102+ if self .debug_events and len (update [1 ]) > nparam :
103+ print (repr (update ), file = sys .stderr )
96104 for args in update [1 :]:
97- handler (* args )
98- except :
105+ handler (* args [: nparam ] )
106+ except Exception :
99107 self ._error = format_exc ()
100108 self ._call (self ._nvim .quit )
101109 if method == 'redraw' :
0 commit comments