Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[memory] shorten cells too wide to fit in prompt #2287

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions visidata/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,12 @@ def inputsingle(vd, prompt, record=True):
return v

@VisiData.api
def inputMultiple(vd, updater=lambda val: None, record=True, **kwargs):
'A simple form, where each input is an entry in `kwargs`, with the key being the key in the returned dict, and the value being a dictionary of kwargs to the singular input().'
def inputMultiple(vd, updater=lambda val: None, record=True, readonly_keys = (), **kwargs):
'''A simple form, where each input is an entry in `kwargs`, with
the key being the key in the returned dict, and the value being a
dictionary of kwargs to the singular input(). *readonly_keys* is
a tuple of keys in `kwargs`; for each key, its corresponding value
will be displayed as a field that cannot be tabbed into or edited.'''
sheet = vd.activeSheet
scr = sheet._scr

Expand All @@ -429,8 +433,8 @@ def inputMultiple(vd, updater=lambda val: None, record=True, **kwargs):
maxw = sheet.windowWidth//2
attr = colors.color_edit_unfocused

keys = list(kwargs.keys())
cur_input_key = keys[0]
editable_keys = [k for k in kwargs.keys() if k not in readonly_keys]
cur_input_key = editable_keys[0]

if scr:
scr.erase()
Expand Down Expand Up @@ -477,8 +481,8 @@ def _drawPrompt(val):
except ChangeInput as e:
input_kwargs['value'] = e.args[0]
offset = e.args[1]
i = keys.index(cur_input_key)
cur_input_key = keys[(i+offset)%len(keys)]
i = editable_keys.index(cur_input_key)
cur_input_key = editable_keys[(i+offset)%len(editable_keys)]

retargs = {}
lastargs = {}
Expand Down
15 changes: 14 additions & 1 deletion visidata/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ def memo(vd, name, col, row):
vd.memory[name] = col.getTypedValue(row)
vd.status('memo %s=%s' % (name, col.getDisplayValue(row)))

@Sheet.api
def memo_cell(sheet):
if not sheet.cursorCol or not sheet.cursorRow: return
value_params = dict(prompt='assign value: ', value=sheet.cursorDisplay)
name_params = dict(prompt='to memo name: ')
# edits to memo_value are blocked, to preserve its type #2287
inputs = vd.inputMultiple(memo_name=name_params,
memo_value=value_params,
readonly_keys=('memo_value',))
if not inputs['memo_name']:
vd.fail('memo name cannot be blank')
vd.memory[inputs['memo_name']] = sheet.cursorTypedValue
vd.status(f'memo {inputs["memo_name"]}={sheet.cursorDisplay}')

class MemorySheet(Sheet):
rowtype = 'memos' # rowdef: keys into vd.memory
Expand All @@ -32,4 +45,4 @@ def memosSheet(vd):


Sheet.addCommand('Alt+Shift+M', 'open-memos', 'vd.push(vd.memosSheet)', 'open the Memory Sheet')
Sheet.addCommand('Alt+m', 'memo-cell', r'vd.memory[input("assign \""+cursorCol.getDisplayValue(cursorRow)+"\" to: ")] = cursorCol.getTypedValue(cursorRow)', 'store value in current cell in Memory Sheet')
Sheet.addCommand('Alt+m', 'memo-cell', 'memo_cell()', 'store value in current cell in Memory Sheet')
1 change: 1 addition & 0 deletions visidata/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def isTestableCommand(longname, cmdlist):
'sheet': '',
'col': 'Units',
'row': '5',
'memo-cell': 'rise',
}

@pytest.mark.usefixtures('curses_setup')
Expand Down
Loading