Skip to content

Commit

Permalink
[sidebar-] fix open-sidebar: open a new sheet with current sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
anjakefala committed Nov 1, 2023
1 parent 541b2d8 commit f763802
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions visidata/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@BaseSheet.property
def sidebar(sheet):
def default_sidebar(sheet):
'Default to format options.disp_sidebar_fmt. Overridable.'
fmt = sheet.options.disp_sidebar_fmt
return sheet.formatString(fmt)
Expand All @@ -25,7 +25,7 @@ def drawSidebar(vd, scr, sheet):
overflowmsg = '[:reverse] Ctrl+P to view all status messages [/]'
try:
if not sidebar and sheet.options.disp_sidebar:
sidebar = sheet.sidebar
sidebar = sheet.default_sidebar
if not sidebar and sheet.options.disp_help > 0:
sidebar = sheet.formatString(sheet.help)

Expand All @@ -39,7 +39,9 @@ def drawSidebar(vd, scr, sheet):
vd.exceptionCaught(e)
sidebar = f'# error\n{e}'

return sheet.drawSidebarText(scr, text=sidebar, overflowmsg=overflowmsg, bottommsg=bottommsg)
sheet.current_sidebar = sidebar

return sheet.drawSidebarText(scr, text=sheet.current_sidebar, overflowmsg=overflowmsg, bottommsg=bottommsg)

@BaseSheet.api
def drawSidebarText(sheet, scr, text:Union[None,str,'HelpPane'], title:str='', overflowmsg:str='', bottommsg:str=''):
Expand Down Expand Up @@ -119,7 +121,7 @@ class SidebarSheet(TextSheet):
'''

BaseSheet.addCommand('b', 'sidebar-toggle', 'sheet.options.disp_sidebar = not sheet.options.disp_sidebar', 'toggle sidebar on/off')
BaseSheet.addCommand('gb', 'open-sidebar', 'vd.push(SidebarSheet(name, options.disp_sidebar_fmt, source=sidebar.splitlines()))', 'open sidebar in new sheet')
BaseSheet.addCommand('gb', 'open-sidebar', 'vd.push(SidebarSheet(name, options.disp_sidebar_fmt, source=sheet.current_sidebar.splitlines()))', 'open sidebar in new sheet')


vd.addMenuItems('''
Expand Down

0 comments on commit f763802

Please sign in to comment.