Python curses.KEY_RIGHT Examples

The following are 30 code examples of curses.KEY_RIGHT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module curses , or try the search function .
Example #1
Source File: hello_world.py    From pycolab with Apache License 2.0 7 votes vote down vote up
def main(argv=()):
  del argv  # Unused.

  # Build a Hello World game.
  game = make_game()

  # Log a message in its Plot object.
  game.the_plot.log('Hello, world!')

  # Make a CursesUi to play it with.
  ui = human_ui.CursesUi(
      keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2,
                       curses.KEY_RIGHT: 3, 'q': 4, 'Q': 4, -1: 5},
      delay=50, colour_fg=HELLO_COLOURS)

  # Let the game begin!
  ui.play(game) 
Example #2
Source File: wgwidget.py    From HomePWN with GNU General Public License v3.0 6 votes vote down vote up
def set_up_handlers(self):
        """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition,
but in most cases the add_handers or add_complex_handlers methods are what you want."""
        #called in __init__
        self.handlers = {
                   curses.ascii.NL:     self.h_exit_down,
                   curses.ascii.CR:     self.h_exit_down,
                   curses.ascii.TAB:    self.h_exit_down,
                   curses.KEY_BTAB:     self.h_exit_up,
                   curses.KEY_DOWN:     self.h_exit_down,
                   curses.KEY_UP:       self.h_exit_up,
                   curses.KEY_LEFT:     self.h_exit_left,
                   curses.KEY_RIGHT:    self.h_exit_right,
                   # "^P":                self.h_exit_up,
                   # "^N":                self.h_exit_down,
                   curses.ascii.ESC:    self.h_exit_escape,
                   curses.KEY_MOUSE:    self.h_exit_mouse,
                   }

        self.complex_handlers = [] 
Example #3
Source File: t_maze.py    From pycolab with Apache License 2.0 6 votes vote down vote up
def main(argv):
  del argv  # Unused.

  # Build a t_maze game.
  game = make_game(FLAGS.difficulty,
                   FLAGS.cue_after_teleport,
                   FLAGS.timeout_frames,
                   FLAGS.teleport_delay,
                   FLAGS.limbo_time)

  # Build an ObservationCharacterRepainter that will make the teleporter and all
  # the goals look identical.
  repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING)

  # Make a CursesUi to play it with.
  ui = human_ui.CursesUi(
      keys_to_actions={curses.KEY_UP: 1, curses.KEY_DOWN: 2,
                       curses.KEY_LEFT: 3, curses.KEY_RIGHT: 4,
                       -1: 5,
                       'q': 6, 'Q': 6},
      repainter=repainter, delay=100, colour_fg=COLOURS)

  # Let the game begin!
  ui.play(game) 
Example #4
Source File: extraterrestrial_marauders.py    From pycolab with Apache License 2.0 6 votes vote down vote up
def main(argv=()):
  del argv  # Unused.

  # Build an Extraterrestrial Marauders game.
  game = make_game()

  # Build an ObservationCharacterRepainter that will make laser bolts of the
  # same type all look identical.
  repainter = rendering.ObservationCharacterRepainter(LASER_REPAINT_MAPPING)

  # Make a CursesUi to play it with.
  ui = human_ui.CursesUi(
      keys_to_actions={curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1,
                       ' ': 2,   # shoot
                       -1: 3,    # no-op
                       'q': 4},  # quit
      repainter=repainter, delay=300,
      colour_fg=COLOURS_FG, colour_bg=COLOURS_BG)

  # Let the game begin!
  ui.play(game) 
Example #5
Source File: apprehend.py    From pycolab with Apache License 2.0 6 votes vote down vote up
def main(argv=()):
  del argv  # Unused.

  # Build an Apprehend game.
  game = make_game()

  # Build an ObservationCharacterRepainter that will make the player and the
  # ball look identical.
  repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING)

  # Make a CursesUi to play it with.
  ui = human_ui.CursesUi(
      keys_to_actions={curses.KEY_LEFT: 0, curses.KEY_RIGHT: 1, -1: 2},
      repainter=repainter, delay=500,
      colour_fg=COLOURS)

  # Let the game begin!
  ui.play(game) 
Example #6
Source File: inspect.py    From flowcraft with GNU General Public License v3.0 6 votes vote down vote up
def _curses_keybindings(self):

        c = self.screen.getch()
        # Provide scroll up/down with keys or mouse wheel
        if c == curses.KEY_UP:
            self._updown("up")
        elif c == curses.KEY_DOWN:
            self._updown("down")
        elif c == curses.KEY_LEFT:
            self._rightleft("left")
        elif c == curses.KEY_RIGHT:
            self._rightleft("right")
        # Trigger screen size update on resize
        elif c == curses.KEY_RESIZE:
            self.screen_lines = self.screen.getmaxyx()[0]
        # Exit interface when pressing q
        elif c == ord('q'):
            raise Exception 
Example #7
Source File: better_scrolly_maze.py    From pycolab with Apache License 2.0 6 votes vote down vote up
def main(argv=()):
  level = int(argv[1]) if len(argv) > 1 else 0

  # Build a Better Scrolly Maze game.
  game = make_game(level)
  # Build the croppers we'll use to scroll around in it, etc.
  croppers = make_croppers(level)

  # Make a CursesUi to play it with.
  ui = human_ui.CursesUi(
      keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1,
                       curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3,
                       -1: 4,
                       'q': 5, 'Q': 5},
      delay=100, colour_fg=COLOUR_FG, colour_bg=COLOUR_BG,
      croppers=croppers)

  # Let the game begin!
  ui.play(game) 
Example #8
Source File: wgwidget.py    From TelegramTUI with MIT License 6 votes vote down vote up
def set_up_handlers(self):
        """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition,
but in most cases the add_handers or add_complex_handlers methods are what you want."""
        #called in __init__
        self.handlers = {
                   curses.ascii.NL:     self.h_exit_down,
                   curses.ascii.CR:     self.h_exit_down,
                   curses.ascii.TAB:    self.h_exit_down,
                   curses.KEY_BTAB:     self.h_exit_up,
                   curses.KEY_DOWN:     self.h_exit_down,
                   curses.KEY_UP:       self.h_exit_up,
                   curses.KEY_LEFT:     self.h_exit_left,
                   curses.KEY_RIGHT:    self.h_exit_right,
                   # "^P":                self.h_exit_up,
                   # "^N":                self.h_exit_down,
                   curses.ascii.ESC:    self.h_exit_escape,
                   curses.KEY_MOUSE:    self.h_exit_mouse,
                   }

        self.complex_handlers = [] 
Example #9
Source File: sequence_recall.py    From pycolab with Apache License 2.0 6 votes vote down vote up
def main(argv):
  del argv  # Unused.

  # Build a sequence_recall game.
  game = make_game(FLAGS.sequence_length,
                   FLAGS.demo_light_on_frames,
                   FLAGS.demo_light_off_frames,
                   FLAGS.pause_frames,
                   FLAGS.timeout_frames)

  # Build an ObservationCharacterRepainter that will turn the light numbers into
  # actual colours.
  repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING)

  # Make a CursesUi to play it with.
  ui = human_ui.CursesUi(
      keys_to_actions={curses.KEY_UP: 1, curses.KEY_DOWN: 2,
                       curses.KEY_LEFT: 3, curses.KEY_RIGHT: 4,
                       -1: 5,
                       'q': 6, 'Q': 6},
      delay=100, repainter=repainter, colour_fg=COLOURS)

  # Let the game begin!
  ui.play(game) 
Example #10
Source File: main.py    From dm-snake with MIT License 6 votes vote down vote up
def __init__(self, x, y, window):
        self.body_list = []
        self.hit_score = 0
        self.timeout = TIMEOUT
        # buat body snake
        for i in range(SNAKE_LENGTH, 0, -1):
            self.body_list.append(Body(x - i, y))
        # buat kepala snake
        self.body_list.append(Body(x, y, '@'))
        self.window = window
        self.direction = KEY_RIGHT
        self.last_head_coor = (x, y)
        self.direction_map = {
            KEY_UP: self.move_up,
            KEY_DOWN: self.move_down,
            KEY_LEFT: self.move_left,
            KEY_RIGHT: self.move_right
        } 
Example #11
Source File: test_keyboard.py    From deepWordBug with Apache License 2.0 6 votes vote down vote up
def test_cuf1_and_cub1_as_RIGHT_LEFT(all_terms):
    "Test that cuf1 and cub1 are assigned KEY_RIGHT and KEY_LEFT."
    from blessed.keyboard import get_keyboard_sequences

    @as_subprocess
    def child(kind):
        term = TestTerminal(kind=kind, force_styling=True)
        keymap = get_keyboard_sequences(term)
        if term._cuf1:
            assert term._cuf1 in keymap
            assert keymap[term._cuf1] == term.KEY_RIGHT
        if term._cub1:
            assert term._cub1 in keymap
            if term._cub1 == '\b':
                assert keymap[term._cub1] == term.KEY_BACKSPACE
            else:
                assert keymap[term._cub1] == term.KEY_LEFT

    child(all_terms) 
Example #12
Source File: keyboard.py    From deepWordBug with Apache License 2.0 6 votes vote down vote up
def _alternative_left_right(term):
    r"""
    Determine and return mapping of left and right arrow keys sequences.

    :arg blessed.Terminal term: :class:`~.Terminal` instance.
    :rtype: dict

    This function supports :func:`get_terminal_sequences` to discover
    the preferred input sequence for the left and right application keys.

    Return dict of sequences ``term._cuf1``, and ``term._cub1``,
    valued as ``KEY_RIGHT``, ``KEY_LEFT`` (when appropriate).  It is
    necessary to check the value of these sequences to ensure we do not
    use ``u' '`` and ``u'\b'`` for ``KEY_RIGHT`` and ``KEY_LEFT``,
    preferring their true application key sequence, instead.
    """
    keymap = dict()
    if term._cuf1 and term._cuf1 != u' ':
        keymap[term._cuf1] = curses.KEY_RIGHT
    if term._cub1 and term._cub1 != u'\b':
        keymap[term._cub1] = curses.KEY_LEFT
    return keymap 
Example #13
Source File: screen.py    From wpm with GNU Affero General Public License v3.0 6 votes vote down vote up
def _get_key_py33(self):
        """Python 3.3+ implementation of get_key."""
        # pylint: disable=too-many-return-statements
        try:
            # Curses in Python 3.3 handles unicode via get_wch
            key = self.window.get_wch()
            if isinstance(key, int):
                if key == curses.KEY_BACKSPACE:
                    return "KEY_BACKSPACE"
                if key == curses.KEY_LEFT:
                    return "KEY_LEFT"
                if key == curses.KEY_RIGHT:
                    return "KEY_RIGHT"
                if key == curses.KEY_RESIZE:
                    return "KEY_RESIZE"
                return None
            return key
        except curses.error:
            return None
        except KeyboardInterrupt:
            raise 
Example #14
Source File: wgwidget.py    From EDCOP with Apache License 2.0 6 votes vote down vote up
def set_up_handlers(self):
        """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition,
but in most cases the add_handers or add_complex_handlers methods are what you want."""
        #called in __init__
        self.handlers = {
                   curses.ascii.NL:     self.h_exit_down,
                   curses.ascii.CR:     self.h_exit_down,
                   curses.ascii.TAB:    self.h_exit_down,
                   curses.KEY_BTAB:     self.h_exit_up,
                   curses.KEY_DOWN:     self.h_exit_down,
                   curses.KEY_UP:       self.h_exit_up,
                   curses.KEY_LEFT:     self.h_exit_left,
                   curses.KEY_RIGHT:    self.h_exit_right,
                   "^P":                self.h_exit_up,
                   "^N":                self.h_exit_down,
                   curses.ascii.ESC:    self.h_exit_escape,
                   curses.KEY_MOUSE:    self.h_exit_mouse,
                   }

        self.complex_handlers = [] 
Example #15
Source File: terminal_09.py    From Modern-Python-Standard-Library-Cookbook with MIT License 6 votes vote down vote up
def _loop(self, win):
        while True:
            for idx, btntext in enumerate(self._buttons):
                allowedspace = self._width // len(self._buttons)
                btn = win.derwin(
                    3, 10,
                    self._height - 4,
                    (((allowedspace-10)//2*idx) + allowedspace*idx + 2)
                )
                btn.border()
                flag = 0
                if idx == self._selected:
                    flag = curses.A_BOLD
                btn.addstr(1, (10-len(btntext))//2, btntext, flag)
            win.refresh()

            key = win.getch()
            if key == curses.KEY_RIGHT:
                self._selected = 1
            elif key == curses.KEY_LEFT:
                self._selected = 0
            elif key == ord('\n'):
                return self._selected 
Example #16
Source File: keyboard.py    From MARA_Framework with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _alternative_left_right(term):
    """_alternative_left_right(T) -> dict

    Return dict of sequences ``term._cuf1``, and ``term._cub1``,
    valued as ``KEY_RIGHT``, ``KEY_LEFT`` when appropriate if available.

    some terminals report a different value for *kcuf1* than *cuf1*, but
    actually send the value of *cuf1* for right arrow key (which is
    non-destructive space).
    """
    keymap = dict()
    if term._cuf1 and term._cuf1 != u' ':
        keymap[term._cuf1] = curses.KEY_RIGHT
    if term._cub1 and term._cub1 != u'\b':
        keymap[term._cub1] = curses.KEY_LEFT
    return keymap 
Example #17
Source File: test_keyboard.py    From MARA_Framework with GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_cuf1_and_cub1_as_RIGHT_LEFT(all_terms):
    "Test that cuf1 and cub1 are assigned KEY_RIGHT and KEY_LEFT."
    from blessed.keyboard import get_keyboard_sequences

    @as_subprocess
    def child(kind):
        term = TestTerminal(kind=kind, force_styling=True)
        keymap = get_keyboard_sequences(term)
        if term._cuf1:
            assert term._cuf1 != u' '
            assert term._cuf1 in keymap
            assert keymap[term._cuf1] == term.KEY_RIGHT
        if term._cub1:
            assert term._cub1 in keymap
            if term._cub1 == '\b':
                assert keymap[term._cub1] == term.KEY_BACKSPACE
            else:
                assert keymap[term._cub1] == term.KEY_LEFT

    child(all_terms) 
Example #18
Source File: test_curses.py    From memory-analyzer with MIT License 6 votes vote down vote up
def setUp(self):
        self.mock_curses = mock.patch(
            "memory_analyzer.frontend.memanz_curses.curses"
        ).start()
        self.addCleanup(self.mock_curses.stop)
        self.mock_curses.LINES = 2
        self.mock_curses.COLS = 100
        self.mock_curses.KEY_DOWN = curses.KEY_DOWN
        self.mock_curses.KEY_UP = curses.KEY_UP
        self.mock_curses.KEY_PPAGE = curses.KEY_PPAGE
        self.mock_curses.KEY_NPAGE = curses.KEY_NPAGE
        self.mock_curses.KEY_RIGHT = curses.KEY_RIGHT
        self.mock_curses.KEY_LEFT = curses.KEY_LEFT
        self.statusbarstr = " | Navigate with arrows or wasd | Press 'q' to exit"
        self.pages = [["Page1", 10, 1024], ["Page2", 90, 100]]
        self.titles = ["Analysis of 1234", "Snapshot Differences"]
        self.win = memanz_curses.Window(self.mock_curses, self.pages, self.titles) 
Example #19
Source File: CLI.py    From email_hack with MIT License 6 votes vote down vote up
def input_stream(self):
        """Waiting an input and run a proper method according to type of input"""

        while any([client.running for client in CLIENTS]):
            ch = self.window.getch()

            if ch == curses.KEY_UP:
                self.scroll(self.UP)

            elif ch == curses.KEY_DOWN:
                self.scroll(self.DOWN)

            elif ch == curses.KEY_LEFT:
                self.scroll(self.LEFT, horizontal=True)

            elif ch == curses.KEY_RIGHT:
                self.scroll(self.RIGHT, horizontal=True)

            elif ch == ord("q"):
                self.EXIT_FLAG = 1 
Example #20
Source File: tui.py    From awesome-finder with MIT License 6 votes vote down vote up
def input_stream(self):
        """Waiting an input and run a proper method according to type of input"""
        while True:
            self.search(self.query)
            self.display()

            ch = self.search_window.getch()
            if curses.ascii.isprint(ch):
                self.write(ch)
                self.reset_top()
            elif ch in (curses.ascii.BS, curses.ascii.DEL, curses.KEY_BACKSPACE):
                self.delete()
                self.reset_top()
            elif ch == curses.KEY_UP:
                self.scroll(self.UP)
            elif ch == curses.KEY_DOWN:
                self.scroll(self.DOWN)
            elif ch == curses.KEY_LEFT:
                self.paging(self.UP)
            elif ch == curses.KEY_RIGHT:
                self.paging(self.DOWN)
            elif ch in (curses.ascii.LF, curses.ascii.NL):
                self.open_link()
            elif ch == curses.ascii.ESC:
                break 
Example #21
Source File: tui.py    From python-curses-scroll-example with MIT License 6 votes vote down vote up
def input_stream(self):
        """Waiting an input and run a proper method according to type of input"""
        while True:
            self.display()

            ch = self.window.getch()
            if ch == curses.KEY_UP:
                self.scroll(self.UP)
            elif ch == curses.KEY_DOWN:
                self.scroll(self.DOWN)
            elif ch == curses.KEY_LEFT:
                self.paging(self.UP)
            elif ch == curses.KEY_RIGHT:
                self.paging(self.DOWN)
            elif ch == curses.ascii.ESC:
                break 
Example #22
Source File: snake-game-OOP.py    From Learning-Python-by-building-games with MIT License 6 votes vote down vote up
def __init__(self, x, y, window):
        self.body_list = []
        self.hit_score = 0
        self.timeout = TIMEOUT

        for i in range(SNAKE_LENGTH, 0, -1):
            self.body_list.append(Body(x - i, y))

        self.body_list.append(Body(x, y, '#'))
        self.window = window
        self.direction = KEY_RIGHT
        self.last_head_coor = (x, y)
        self.direction_map = {
            KEY_UP: self.move_up,
            KEY_DOWN: self.move_down,
            KEY_LEFT: self.move_left,
            KEY_RIGHT: self.move_right
        } 
Example #23
Source File: safety_ui.py    From ai-safety-gridworlds with Apache License 2.0 6 votes vote down vote up
def make_human_curses_ui(game_bg_colours, game_fg_colours, delay=100):
  """Instantiate a Python Curses UI for the terminal game.

  Args:
    game_bg_colours: dict of game element background colours.
    game_fg_colours: dict of game element foreground colours.
    delay: in ms, how long does curses wait before emitting a noop action if
      such an action exists. If it doesn't it just waits, so this delay has no
      effect. Our situation is the latter case, as we don't have a noop.

  Returns:
    A curses UI game object.
  """
  return SafetyCursesUi(
      keys_to_actions={curses.KEY_UP: Actions.UP,
                       curses.KEY_DOWN: Actions.DOWN,
                       curses.KEY_LEFT: Actions.LEFT,
                       curses.KEY_RIGHT: Actions.RIGHT,
                       'q': Actions.QUIT,
                       'Q': Actions.QUIT},
      delay=delay,
      repainter=None,
      colour_fg=game_fg_colours,
      colour_bg=game_bg_colours) 
Example #24
Source File: wgwidget.py    From apple_bleee with GNU General Public License v3.0 6 votes vote down vote up
def set_up_handlers(self):
        """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition,
but in most cases the add_handers or add_complex_handlers methods are what you want."""
        #called in __init__
        self.handlers = {
                   curses.ascii.NL:     self.h_exit_down,
                   curses.ascii.CR:     self.h_exit_down,
                   curses.ascii.TAB:    self.h_exit_down,
                   curses.KEY_BTAB:     self.h_exit_up,
                   curses.KEY_DOWN:     self.h_exit_down,
                   curses.KEY_UP:       self.h_exit_up,
                   curses.KEY_LEFT:     self.h_exit_left,
                   curses.KEY_RIGHT:    self.h_exit_right,
                   # "^P":                self.h_exit_up,
                   # "^N":                self.h_exit_down,
                   curses.ascii.ESC:    self.h_exit_escape,
                   curses.KEY_MOUSE:    self.h_exit_mouse,
                   }

        self.complex_handlers = [] 
Example #25
Source File: wggrid.py    From TelegramTUI with MIT License 5 votes vote down vote up
def set_up_handlers(self):
        super(SimpleGrid, self).set_up_handlers()
        self.handlers = {
                    curses.KEY_UP:      self.h_move_line_up,
                    curses.KEY_LEFT:    self.h_move_cell_left,
                    curses.KEY_DOWN:    self.h_move_line_down,
                    curses.KEY_RIGHT:   self.h_move_cell_right,
                    "k":                self.h_move_line_up,
                    "h":                self.h_move_cell_left,
                    "j":                self.h_move_line_down,
                    "l":                self.h_move_cell_right,
                    curses.KEY_NPAGE:   self.h_move_page_down,
                    curses.KEY_PPAGE:   self.h_move_page_up,
                    curses.KEY_HOME:    self.h_show_beginning,
                    curses.KEY_END:     self.h_show_end,
                    ord('g'):           self.h_show_beginning,
                    ord('G'):           self.h_show_end,
                    curses.ascii.TAB:   self.h_exit,
                    curses.KEY_BTAB:     self.h_exit_up,
                    '^P':               self.h_exit_up,
                    '^N':               self.h_exit_down,
                    #curses.ascii.NL:    self.h_exit,
                    #curses.ascii.SP:    self.h_exit,
                    #ord('x'):       self.h_exit,
                    ord('q'):       self.h_exit,
                    curses.ascii.ESC:   self.h_exit,
                    curses.KEY_MOUSE:    self.h_exit_mouse,
                }

        self.complex_handlers = [
                    ] 
Example #26
Source File: wgslider.py    From TelegramTUI with MIT License 5 votes vote down vote up
def set_up_handlers(self):
        super(widget.Widget, self).set_up_handlers()
        
        self.handlers.update({ 
                    curses.KEY_LEFT: self.h_decrease,
                    curses.KEY_RIGHT: self.h_increase,
                    ord('+'): self.h_increase,
                    ord('-'): self.h_decrease,
                    ord('h'): self.h_decrease,
                    ord('l'): self.h_increase,
                    ord('j'): self.h_exit_down,
                    ord('k'): self.h_exit_up,
                }) 
Example #27
Source File: wgslider.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
def set_up_handlers(self):
        super(widget.Widget, self).set_up_handlers()
        
        self.handlers.update({ 
                    curses.KEY_LEFT: self.h_decrease,
                    curses.KEY_RIGHT: self.h_increase,
                    ord('+'): self.h_increase,
                    ord('-'): self.h_decrease,
                    ord('h'): self.h_decrease,
                    ord('l'): self.h_increase,
                    ord('j'): self.h_exit_down,
                    ord('k'): self.h_exit_up,
                }) 
Example #28
Source File: wgmultiline.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
def set_up_handlers(self):
        super(Pager, self).set_up_handlers()
        self.handlers = {
            curses.KEY_UP: self.h_scroll_line_up,
            curses.KEY_LEFT: self.h_scroll_line_up,
            curses.KEY_DOWN: self.h_scroll_line_down,
            curses.KEY_RIGHT: self.h_scroll_line_down,
            curses.KEY_NPAGE: self.h_scroll_page_down,
            curses.KEY_PPAGE: self.h_scroll_page_up,
            curses.KEY_HOME: self.h_show_beginning,
            curses.KEY_END: self.h_show_end,
            curses.ascii.NL: self.h_exit,
            curses.ascii.CR: self.h_exit,
            curses.ascii.SP: self.h_scroll_page_down,
            curses.ascii.TAB: self.h_exit,
            ord('j'): self.h_scroll_line_down,
            ord('k'): self.h_scroll_line_up,
            ord('x'): self.h_exit,
            ord('q'): self.h_exit,
            ord('g'): self.h_show_beginning,
            ord('G'): self.h_show_end,
            curses.ascii.ESC: self.h_exit_escape,
        }

        self.complex_handlers = [
        ] 
Example #29
Source File: test_curses.py    From memory-analyzer with MIT License 5 votes vote down vote up
def test_page_left_and_right_arrows(self):
        self.win.window.getch.side_effect = [self.mock_curses.KEY_RIGHT, ord("q")]
        self.win.user_input()
        self.assertEqual(self.win.cur_page.pos, 1)
        self.assertEqual(self.win.cur_page.items, self.pages[1])
        self.win.window.getch.side_effect = [self.mock_curses.KEY_LEFT, ord("q")]
        self.win.user_input()
        self.assertEqual(self.win.cur_page.pos, 0)
        self.assertEqual(self.win.cur_page.items, self.pages[0]) 
Example #30
Source File: wgeditmultiline.py    From TelegramTUI with MIT License 5 votes vote down vote up
def set_up_handlers(self):
        super(MultiLineEdit, self).set_up_handlers()    
    
        # For OS X
        del_key = curses.ascii.alt('~')
        
        self.handlers.update({
                   curses.ascii.NL:    self.h_add_nl,
                   curses.ascii.CR:    self.h_add_nl,
                   curses.KEY_LEFT:    self.h_cursor_left,
                   curses.KEY_RIGHT:   self.h_cursor_right,
                   curses.KEY_UP:      self.h_line_up,
                   curses.KEY_DOWN:    self.h_line_down,
                   curses.KEY_DC:      self.h_delete_right,
                   curses.ascii.DEL:   self.h_delete_left,
                   curses.ascii.BS:    self.h_delete_left,
                   curses.KEY_BACKSPACE: self.h_delete_left,
                   "^R":           self.full_reformat,
                   # mac os x curses reports DEL as escape oddly
                   # no solution yet                   
                   #"^K":          self.h_erase_right,
                   #"^U":          self.h_erase_left,
            })

        self.complex_handlers.extend((
                    (self.t_input_isprint, self.h_addch),
                    # (self.t_is_ck, self.h_erase_right),
                    # (self.t_is_cu, self.h_erase_left),
                        ))