First broken attempt at implementing count
This commit is contained in:
parent
bf99519046
commit
114c2c01d3
@ -53,29 +53,29 @@ class Print(Command):
|
|||||||
nargs = 0
|
nargs = 0
|
||||||
signal = pyqtSignal()
|
signal = pyqtSignal()
|
||||||
|
|
||||||
# FIXME implement count
|
|
||||||
class ScrollLeft(Command):
|
class ScrollLeft(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
key = 'h'
|
key = 'h'
|
||||||
signal = pyqtSignal()
|
count = True
|
||||||
|
signal = pyqtSignal([], [int])
|
||||||
|
|
||||||
# FIXME implement count
|
|
||||||
class ScrollDown(Command):
|
class ScrollDown(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
key = 'j'
|
key = 'j'
|
||||||
signal = pyqtSignal()
|
count = True
|
||||||
|
signal = pyqtSignal([], [int])
|
||||||
|
|
||||||
# FIXME implement count
|
|
||||||
class ScrollUp(Command):
|
class ScrollUp(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
key = 'k'
|
key = 'k'
|
||||||
signal = pyqtSignal()
|
count = True
|
||||||
|
signal = pyqtSignal([], [int])
|
||||||
|
|
||||||
# FIXME implement count
|
|
||||||
class ScrollRight(Command):
|
class ScrollRight(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
key = 'l'
|
key = 'l'
|
||||||
signal = pyqtSignal()
|
count = True
|
||||||
|
signal = pyqtSignal([], [int])
|
||||||
|
|
||||||
class Undo(Command):
|
class Undo(Command):
|
||||||
nargs = 0
|
nargs = 0
|
||||||
|
@ -2,6 +2,7 @@ from PyQt5.QtCore import QObject, Qt, pyqtSignal
|
|||||||
from PyQt5.QtWidgets import QShortcut
|
from PyQt5.QtWidgets import QShortcut
|
||||||
from PyQt5.QtGui import QKeySequence
|
from PyQt5.QtGui import QKeySequence
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
class KeyParser(QObject):
|
class KeyParser(QObject):
|
||||||
keystring = ''
|
keystring = ''
|
||||||
@ -16,28 +17,46 @@ class KeyParser(QObject):
|
|||||||
|
|
||||||
def handle(self, e):
|
def handle(self, e):
|
||||||
logging.debug('Got key: {} / text: "{}"'.format(e.key(), e.text()))
|
logging.debug('Got key: {} / text: "{}"'.format(e.key(), e.text()))
|
||||||
if not e.text().strip():
|
txt = e.text().strip()
|
||||||
|
if not txt:
|
||||||
logging.debug('Ignoring, no text')
|
logging.debug('Ignoring, no text')
|
||||||
return
|
return
|
||||||
self.keystring += e.text()
|
|
||||||
|
self.keystring += txt
|
||||||
|
|
||||||
if self.keystring == ':':
|
if self.keystring == ':':
|
||||||
self.set_cmd_text.emit(':')
|
self.set_cmd_text.emit(':')
|
||||||
self.keystring = ''
|
self.keystring = ''
|
||||||
return
|
return
|
||||||
|
|
||||||
|
(countstr, cmdstr) = re.match('^(\d*)(.*)', self.keystring).groups()
|
||||||
|
|
||||||
|
if not cmdstr:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmd = self.key_to_cmd[self.keystring]
|
cmd = self.key_to_cmd[cmdstr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pos = len(self.keystring)
|
pos = len(cmdstr)
|
||||||
if any([self.keystring[-1] == needle[pos-1]
|
if any([cmdstr[-1] == needle[pos-1]
|
||||||
for needle in self.key_to_cmd]):
|
for needle in self.key_to_cmd]):
|
||||||
logging.debug('No match for "{}" (added {})'.format(self.keystring, e.text()))
|
logging.debug('No match for "{}" (added {})'.format(
|
||||||
|
self.keystring, txt))
|
||||||
else:
|
else:
|
||||||
logging.debug('Giving up with "{}", no matches'.format(self.keystring))
|
logging.debug('Giving up with "{}", no matches'.format(
|
||||||
|
self.keystring))
|
||||||
self.keystring = ''
|
self.keystring = ''
|
||||||
|
return
|
||||||
|
|
||||||
|
self.keystring = ''
|
||||||
|
count = int(countstr) if countstr else None
|
||||||
|
|
||||||
|
if cmd.nargs and cmd.nargs != 0:
|
||||||
|
logging.debug('Filling statusbar with partial command {}'.format(
|
||||||
|
cmd.name))
|
||||||
|
self.set_cmd_text.emit(':{} '.format(cmd.name))
|
||||||
else:
|
else:
|
||||||
self.keystring = ''
|
if count is not None:
|
||||||
if cmd.nargs and cmd.nargs != 0:
|
cmd.run(count=count)
|
||||||
logging.debug('Filling statusbar with partial command {}'.format(cmd.name))
|
|
||||||
self.set_cmd_text.emit(':{} '.format(cmd.name))
|
|
||||||
else:
|
else:
|
||||||
cmd.run()
|
cmd.run()
|
||||||
|
@ -41,6 +41,7 @@ class Command(QObject):
|
|||||||
name = None
|
name = None
|
||||||
key = None
|
key = None
|
||||||
signal = None
|
signal = None
|
||||||
|
count = False
|
||||||
bind = True
|
bind = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -54,15 +55,21 @@ class Command(QObject):
|
|||||||
(self.nargs == '+' and len(argv) < 1)):
|
(self.nargs == '+' and len(argv) < 1)):
|
||||||
raise TypeError("Invalid argument count!")
|
raise TypeError("Invalid argument count!")
|
||||||
|
|
||||||
def run(self, argv=None):
|
def run(self, argv=None, count=None):
|
||||||
logging.debug("Cmd called: {}({})".format(self.__class__.__name__,
|
logging.debug("Cmd called: {}({})".format(self.__class__.__name__,
|
||||||
", ".join(argv) if argv else ''))
|
", ".join(argv) if argv else ''))
|
||||||
if not self.signal:
|
if not self.signal:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
# some sane defaults
|
# some sane defaults
|
||||||
if self.nargs == 0:
|
if self.nargs == 0:
|
||||||
self.signal.emit()
|
if count is not None:
|
||||||
|
self.signal.emit(count)
|
||||||
|
else:
|
||||||
|
self.signal.emit()
|
||||||
elif self.nargs == 1:
|
elif self.nargs == 1:
|
||||||
self.signal.emit(argv[0])
|
if count is not None:
|
||||||
|
self.signal.emit(count, argv[0])
|
||||||
|
else:
|
||||||
|
self.signal.emit(argv[0])
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
Loading…
Reference in New Issue
Block a user