Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

New Guides API #2134

Merged
merged 11 commits into from
Nov 26, 2023
1 change: 1 addition & 0 deletions visidata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def getGlobals():
import visidata.textsheet
import visidata.threads
import visidata.path
import visidata.experimental.guide

import visidata._input
import visidata.tuiwin
Expand Down
22 changes: 19 additions & 3 deletions visidata/experimental/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@

import re

from visidata import vd, BaseSheet, Sheet, ItemColumn, Column, VisiData
from visidata import vd, BaseSheet, Sheet, ItemColumn, Column, VisiData, ENTER

vd.guides = {} # guidename -> guideobj

@VisiData.api
def addGuide(vd, guidename, guideobj):
vd.guides[guidename] = guideobj

@VisiData.api
class GuideGuide(Sheet):
help = __doc__
columns = [
ItemColumn('n', 0, type=int),
ItemColumn('sheetname', 1, width=0),
ItemColumn('guidename', 1, width=0),
ItemColumn('topic', 2, width=60),
Column('points', type=int, getter=lambda c,r: 0),
Column('max_points', type=int, getter=lambda c,r: 100),
Expand Down Expand Up @@ -86,4 +91,15 @@ def iterload(self):
yield [i] + list(m.groups())
i += 1

BaseSheet.addCommand('', 'open-guide', 'vd.push(GuideGuide("VisiData_Guide"))')
@VisiData.api
def getGuide(vd, guidename):
if guidename in vd.guides:
return vd.guides[guidename]
vd.warning(f'there is no guide: {guidename}')

BaseSheet.addCommand('', 'open-guide', 'vd.push(GuideGuide("VisiData_Guide"))', 'opens guide to features in VisiData')
GuideGuide.addCommand(ENTER, 'open-guide-row', 'vd.push(vd.getGuide(cursorRow[1]))')
anjakefala marked this conversation as resolved.
Show resolved Hide resolved

vd.addMenuItems('''
Help > Guide > open-guide
''')
27 changes: 25 additions & 2 deletions visidata/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from visidata.cmdlog import CommandLog, CommandLogJsonl
from visidata import vd, UNLOADED, asyncthread
from visidata import IndexSheet, VisiData, Sheet, Path, VisiDataMetaSheet, Column, ItemColumn, BaseSheet
from visidata import IndexSheet, VisiData, Sheet, Path, VisiDataMetaSheet, Column, ItemColumn, BaseSheet, TextSheet

vd.macroMode = None
vd.macrobindings = {}
Expand Down Expand Up @@ -125,15 +125,38 @@ def startMacro(cmdlog):
vd.status("recording macro; stop recording with `m`")
vd.macroMode = CommandLogJsonl('current_macro', rows=[])


@VisiData.before
def run(vd, *args, **kwargs):
vd.macrosheet

class MacrosGuide(TextSheet):
pass


Sheet.addCommand('m', 'macro-record', 'vd.cmdlog.startMacro()', 'record macro')
Sheet.addCommand('gm', 'macro-sheet', 'vd.push(vd.macrosheet)', 'open macros sheet')

vd.addMenuItems('''
System > Macros sheet > macro-sheet
''')

vd.addGuide('MacrosSheet', MacrosGuide(source = '''# Macros
Macros allow you to bind a series of commands to a key and then replay those commands within a session by using that keystroke.
anjakefala marked this conversation as resolved.
Show resolved Hide resolved

The basic usage is:
1. Press `m` (macro-record) to begin recording the macro.
2. Go through the commands you wish to record.
3. Then type `m` again to complete the recording, and prompt for the keystroke or longname to bind it to.

The macro will then be executed everytime the provided keystroke is used. Note: the Alt+keys and the function keys are left unbound; overridding other keys may conflict with existing bindings, now or in the future.

Executing a macro will the series of commands starting on the current row and column on the current sheet.

# The Macros Sheet

Use `gm` (`open-macros-or-whatever`) to open an index existing macros.

Macros can be marked for deletion (with `d`). Changes can then be committed with `z Ctrl+S`.

`Enter` will open the macro in the current row, and you can view the series of commands composing it.'''.splitlines()
) )
Loading