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

keyboard/mouse context mgrs, printable width of sequences, sequence parsers #27

Closed
wants to merge 78 commits into from

Commits on Apr 11, 2013

  1. implement _resolve_multibyte

    - add unicode-derived 'Keystroke' class, which is yielded by the
    generator method _resolve_multibyte, adding additional properties,
    .is_sequence (bool), .code (int), and .name (str).
    - detect encoding and initialize incrementaldecoder in __init__, used
    by _resolve_multibyte.
    - inherit curses key capability names, values, and create multibyte
    sequence pattern lookup in __init__
    - add _resolve_keycode method, returns key capability name for an
    integer.
    - add _resolve_multibyte(text) method, given a string of multibyte
    input, 'text', returns instances of Keystroke class, which may be
    checked for .is_sequence, .code, and .name.
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    596602c View commit details
    Browse the repository at this point in the history
  2. Implement sequence-safe word wrapping

    Add wrap method to Terminal, with accompanying AnsiWrapper class, a
    derived version of textwrap.TextWrapper, with a modified version of
    _wrap_chunks that is sequence-safe.
    
    A module-global function, 'ansiwrap' is exposed. Sequences are detected
    using a range of byte matching and regular expressions. This sequence
    padding code been tested thoroughly on ANSI Art from the "Dark Domains"
    DVD by "ACiD Productions". Example usage:
    
    >> import blessings
    >> t = blessings.Terminal()
    >>> for num, byte in enumerate('Pony Express, Choo! CHooooooOOoooOOo!'):
    ...    seq += t.color(num % 7) + t.bold + byte + t.normal
    >>> import textwrap
    >>> print u'\n'.join(textwrap.wrap(seq, 15))
    
    (as you can see, textwrap fails horribly !!)
    
    >>> print u'\n'.join(t.wrap(seq, 15))
    Pony Express,
    Choo!
    CHooooooOOoooOOo!
    
    winning !!
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    f366cc8 View commit details
    Browse the repository at this point in the history
  3. Fix center, ljust, rjust

    Continuing the example from the previous commit, it is now possible:
    
    >>> print t.center(seq)
                         Pony Express, Choo! CHooooooOOoooOOo!
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    f1a3cf1 View commit details
    Browse the repository at this point in the history
  4. re-shuffle .center, .ljust, and .rjust

    Instantate AnsiString from Terminal, so AnsiString contains these
    padding methods, requires less instantiation.
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    0ef2233 View commit details
    Browse the repository at this point in the history
  5. match spacing styling

    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    9d7b4d0 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    77ecb9c View commit details
    Browse the repository at this point in the history
  7. static import for fcntl, will use fcntl.fcntl,

    also readability from pexpect
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    982192d View commit details
    Browse the repository at this point in the history
  8. Implement 'inkey_enabled' context manager

    * add _conanical and _echo terminal state helpers and related functions.
    * remove another magic bit, '27', by explicitly setting to curses.ascii.ESC
    * fix for incremental decoder
    * add warning for failed decodes in _resolve_multibyte
    * placeholder for inkey() with docstrings of expected behavior
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    cd5ae7d View commit details
    Browse the repository at this point in the history
  9. readability only

    use tty.LFLAGS instead of magic attrs[3] bit. Also rename 'attrs' references to 'mode' to match python standard module naming conv.
    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    a1d97c8 View commit details
    Browse the repository at this point in the history
  10. docfix

    jquast committed Apr 11, 2013
    Configuration menu
    Copy the full SHA
    e803a44 View commit details
    Browse the repository at this point in the history

Commits on Apr 12, 2013

  1. implement complete keyboard handling, win32 support ?

    in the usual style of mine, fully written but not yet run, this intermittent commit has complete docstrings for the interface in mind.
    
    I haven't a win32 platform, but diligent effort was made to support it.
    This commit also includes a possible fix for windows systems to determine the terminal height and width without calls to fcntl.
    
    - remove unused defaultdict import
    - refactor input stream key capability from __init__ to
      _init_keystrokes()
    - remove redundant input key capability definitions
    - store _state_echo and _state_canonical; necessary for win32 systems
    - refactor term.stream to term.o_stream to accompany term.i_stream
    - refactor documented @Property, do_style
    - refactor _resolve_multibyte to _resolve_msb, consistent reference
      'MSB' can be either 'escape sequence' for application keys, or utf-8 bytes
      as part of a hamsterface emoticon.
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    7d1668c View commit details
    Browse the repository at this point in the history
  2. syntax fixes

    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    619ae9e View commit details
    Browse the repository at this point in the history
  3. many various fixes

    getch() so far works in non-conanical mode, as unimpressive as it is.
    
    various issues with multibyte sequence decoding, currently looks like
    the loop timing and buffering at issue.
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    50241f0 View commit details
    Browse the repository at this point in the history
  4. unset canonical or echo on __del__

    This is what the curses wrapper is missing; it is very obnoxious when developing curses when your program crashes, you have to type 'reset' after each crash
    
    That's fine, we simply check the state and always restore it on __del__. If python throws an exception and kicks you out while the terminal is in cbreak mode, a warning is issued to let you know it was restored after doing so.
    
    This will appear after your traceback. So it won't be any suprised as to what happened.
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    c234619 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    4697a0f View commit details
    Browse the repository at this point in the history
  6. remove MSB decode warning, as we aggressively test

    also sprinly various print debugs for MSB, there is a timing issue related to the 2nd byte of a '\x1b[A' sequence failing the kbhit() check. I think i've seen this before, has to do with flushing something correctly at a particular time? will look tomorrow.
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    93810b8 View commit details
    Browse the repository at this point in the history
  7. add this temporary test script

    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    1f4d101 View commit details
    Browse the repository at this point in the history
  8. py2.5 compat

    remove @property.setter, not python 2.5 compatible.
    
    do_styling remains a property, but read-only !
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    6997889 View commit details
    Browse the repository at this point in the history
  9. remove __del__, revert window size to old behavior

    That is, for win32 systems, if the new height & width returns 0, then the old behavior of trying to use termios is used..
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    99f1aff View commit details
    Browse the repository at this point in the history
  10. change o_stream back to stream

    so that the tests don't have to be updated
    also a fix for o_fd/decriptor
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    f34d972 View commit details
    Browse the repository at this point in the history
  11. uncommit debug in test

    was trying to figure out why this test failed for so long, but I was running it with 'nose 2>&1 | less' -- no wonder, output was not a tty...
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    19005bd View commit details
    Browse the repository at this point in the history
  12. finished input! Go ahead; kick the tires!

    For the longest time, the 2nd byte in a multibyte sequence was blocking on select. I discovered using i_stream.read(1) does not interact with the VMIN and VTIME set for cbreak mode on terminals connected to the stream. a call using os.read(i_stream.fileno(), 1) resolved this.
    
    - is_a_tty class attribute changed to property. This brevities the
      documentation and interface, certainly enforcing the concept that
      this property is read-only!
    - the input stream is *always* stdin.
    - helped comment the whys and whats of __init__, about fd's, curses, etc.
    - remove list comprehension, fix bug with _keycodes being empty
    - only detect input encoding if stream is connected to a tty, otherwise
      it is not necessary to detect encoding of multibyte input, as we can't
      support interactive keyboard input on non-ttys.
    - try to cleanup _height_and_width win32 support.
    - however; removed the windows getch() and kbhit() until it can be tried ..
    - removed the debug prints since inkey appears to work now
    - removed the excessive delve into termios, using only tty.setcbreak()
      and restoring original terminal settings in finally: clause
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    726ce6b View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    eaa2955 View commit details
    Browse the repository at this point in the history
  14. create comprehensive *human* test interface

    doubles as a video game
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    e0730ff View commit details
    Browse the repository at this point in the history
  15. improve comments

    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    3588ed9 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    2482606 View commit details
    Browse the repository at this point in the history
  17. pep8 compliance; 79-col wrapping for better pydoc

    also snuck a kbhit() timing fix, woops
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    5db146c View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    b6eff3e View commit details
    Browse the repository at this point in the history
  19. backspace fix

    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    9aa1f39 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    e44f08f View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    db90d03 View commit details
    Browse the repository at this point in the history
  22. add test for _seqlen

    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    c8c704d View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    ed0b3f5 View commit details
    Browse the repository at this point in the history
  24. add test case for _is_movement

    caught \033#8, my favorite 'fill the screen' sequence. not that anyone would have noticed.
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    56dbd5a View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    a896f7f View commit details
    Browse the repository at this point in the history
  26. add test for t.wrap

    passed w/flying colors ..
    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    8d2ba43 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    68f16ba View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    3a909ec View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    7dfb756 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    e00efb8 View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    08e535a View commit details
    Browse the repository at this point in the history
  32. same fix for other test

    jquast committed Apr 12, 2013
    Configuration menu
    Copy the full SHA
    a2c157c View commit details
    Browse the repository at this point in the history

Commits on Apr 13, 2013

  1. fix for python 2.5 textwrap

    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    a7aa242 View commit details
    Browse the repository at this point in the history
  2. make test paragraph slightly smaller

    (take a byte out of i/o crime!)
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    85868d8 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    937f10f View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e199f4b View commit details
    Browse the repository at this point in the history
  5. add nother *human* test for animations

    this is really just a test of timing performance, revived an old alogorithm i made as a kid and wrapped it into a simple game, called "newton's nightmare".
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    277cb50 View commit details
    Browse the repository at this point in the history
  6. make newton's nightmare more interesting

    add a new planet? every 50 points.
    
    really should track the tracers and keep only the 10th last.
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    32b703c View commit details
    Browse the repository at this point in the history
  7. better animations

    leave only a limited tail length using a stack of unique screen positions
    die animation !
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    4b1d7b5 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    f684e2d View commit details
    Browse the repository at this point in the history
  9. mnumonic fix; bad attr

    also add SUP/SDOWN/SLEFT/SRIGHT to game for testing
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    0c51b54 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    22b2cc6 View commit details
    Browse the repository at this point in the history
  11. better looks

    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    a4c62d4 View commit details
    Browse the repository at this point in the history
  12. random velocity fix

    velocity was always in Down-right direction, now can be any.
    also change the 'your score' to be term.height -3, and use term.clear_eol
    
    this game is pretty fun !
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    85ec2f7 View commit details
    Browse the repository at this point in the history
  13. fix for kbhit(0)

    do not allow negative numbers to pass to select
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    5b6c4c6 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    83798cb View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    59ea95f View commit details
    Browse the repository at this point in the history
  16. todo tests

    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    f616114 View commit details
    Browse the repository at this point in the history
  17. add timing tests of input using pexpect

    pexpect gives us a real pty; will travis-ci allows it?
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    5cbb2d8 View commit details
    Browse the repository at this point in the history
  18. refactor resolve_mbs; improve test cases

    make unicode decoding more internal, but externally exposed and documented
    through the encoding parameter. further improving pexpect test cases.
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    1616da7 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    1caec63 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    54c1fd2 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    f1e4d45 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    d88e249 View commit details
    Browse the repository at this point in the history
  23. complete mouse tracking extended modes

    the default mode is a comprimise of the most compatible and most capable and documented well.
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    4f76056 View commit details
    Browse the repository at this point in the history
  24. add human test for mouse tracking feature

    go ahead, draw a box ...
    jquast committed Apr 13, 2013
    Configuration menu
    Copy the full SHA
    f02f818 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    44fe0c3 View commit details
    Browse the repository at this point in the history

Commits on Apr 14, 2013

  1. add mouse scroll tracking test

    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    d72f279 View commit details
    Browse the repository at this point in the history
  2. add a game of pong

    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    5933088 View commit details
    Browse the repository at this point in the history
  3. broad and comprehensive _is_movement tests

    also brought a few changes to WILL_MOVE, WONT_MOVE
    also assert TypeError for non-ints for things like term.move(1.0)
    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    11a309c View commit details
    Browse the repository at this point in the history
  4. possible fix for python 2.5?

    my nose for python 2.5 doesn't seem to work
    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    133fd9c View commit details
    Browse the repository at this point in the history
  5. minor TypeError friendly msg fix for mised strings

    plus a test case, and disable the float exception testing,
    as it fails on older python where only a DeprecationWarning is emitted
    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    fe92ffe View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    e57e8a1 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    bd62d89 View commit details
    Browse the repository at this point in the history
  8. polish off pong.

    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    7c94c4c View commit details
    Browse the repository at this point in the history
  9. demo correct use of KEY_EXIT

    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    1ecc3cb View commit details
    Browse the repository at this point in the history
  10. make msg 79-column friendly

    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    8137f93 View commit details
    Browse the repository at this point in the history
  11. more polish on pong

    jquast committed Apr 14, 2013
    Configuration menu
    Copy the full SHA
    2a0e316 View commit details
    Browse the repository at this point in the history