Linter fixes. Added ctrl-d and ctrl-u for pagedown/pageup.

This commit is contained in:
Michael Lazar
2016-02-10 01:02:37 -08:00
parent a0da5fc6ca
commit 5fda5a7999
6 changed files with 25 additions and 20 deletions

View File

@@ -4,13 +4,13 @@ from __future__ import unicode_literals
import re import re
import os import os
import time import time
import curses
import signal import signal
import inspect import inspect
import weakref import weakref
import logging import logging
import threading import threading
from curses import ascii import curses
import curses.ascii
from contextlib import contextmanager from contextlib import contextmanager
import six import six
@@ -545,9 +545,9 @@ class Controller(object):
# different function. # different function.
if controller.character_map.get(val, func) != func: if controller.character_map.get(val, func) != func:
raise exceptions.ConfigError( raise exceptions.ConfigError(
'Invalid configuration, cannot bind the `%s`' "Invalid configuration! `%s` is bound to "
' key to two different commands in the `%s`' "duplicate commands in the "
' context' % (key, self.__class__.__name__)) "%s" % (key, controller.__name__))
controller.character_map[val] = func controller.character_map[val] = func
def trigger(self, char, *args, **kwargs): def trigger(self, char, *args, **kwargs):
@@ -632,8 +632,8 @@ class KeyMap(object):
try: try:
return self._keymap[command] return self._keymap[command]
except KeyError: except KeyError:
raise exceptions.ConfigError( raise exceptions.ConfigError('Invalid configuration! `%s` key is '
'Invalid configuration, `%s` key undefined' % command.val) 'undefined' % command.val)
@staticmethod @staticmethod
def parse(key): def parse(key):
@@ -649,7 +649,7 @@ class KeyMap(object):
return getattr(curses, key[1:-1]) return getattr(curses, key[1:-1])
elif re.match('[<].*[>]', key): elif re.match('[<].*[>]', key):
# Ascii control character # Ascii control character
return getattr(ascii, key[1:-1]) return getattr(curses.ascii, key[1:-1])
elif key.startswith('0x'): elif key.startswith('0x'):
# Ascii hex code # Ascii hex code
return int(key, 16) return int(key, 16)
@@ -660,8 +660,9 @@ class KeyMap(object):
return code return code
# Python 3.3 has a curses.get_wch() function that we can use # Python 3.3 has a curses.get_wch() function that we can use
# for unicode keys, but Python 2.7 is limited to ascii. # for unicode keys, but Python 2.7 is limited to ascii.
raise exceptions.ConfigError( raise exceptions.ConfigError('Invalid configuration! `%s` is '
'Invalid key `%s`, must be in the ascii range' % key) 'not in the ascii range' % key)
except (AttributeError, ValueError, TypeError): except (AttributeError, ValueError, TypeError):
raise exceptions.ConfigError('Invalid key string `%s`' % key) raise exceptions.ConfigError('Invalid configuration! "%s" is not a '
'valid key' % key)

View File

@@ -39,6 +39,7 @@ class Page(object):
self.oauth = oauth self.oauth = oauth
self.content = None self.content = None
self.nav = None self.nav = None
self.controller = None
self.active = True self.active = True
self._row = 0 self._row = 0

View File

@@ -77,7 +77,10 @@ oauth_scope = edit,history,identity,mysubreddits,privatemessages,read,report,sav
; Notes: ; Notes:
; - Curses <KEY_ENTER> is unreliable and should always be used in conjunction ; - Curses <KEY_ENTER> is unreliable and should always be used in conjunction
; with <LF>. ; with <LF>.
; - Use 0x20 for the space key ; - Use 0x20 for the space key.
; - A subset of Ctrl modifiers are available through the ascii control codes.
; For example, Ctrl-D will trigger an <EOT> signal. See the table above for
; a complete reference.
; Base page ; Base page
EXIT = q EXIT = q
@@ -90,8 +93,8 @@ SORT_NEW = 4
SORT_CONTROVERSIAL = 5 SORT_CONTROVERSIAL = 5
MOVE_UP = k, <KEY_UP> MOVE_UP = k, <KEY_UP>
MOVE_DOWN = j, <KEY_DOWN> MOVE_DOWN = j, <KEY_DOWN>
PAGE_UP = m, <KEY_PPAGE> PAGE_UP = m, <KEY_PPAGE>, <NAK>
PAGE_DOWN = n, <KEY_NPAGE> PAGE_DOWN = n, <KEY_NPAGE>, <EOT>
UPVOTE = a UPVOTE = a
DOWNVOTE = z DOWNVOTE = z
LOGIN = u LOGIN = u

View File

@@ -17,9 +17,9 @@ class SubmissionController(PageController):
class SubmissionPage(Page): class SubmissionPage(Page):
def __init__(self, reddit, term, config, oauth, url=None, submission=None): def __init__(self, reddit, term, config, oauth, url=None, submission=None):
self.controller = SubmissionController(self, keymap=config.keymap)
super(SubmissionPage, self).__init__(reddit, term, config, oauth) super(SubmissionPage, self).__init__(reddit, term, config, oauth)
self.controller = SubmissionController(self, keymap=config.keymap)
if url: if url:
self.content = SubmissionContent.from_url(reddit, url, term.loader) self.content = SubmissionContent.from_url(reddit, url, term.loader)
else: else:

View File

@@ -24,9 +24,9 @@ class SubredditPage(Page):
name (string): Name of subreddit to open name (string): Name of subreddit to open
url (string): Optional submission to load upon start url (string): Optional submission to load upon start
""" """
self.controller = SubredditController(self, keymap=config.keymap)
super(SubredditPage, self).__init__(reddit, term, config, oauth) super(SubredditPage, self).__init__(reddit, term, config, oauth)
self.controller = SubredditController(self, keymap=config.keymap)
self.content = SubredditContent.from_name(reddit, name, term.loader) self.content = SubredditContent.from_name(reddit, name, term.loader)
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)

View File

@@ -15,9 +15,9 @@ class SubscriptionController(PageController):
class SubscriptionPage(Page): class SubscriptionPage(Page):
def __init__(self, reddit, term, config, oauth): def __init__(self, reddit, term, config, oauth):
self.controller = SubscriptionController(self, keymap=config.keymap)
super(SubscriptionPage, self).__init__(reddit, term, config, oauth) super(SubscriptionPage, self).__init__(reddit, term, config, oauth)
self.controller = SubscriptionController(self, keymap=config.keymap)
self.content = SubscriptionContent.from_user(reddit, term.loader) self.content = SubscriptionContent.from_user(reddit, term.loader)
self.nav = Navigator(self.content.get) self.nav = Navigator(self.content.get)
self.subreddit_data = None self.subreddit_data = None