-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,601 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
sheet col row keystrokes input comment | ||
o sample_data/sample-sales-reps.xlsx open file | ||
sample-sales-reps キsample-salesv4 ^J load the entire table into memory | ||
sample-sales-reps_sample-salesv4 g^ set names of all visible columns to contents of selected rows (or current row) | ||
sample-sales-reps_sample-salesv4 0 d delete current row and move it to clipboard | ||
sheet col row longname input keystrokes comment | ||
open-file sample_data/sample-sales-reps.xlsx o | ||
sample-sales-reps キsample-salesv4 dive-row ^J |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sheet col row longname input keystrokes comment | ||
override header set-option 0 | ||
open-file sample_data/sample-sales-reps.xlsx o | ||
sample-sales-reps キsample-salesv4 dive-row ^J | ||
sample-sales-reps_sample-salesv4 0 rename-cols-row g^ | ||
sample-sales-reps_sample-salesv4 0 delete-row d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.Dd September 21, 2018 | ||
.Dd November 1, 2018 | ||
.Dt vd \&1 "Quick Reference Guide" | ||
.Os Linux/MacOS | ||
. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
# Just include this whole file in your project as-is. If you do make | ||
# modifications, please keep the base vdtui version and append your own id and | ||
# version. | ||
__version__ = '1.4' | ||
__version__ = '1.5' | ||
__version_info__ = 'saul.pw/vdtui v' + __version__ | ||
__author__ = 'Saul Pwanson <[email protected]>' | ||
__license__ = 'MIT' | ||
|
@@ -37,6 +37,7 @@ | |
import sys | ||
import os | ||
import collections | ||
from collections import defaultdict | ||
from copy import copy, deepcopy | ||
from contextlib import suppress | ||
import curses | ||
|
@@ -255,7 +256,7 @@ def replayableOption(optname, default, helpstr): | |
|
||
|
||
replayableOption('encoding', 'utf-8', 'encoding passed to codecs.open') | ||
replayableOption('encoding_errors', 'surrogateescape', 'encoding errors passed to codecs.open') | ||
replayableOption('encoding_errors', 'surrogateescape', 'encoding_errors passed to codecs.open') | ||
|
||
replayableOption('regex_flags', 'I', 'flags to pass to re.compile() [AILMSUX]') | ||
replayableOption('default_width', 20, 'default column width') | ||
|
@@ -561,6 +562,11 @@ def __init__(self): | |
self.prefixWaiting = False | ||
self.scr = None # curses scr | ||
self.hooks = collections.defaultdict(list) # [hookname] -> list(hooks) | ||
self.mousereg = defaultdict( # [scr] -> | ||
lambda: defaultdict( # [y] -> | ||
lambda: defaultdict( # [x] -> | ||
lambda: defaultdict( # [button] (like "BUTTON1_CLICKED") -> | ||
lambda: None)))) # func(y, x, button) | ||
self.threads = [] # all long-running threads, including main and finished | ||
self.addThread(threading.current_thread(), endTime=0) | ||
self.addHook('rstatus', lambda sheet,self=self: (self.keystrokes, 'color_keystrokes')) | ||
|
@@ -746,6 +752,12 @@ def exceptionCaught(self, exc=None, **kwargs): | |
if options.debug: | ||
raise | ||
|
||
def onMouse(self, scr, y, x, h, w, **kwargs): | ||
for i in range(y, y+h): | ||
for j in range(x, x+w): | ||
for button, func in kwargs.items(): | ||
self.mousereg[scr][i][j][button] = func | ||
|
||
def drawLeftStatus(self, scr, vs): | ||
'Draw left side of status bar.' | ||
cattr = CursesAttr(colors.color_status) | ||
|
@@ -762,6 +774,10 @@ def drawLeftStatus(self, scr, vs): | |
|
||
y = self.windowHeight-1 | ||
x = clipdraw(scr, y, 0, lstatus, attr) | ||
self.onMouse(scr, y, 0, 1, x, | ||
BUTTON1_PRESSED='sheets', | ||
BUTTON3_PRESSED='rename-sheet') | ||
|
||
one = False | ||
for (pri, msgparts), n in sorted(self.statuses.items(), key=lambda k: -k[0][0]): | ||
if x > self.windowWidth: | ||
|
@@ -851,22 +867,37 @@ def run(self, scr): | |
self.statuses.clear() | ||
|
||
if keystroke == 'KEY_MOUSE': | ||
self.keystrokes = '' | ||
clicktype = '' | ||
try: | ||
devid, x, y, z, bstate = curses.getmouse() | ||
sheet.mouseX, sheet.mouseY = x, y | ||
if bstate & curses.BUTTON_CTRL: | ||
self.keystrokes += "CTRL-" | ||
clicktype += "CTRL-" | ||
bstate &= ~curses.BUTTON_CTRL | ||
if bstate & curses.BUTTON_ALT: | ||
self.keystrokes += "ALT-" | ||
clicktype += "ALT-" | ||
bstate &= ~curses.BUTTON_ALT | ||
if bstate & curses.BUTTON_SHIFT: | ||
self.keystrokes += "SHIFT-" | ||
clicktype += "SHIFT-" | ||
bstate &= ~curses.BUTTON_SHIFT | ||
|
||
keystroke = curses.mouseEvents.get(bstate, str(bstate)) | ||
sheet.mouseX, sheet.mouseY = x, y | ||
keystroke = clicktype + curses.mouseEvents.get(bstate, str(bstate)) | ||
|
||
f = self.mousereg[scr][y][x][keystroke] | ||
if f: | ||
if isinstance(f, str): | ||
for cmd in f.split(): | ||
sheet.exec_keystrokes(cmd) | ||
else: | ||
f(y, x, keystroke) | ||
|
||
self.keystrokes = keystroke | ||
keystroke = '' | ||
except curses.error: | ||
keystroke = '' | ||
pass | ||
except Exception as e: | ||
exceptionCaught(e) | ||
|
||
self.keystrokes += keystroke | ||
|
||
|
@@ -1695,6 +1726,7 @@ def drawColHeader(self, scr, y, vcolidx): | |
N = N[:colwidth-len(options.disp_truncator)] + options.disp_truncator | ||
clipdraw(scr, y, x, N, hdrattr.attr, colwidth) | ||
clipdraw(scr, y, x+colwidth-len(T), T, hdrattr.attr, len(T)) | ||
vd.onMouse(scr, y, x, 1, colwidth, BUTTON3_RELEASED='rename-col') | ||
|
||
if vcolidx == self.leftVisibleColIndex and col not in self.keyCols and self.nonKeyVisibleCols.index(col) > 0: | ||
A = options.disp_more_left | ||
|
@@ -1764,6 +1796,7 @@ def draw(self, scr): | |
clipdraw(scr, y, x+colwidth-len(note), note, noteattr.attr, len(note)) | ||
|
||
clipdraw(scr, y, x, disp_column_fill+cellval.display, attr.attr, colwidth-(1 if note else 0)) | ||
vd.onMouse(scr, y, x, 1, colwidth, BUTTON3_RELEASED='edit-cell') | ||
|
||
sepchars = disp_column_sep | ||
if (self.keyCols and col is self.keyCols[-1]) or vcolidx == self.rightVisibleColIndex: | ||
|
@@ -1820,9 +1853,13 @@ def editCell(self, vcolidx=None, rowidx=None, **kwargs): | |
|
||
Sheet.addCommand('BUTTON1_PRESSED', 'go-mouse', 'sheet.cursorRowIndex=topRowIndex+mouseY-1; sheet.cursorVisibleColIndex=visibleColAtX(mouseX)'), | ||
Sheet.addCommand('BUTTON1_RELEASED', 'scroll-mouse', 'sheet.topRowIndex=cursorRowIndex-mouseY+1'), | ||
|
||
Sheet.addCommand('BUTTON4_PRESSED', 'scroll-up', 'cursorDown(options.scroll_incr); sheet.topRowIndex += options.scroll_incr'), | ||
Sheet.addCommand('REPORT_MOUSE_POSITION', 'scroll-down', 'cursorDown(-options.scroll_incr); sheet.topRowIndex -= options.scroll_incr'), | ||
|
||
Sheet.bindkey('BUTTON1_CLICKED', 'go-mouse') | ||
Sheet.bindkey('BUTTON3_PRESSED', 'go-mouse') | ||
|
||
Sheet.addCommand('^G', 'show-cursor', 'status(statusLine)'), | ||
|
||
Sheet.addCommand('_', 'resize-col-max', 'cursorCol.toggleWidth(cursorCol.getMaxWidth(visibleRows))'), | ||
|