Add VimspectorToggleLog

This commit is contained in:
Ben Jackson 2020-08-27 18:09:48 +01:00
commit 51cc6c4d3a
6 changed files with 56 additions and 3 deletions

View file

@ -55,6 +55,7 @@ class DebugSession( object ):
install.GetGadgetDir( VIMSPECTOR_HOME ) )
self._uiTab = None
self._logView = None
self._stackTraceView = None
self._variablesView = None
self._outputView = None
@ -332,12 +333,15 @@ class DebugSession( object ):
return wrapper
return decorator
def _HasUI( self ):
return self._uiTab and self._uiTab.valid
def RequiresUI( otherwise=None ):
"""Decorator, call fct if self._connected else echo warning"""
def decorator( fct ):
@functools.wraps( fct )
def wrapper( self, *args, **kwargs ):
if not self._uiTab or not self._uiTab.valid:
if not self._HasUI():
utils.UserMessage(
'Vimspector is not active',
persist=False,
@ -492,6 +496,26 @@ class DebugSession( object ):
def ExpandFrameOrThread( self ):
self._stackTraceView.ExpandFrameOrThread()
def ToggleLog( self ):
if self._HasUI():
return self.ShowOutput( 'Vimspector' )
if self._logView and self._logView.WindowIsValid():
self._logView.Reset()
self._logView = None
return
if self._logView:
self._logView.Reset()
# TODO: The UI code is too scattered. Re-organise into a UI class that
# just deals with these thigns like window layout and custmisattion.
vim.command( f'botright { settings.Int( "bottombar_height", 10 ) }new' )
win = vim.current.window
self._logView = output.OutputView( win, self._api_prefix )
self._logView.AddLogFileView()
self._logView.ShowOutput( 'Vimspector' )
@RequiresUI()
def ShowOutput( self, category ):
if not self._outputView.WindowIsValid():

View file

@ -187,7 +187,6 @@ class OutputView( object ):
syntax,
self._buffers[ category ].buf )
def _RenderWinBar( self, category ):
if not self._window.valid:
return
@ -216,6 +215,9 @@ class OutputView( object ):
def GetCategories( self ):
return list( self._buffers.keys() )
def AddLogFileView( self, file_name = utils.LOG_FILE ):
self._CreateBuffer( 'Vimspector', file_name = file_name )
class DAPOutputView( OutputView ):
"""Specialised OutputView which adds the DAP Console (REPL)"""
@ -226,7 +228,7 @@ class DAPOutputView( OutputView ):
for b in set( BUFFER_MAP.values() ):
self._CreateBuffer( b )
self._CreateBuffer( 'Vimspector', file_name = utils.LOG_FILE )
self.AddLogFileView()
self._ShowOutput( 'Console' )
def ConnectionUp( self, connection ):