Skip to content

Commit

Permalink
[input] smoother input help #2085 #1961
Browse files Browse the repository at this point in the history
- inputMultiple help fixed
- only display one help sidebar
- cycle through disp_help with Ctrl+G
  • Loading branch information
saulpw committed Oct 27, 2023
1 parent 41e92d1 commit 4b061f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
7 changes: 5 additions & 2 deletions visidata/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def find_nonword(s, a, b, incr):
a += incr
return min(max(a, 0), len(s))

disp_help = vd.options.disp_help
max_disp_help = disp_help = vd.options.disp_help
while True:
updater(v)
if disp_help > 0:
Expand Down Expand Up @@ -266,7 +266,7 @@ def find_nonword(s, a, b, incr):
elif ch == '^E' or ch == 'KEY_END': i = len(v)
elif ch == '^F' or ch == 'KEY_RIGHT': i += 1
elif ch == '^G':
disp_help = 2 if disp_help != 2 else 0
disp_help = (disp_help+1)%(max_disp_help+1)
vd.draw_all() #1971
continue # not considered a first keypress
elif ch in ('^H', 'KEY_BACKSPACE', '^?'): i -= 1; v = delchar(v, i)
Expand Down Expand Up @@ -392,6 +392,9 @@ def _throw(v, i):
keys = list(kwargs.keys())
cur_input_key = keys[0]

if sheet._scr:
sheet._scr.erase()

while True:
if sheet._scr:
vd.drawSheet(sheet._scr, sheet)
Expand Down
7 changes: 2 additions & 5 deletions visidata/mainloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def drawSheet(self, scr, sheet):

sheet._scr = scr


try:
sheet.draw(scr)
except Exception as e:
Expand All @@ -42,10 +41,6 @@ def drawSheet(self, scr, sheet):
self.drawLeftStatus(scr, sheet)
self.drawRightStatus(scr, sheet) # visible during this getkeystroke

self.drawSidebar(scr, sheet)




vd.windowConfig = dict(pct=0, n=0, h=0, w=0) # n=top line of bottom window; h=height of bottom window; w=width of screen

Expand Down Expand Up @@ -131,6 +126,8 @@ def draw_all(vd):
if vd.scrMenu:
vd.drawMenu(vd.scrMenu, vd.activeSheet)

vd.drawSidebar(vd.scrFull, vd.activeSheet)

if vd.win1:
vd.win1.refresh()
if vd.win2:
Expand Down
13 changes: 8 additions & 5 deletions visidata/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,28 @@ def findMatchingColumn(sheet, row, columns, func):
vd.status('%s matches for /%s/' % (matchingRowIndexes, regex.pattern))


regex_flags_help = '''# regex flags
help_regex_flags = '''# regex flags
- `A` (ASCII) ASCII-only matching (not unicode)
- `I` (IGNORECASE): case-insensitive matching
- `M` (MULTILINE): `^` and `$` match after/before newlines
- `S` (DOTALL): `.` match any character at all, including newline
- `X` (VERBOSE): allow verbose regex
'''

help_regex = 'regex help goes here'

@Sheet.api
def searchInputRegex(sheet, action:str, columns:str='cursorCol'):
r = vd.inputMultiple(regex=dict(prompt=f"{action} regex: ", type="regex", defaultLast=True, help='# regex help'),
flags=dict(prompt="regex flags: ", type="regex_flags", value=sheet.options.regex_flags, help=regex_flags_help))
r = vd.inputMultiple(regex=dict(prompt=f"{action} regex: ", type="regex", defaultLast=True, help=help_regex),
flags=dict(prompt="regex flags: ", type="regex_flags", value=sheet.options.regex_flags, help=help_regex_flags))

return vd.searchRegex(sheet, regex=r['regex'], regex_flags=r['flags'], columns=columns)

@Sheet.api
def moveInputRegex(sheet, action:str, type="regex", **kwargs):
r = vd.inputMultiple(regex=dict(prompt=f"{action} regex: ", type=type, defaultLast=True),
flags=dict(prompt="regex flags: ", type="regex_flags", value=sheet.options.regex_flags))
r = vd.inputMultiple(regex=dict(prompt=f"{action} regex: ", type=type, defaultLast=True, help=help_regex),
flags=dict(prompt="regex flags: ", type="regex_flags", value=sheet.options.regex_flags, help=help_regex_flags))

return vd.moveRegex(sheet, regex=r['regex'], regex_flags=r['flags'], **kwargs)

Expand Down

0 comments on commit 4b061f7

Please sign in to comment.