Mark unread output with *; Show vimspector log in output view

This commit is contained in:
Ben Jackson 2019-02-04 15:04:21 +00:00
commit 463f7a8220
4 changed files with 129 additions and 37 deletions

View file

@ -19,6 +19,14 @@ import vim
import json
class TabBuffer( object ):
def __init__( self, buf, index ):
self.buf = buf
self.index = index
self.flag = False
self.job = None
BUFFER_MAP = {
'console': 'Console',
'stdout': 'Console',
@ -40,7 +48,11 @@ class OutputView( object ):
for b in set( BUFFER_MAP.values() ):
self._CreateBuffer( b )
self.ShowOutput( 'Console' )
self._CreateBuffer(
'Vimspector',
file_name = vim.eval( 'expand( "~/.vimspector.log" )' ) )
self._ShowOutput( 'Console' )
def ServerEcho( self, text ):
self._Print( 'server', text.splitlines() )
@ -58,15 +70,17 @@ class OutputView( object ):
if category not in self._buffers:
self._CreateBuffer( category )
buf = self._buffers[ category ]
buf = self._buffers[ category ].buf
with utils.ModifiableScratchBuffer( buf ):
utils.AppendToBuffer( buf, text_lines )
self._ToggleFlag( category, True )
# Scroll the buffer
with utils.RestoreCurrentWindow():
with utils.RestoreCurrentBuffer( self._window ):
self.ShowOutput( category )
vim.command( 'normal G' )
self._ShowOutput( category )
def ConnectionClosed( self ):
self._connection = None
@ -76,19 +90,28 @@ class OutputView( object ):
def Clear( self ):
for buf in self._buffers:
vim.command( 'bwipeout! {0}'.format( self._buffers[ buf ].name ) )
vim.command( 'bwipeout! {0}'.format( self._buffers[ buf ].buf.name ) )
if 'Vimspector' in self._buffers:
if self._buffers[ 'Vimspector' ].job is not None:
utils.TerminateJob( self._buffers[ 'Vimspector' ].job )
self._buffers.clear()
def ShowOutput( self, category ):
def _ShowOutput( self, category ):
vim.current.window = self._window
vim.command( 'bu {0}'.format( self._buffers[ category ].name ) )
vim.command( 'bu {0}'.format( self._buffers[ category ].buf.name ) )
vim.command( 'normal G' )
def ShowOutput( self, category ):
self._ToggleFlag( category, False )
self._ShowOutput( category )
def Evaluate( self, frame, expression ):
if not frame:
return
console = self._buffers[ 'Console' ]
console = self._buffers[ 'Console' ].buf
utils.AppendToBuffer( console, 'Evaluating: ' + expression )
def print_result( message ):
@ -110,24 +133,56 @@ class OutputView( object ):
}
} )
def _CreateBuffer( self, category ):
def _ToggleFlag( self, category, flag ):
if self._buffers[ category ].flag != flag:
self._buffers[ category ].flag = flag
with utils.RestoreCurrentWindow():
vim.current.window = self._window
self._RenderWinBar( category )
def _CreateBuffer( self, category, file_name = None ):
with utils.RestoreCurrentWindow():
vim.current.window = self._window
with utils.RestoreCurrentBuffer( self._window ):
vim.command( 'enew' )
self._buffers[ category ] = vim.current.buffer
if category == 'Console':
utils.SetUpPromptBuffer( self._buffers[ category ],
'vimspector.Console',
'> ',
'vimspector#EvaluateConsole',
hidden=True )
if file_name is not None:
tab_buffer = TabBuffer( utils.BufferForFile( file_name ),
len( self._buffers ) )
tab_buffer.job = utils.SetUpTailBuffer( tab_buffer.buf, file_name )
self._buffers[ category ] = tab_buffer
else:
utils.SetUpHiddenBuffer( self._buffers[ category ],
'vimspector.Output:{0}'.format( category ) )
vim.command( 'enew' )
tab_buffer = TabBuffer( vim.current.buffer, len( self._buffers ) )
self._buffers[ category ] = tab_buffer
if category == 'Console':
utils.SetUpPromptBuffer( tab_buffer.buf,
'vimspector.Console',
'> ',
'vimspector#EvaluateConsole',
hidden=True )
else:
utils.SetUpHiddenBuffer(
tab_buffer.buf,
'vimspector.Output:{0}'.format( category ) )
vim.command( "nnoremenu WinBar.{0} "
":call vimspector#ShowOutput( '{0}' )<CR>".format(
utils.Escape( category ) ) )
self._RenderWinBar( category )
def _RenderWinBar( self, category ):
tab_buffer = self._buffers[ category ]
try:
if tab_buffer.flag:
vim.command( 'nunmenu WinBar.{}'.format( utils.Escape( category ) ) )
else:
vim.command( 'nunmenu WinBar.{}*'.format( utils.Escape( category ) ) )
except vim.error as e:
# E329 means the menu doesn't exist; ignore that.
if 'E329' not in str( e ):
raise
vim.command( "nnoremenu 1.{0} WinBar.{1}{2} "
":call vimspector#ShowOutput( '{1}' )<CR>".format(
tab_buffer.index,
utils.Escape( category ),
'*' if tab_buffer.flag else '' ) )