def set_dummy_app(): """ Return a context manager that makes sure that this dummy application is active. This is important, because we need an `Application` with `is_done=False` flag, otherwise no keys will be processed. """ app = Application(layout=Layout(Window()), output=DummyOutput(), input=create_pipe_input()) return set_app(app)
def set_dummy_app(): """ Return a context manager that makes sure that this dummy application is active. This is important, because we need an `Application` with `is_done=False` flag, otherwise no keys will be processed. """ app = Application( layout=Layout(Window()), output=DummyOutput(), input=create_pipe_input()) return set_app(app)
def _run_command(self, packet): """ Execute a run command from the client. """ create_temp_cli = self.client_states is None if create_temp_cli: # If this client doesn't have a CLI. Create a Fake CLI where the # window containing this pane, is the active one. (The CLI instance # will be removed before the render function is called, so it doesn't # hurt too much and makes the code easier.) pane_id = int(packet['pane_id']) self._create_app() with set_app(self.client_state.app): self.pymux.arrangement.set_active_window_from_pane_id(pane_id) with set_app(self.client_state.app): try: self.pymux.handle_command(packet['data']) finally: self._close_connection()
def remove_pane(self, pane): """ Remove a :class:`.Pane`. (Look in all windows.) """ assert isinstance(pane, Pane) for w in self.windows: w.remove_pane(pane) # No panes left in this window? if not w.has_panes: # Focus next. for app, active_w in self._active_window_for_cli.items(): if w == active_w: with set_app(app): self.focus_next_window() self.windows.remove(w)
def remove_pane(self, pane): """ Remove a :class:`.Pane`. (Look in all windows.) """ assert isinstance(pane, Pane) for w in self.windows: w.remove_pane(pane) # No panes left in this window? if not w.has_panes: # Focus next. for app, active_w in self._active_window_for_cli.items(): if w == active_w: with set_app(app): self.focus_next_window() self.windows.remove(w)
def active_window_for_app(app): with set_app(app): return self.arrangement.get_active_window()
def _create_app(self): """ Create `Application` instance for this . """ pymux = self.pymux def on_focus_changed(): """ When the focus changes to a read/write buffer, make sure to go to insert mode. This happens when the ViState was set to NAVIGATION in the copy buffer. """ vi_state = app.vi_state if app.current_buffer.read_only(): vi_state.input_mode = InputMode.NAVIGATION else: vi_state.input_mode = InputMode.INSERT app = Application( output=self.output, input=self.input, color_depth=self.color_depth, layout=Layout(container=self.layout_manager.layout), key_bindings=pymux.key_bindings_manager.key_bindings, mouse_support=Condition(lambda: pymux.enable_mouse_support), full_screen=True, style=self.pymux.style, on_invalidate=(lambda _: pymux.invalidate())) # Synchronize the Vi state with the CLI object. # (This is stored in the current class, but expected to be in the # CommandLineInterface.) def sync_vi_state(_): VI = EditingMode.VI EMACS = EditingMode.EMACS if self.confirm_text or self.prompt_command or self.command_mode: app.editing_mode = VI if pymux.status_keys_vi_mode else EMACS else: app.editing_mode = VI if pymux.mode_keys_vi_mode else EMACS app.key_processor.before_key_press += sync_vi_state app.key_processor.after_key_press += sync_vi_state app.key_processor.after_key_press += self.sync_focus # Set render postpone time. (.1 instead of 0). # This small change ensures that if for a split second a process # outputs a lot of information, we don't give the highest priority to # rendering output. (Nobody reads that fast in real-time.) app.max_render_postpone_time = .1 # Second. # Hide message when a key has been pressed. def key_pressed(_): self.message = None app.key_processor.before_key_press += key_pressed # The following code needs to run with the application active. # Especially, `create_window` needs to know what the current # application is, in order to focus the new pane. with set_app(app): # Redraw all CLIs. (Adding a new client could mean that the others # change size, so everything has to be redrawn.) pymux.invalidate() pymux.startup() return app
def active_window_for_app(app): with set_app(app): return self.arrangement.get_active_window()
def _create_app(self): """ Create `Application` instance for this . """ pymux = self.pymux def on_focus_changed(): """ When the focus changes to a read/write buffer, make sure to go to insert mode. This happens when the ViState was set to NAVIGATION in the copy buffer. """ vi_state = app.vi_state if app.current_buffer.read_only(): vi_state.input_mode = InputMode.NAVIGATION else: vi_state.input_mode = InputMode.INSERT app = Application( output=self.output, input=self.input, color_depth=self.color_depth, layout=Layout(container=self.layout_manager.layout), key_bindings=pymux.key_bindings_manager.key_bindings, mouse_support=Condition(lambda: pymux.enable_mouse_support), full_screen=True, style=self.pymux.style, style_transformation=ConditionalStyleTransformation( SwapLightAndDarkStyleTransformation(), Condition(lambda: self.pymux.swap_dark_and_light), ), on_invalidate=(lambda _: pymux.invalidate())) # Synchronize the Vi state with the CLI object. # (This is stored in the current class, but expected to be in the # CommandLineInterface.) def sync_vi_state(_): VI = EditingMode.VI EMACS = EditingMode.EMACS if self.confirm_text or self.prompt_command or self.command_mode: app.editing_mode = VI if pymux.status_keys_vi_mode else EMACS else: app.editing_mode = VI if pymux.mode_keys_vi_mode else EMACS app.key_processor.before_key_press += sync_vi_state app.key_processor.after_key_press += sync_vi_state app.key_processor.after_key_press += self.sync_focus # Set render postpone time. (.1 instead of 0). # This small change ensures that if for a split second a process # outputs a lot of information, we don't give the highest priority to # rendering output. (Nobody reads that fast in real-time.) app.max_render_postpone_time = .1 # Second. # Hide message when a key has been pressed. def key_pressed(_): self.message = None app.key_processor.before_key_press += key_pressed # The following code needs to run with the application active. # Especially, `create_window` needs to know what the current # application is, in order to focus the new pane. with set_app(app): # Redraw all CLIs. (Adding a new client could mean that the others # change size, so everything has to be redrawn.) pymux.invalidate() pymux.startup() return app