Ejemplo n.º 1
0
 def __init__(self):
     self._vim = VimSupport()
     self._sessions = {}
     self._session_views = {}
     self._tabpage_view = TabpageView(self._vim)
     self._worker = _ThreadExecutor()
     self._last_focused_bufnr = None
Ejemplo n.º 2
0
 def test_show_message_focused(self):
     '''Test method `show_message` when the view is focused.'''
     vim = Mock()
     tpview = TabpageView(vim)
     view = SessionView(3, tpview, vim)
     view.focus()
     view.show_message('info', 'msg')
     tpview.draw()
     vim.set_bufname_lines.assert_called_once_with('/Messages/', ['msg'])
Ejemplo n.º 3
0
 def test_set_goals_focused(self):
     '''Test method `set_goals` when the view is focused.'''
     vim = Mock()
     goal1 = Mock()
     tpview = TabpageView(vim)
     view = SessionView(3, tpview, vim)
     view.focus()
     view.set_goals(goal1)
     tpview.draw()
     vim.set_bufname_lines.assert_any_call('/Goals/',
                                           goal1.tolines.return_value)
Ejemplo n.º 4
0
 def test_set_messages(self):
     '''Test method `set_messages`.'''
     msg1 = ('info', 'msg1\nmsg2')
     msg2 = ('error', 'msg3')
     vim = Mock()
     view = TabpageView(vim)
     view.show_message(*msg1)
     view.show_message(*msg2)
     view.draw()
     vim.set_bufname_lines.assert_called_once_with('/Messages/',
                                                   ['msg1', 'msg2', 'msg3'])
Ejemplo n.º 5
0
 def test_show_message_unfocused(self):
     '''Test method `show_message` when the view is unfocused.'''
     vim = Mock()
     tpview = TabpageView(vim)
     tpview.show_message('info', 'msg4')
     view = SessionView(3, tpview, vim)
     view.focus()
     view.show_message('info', 'msg1')
     view.show_message('info', 'msg2\nmsg3')
     tpview.draw()
     vim.set_bufname_lines.assert_any_call('/Messages/',
                                           ['msg1', 'msg2', 'msg3'])
Ejemplo n.º 6
0
 def test_set_goals_unfocused(self):
     '''Test method `set_goals` when the view is unfocused.'''
     vim = Mock()
     goal1 = Mock()
     goal1.tolines.side_effect = [['goal']]
     tpview = TabpageView(vim)
     view = SessionView(3, tpview, vim)
     view.set_goals(goal1)
     tpview.draw()
     vim.set_bufname_lines.assert_not_called()
     view.focus()
     tpview.draw()
     vim.set_bufname_lines.assert_any_call('/Goals/', ['goal'])
Ejemplo n.º 7
0
 def test_set_goals(self):
     '''Test method `set_goals`.'''
     goal1 = Mock()
     goal2 = Mock()
     vim = Mock()
     view = TabpageView(vim)
     view.set_goals(goal1)
     view.set_goals(goal2)
     view.draw()
     goal1.tolines.assert_not_called()
     goal2.tolines.assert_called_once()
     vim.set_bufname_lines.assert_called_once_with(
         '/Goals/', goal2.tolines.return_value)
Ejemplo n.º 8
0
class Plugin:
    '''The plugin entry point.'''
    def __init__(self):
        self._vim = VimSupport()
        self._sessions = {}
        self._session_views = {}
        self._tabpage_view = TabpageView(self._vim)
        self._worker = _ThreadExecutor()
        self._last_focused_bufnr = None

    @_catch_exception
    @_draw_views
    def new_session(self):
        '''Create a new session on the current buffer.'''
        buf = self._vim.get_buffer()
        bufnr = buf.number
        if bufnr in self._sessions:
            print('Already in a Coq session')
            return
        logger.debug('Create session on buffer: %s [%s]', buf.name, bufnr)
        session_view = SessionView(bufnr, self._tabpage_view, self._vim)
        session = Session(session_view, self._vim, self._worker)
        self._sessions[bufnr] = session
        self._session_views[bufnr] = session_view

    @_catch_exception
    @_draw_views
    @_in_session
    def close_session(self, session, buf):
        '''Close the session on the current buffer.'''
        logger.debug('Close session on buffer: %s [%s]', buf.name, buf.number)
        session.close()
        del self._sessions[buf.number]
        del self._session_views[buf.number]

    @_catch_exception
    @_draw_views
    @_in_session
    @_not_busy
    def forward_one(self, session, buf):  # pylint: disable=R0201
        '''Forward one sentence.'''
        logger.debug('Session [%s]: forward one', buf.name)
        session.forward_one()

    @_catch_exception
    @_draw_views
    @_in_session
    @_not_busy
    def backward_one(self, session, buf):  # pylint: disable=R0201
        '''Backward one sentence.'''
        logger.debug('Session [%s]: backward one', buf.name)
        session.backward_one()

    @_catch_exception
    @_draw_views
    @_in_session
    @_not_busy
    def to_cursor(self, session, buf):  # pylint: disable=R0201
        '''Run to cursor.'''
        logger.debug('Session [%s]: to cursor', buf.name)
        session.to_cursor()

    @_catch_exception
    @_draw_views
    def redraw_goals(self):
        '''Redraw the goals to the goal window.'''
        logger.debug('Redraw goals')
        self._tabpage_view.redraw_goals()

    @_catch_exception
    @_draw_views
    def redraw_messages(self):
        '''Redraw the messages to the message window.'''
        logger.debug('Redraw messages')
        self._tabpage_view.redraw_messages()

    @_catch_exception
    @_draw_views
    @_not_busy
    def process_feedbacks(self):
        '''Process the feedbacks received by each session.'''
        for session in self._sessions.values():
            session.process_feedbacks()

    @_catch_exception
    @_draw_views
    @_in_session
    def focus(self, _, buf):
        '''Focus a session.'''
        if buf.number == self._last_focused_bufnr:
            return
        logger.debug('Session [%s]: focus', buf.name)
        if self._last_focused_bufnr is not None:
            last_view = self._session_views[self._last_focused_bufnr]
            last_view.unfocus()
        self._last_focused_bufnr = buf.number
        cur_view = self._session_views[self._last_focused_bufnr]
        cur_view.focus()

    @_catch_exception
    @_draw_views
    @_in_session
    def set_active(self, _, buf):  # pylint: disable=R0201
        '''Set the session active in a window.'''
        logger.debug('Session [%s]: set window active', buf.name)
        view = self._session_views[buf.number]
        view.set_active()

    @_catch_exception
    @_draw_views
    @_in_session
    def set_inactive(self, _, buf):  # pylint: disable=R0201
        '''Set the session inactive in a window.'''
        logger.debug('Session [%s]: set window inactive', buf.name)
        view = self._session_views[buf.number]
        view.set_inactive()

    @_catch_exception
    @_draw_views
    def clear_messages(self):
        '''Clear the messages in the message window.'''
        logger.debug('Clear messages')
        self._tabpage_view.clear_messages()

    def cleanup(self):
        '''Cleanup the plugin.'''
        logger.debug('Plugin clean up')
        for session in self._sessions.values():
            session.close()
        for view in self._session_views.values():
            view.destroy()
        self._sessions.clear()
        self._session_views.clear()
        self._worker.shutdown()

    def do_draw_views(self):
        '''Draw the changes of the views to Vim.'''
        self._tabpage_view.draw()
        for view in self._session_views.values():
            view.draw()