How to use the birdears.urwid.escape function in birdears

To help you get started, we’ve selected a few birdears examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iacchus / birdears / birdears / urwid / curses_display.py View on Github external
append_button( 0 )
            next |= 1
        if bstate & curses.BUTTON2_PRESSED and last & 2 == 0:
            append_button( 1 )
            next |= 2
        if bstate & curses.BUTTON3_PRESSED and last & 4 == 0:
            append_button( 2 )
            next |= 4
        if bstate & curses.BUTTON4_PRESSED and last & 8 == 0:
            append_button( 64 )
            next |= 8
        if bstate & curses.BUTTON1_RELEASED and last & 1:
            append_button( 0 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 1
        if bstate & curses.BUTTON2_RELEASED and last & 2:
            append_button( 1 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 2
        if bstate & curses.BUTTON3_RELEASED and last & 4:
            append_button( 2 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 4
        if bstate & curses.BUTTON4_RELEASED and last & 8:
            append_button( 64 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 8

        if bstate & curses.BUTTON1_DOUBLE_CLICKED:
            append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON2_DOUBLE_CLICKED:
            append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON3_DOUBLE_CLICKED:
            append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON4_DOUBLE_CLICKED:
            append_button( 64 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
github iacchus / birdears / birdears / urwid / raw_display.py View on Github external
on Python 3.
        """
        # Note: event_loop may be None for 100% synchronous support, only used
        # by get_input.  Not documented because you shouldn't be doing it.
        if self._input_timeout and event_loop:
            event_loop.remove_alarm(self._input_timeout)
            self._input_timeout = None

        original_codes = codes
        processed = []
        try:
            while codes:
                run, codes = escape.process_keyqueue(
                    codes, wait_for_more)
                processed.extend(run)
        except escape.MoreInputRequired:
            # Set a timer to wait for the rest of the input; if it goes off
            # without any new input having come in, use the partial input
            k = len(original_codes) - len(codes)
            processed_codes = original_codes[:k]
            self._partial_codes = codes

            def _parse_incomplete_input():
                self._input_timeout = None
                self._partial_codes = None
                self.parse_input(
                    event_loop, callback, codes, wait_for_more=False)
            if event_loop:
                self._input_timeout = event_loop.alarm(
                    self.complete_wait, _parse_incomplete_input)

        else:
github iacchus / birdears / birdears / urwid / raw_display.py View on Github external
def set_cursor_position(x, y):
            if not partial_display():
                return escape.set_cursor_position(x, y)
            if cy > y:
                return ('\b' + escape.CURSOR_HOME_COL +
                    escape.move_cursor_up(cy - y) +
                    escape.move_cursor_right(x))
            return ('\b' + escape.CURSOR_HOME_COL +
                escape.move_cursor_down(y - cy) +
                escape.move_cursor_right(x))
github iacchus / birdears / birdears / urwid / raw_display.py View on Github external
def set_cursor_home():
            if not partial_display():
                return escape.set_cursor_position(0, 0)
            return (escape.CURSOR_HOME_COL +
                escape.move_cursor_up(cy))
github iacchus / birdears / birdears / urwid / util.py View on Github external
#    Lesser General Public License for more details.
#
#    You should have received a copy of the GNU Lesser General Public
#    License along with this library; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Urwid web site: http://excess.org/urwid/

from __future__ import division, print_function

from ..urwid import escape
from ..urwid.compat import bytes, text_type, text_types

import codecs

str_util = escape.str_util

# bring str_util functions into our namespace
calc_text_pos = str_util.calc_text_pos
calc_width = str_util.calc_width
is_wide_char = str_util.is_wide_char
move_next_char = str_util.move_next_char
move_prev_char = str_util.move_prev_char
within_double_byte = str_util.within_double_byte


def detect_encoding():
    # Try to determine if using a supported double-byte encoding
    import locale
    try:
        try:
            locale.setlocale(locale.LC_ALL, "")
github iacchus / birdears / birdears / urwid / raw_display.py View on Github external
`codes` should be a sequence of keycodes, i.e. bytes.  A bytearray is
        appropriate, but beware of using bytes, which only iterates as integers
        on Python 3.
        """
        # Note: event_loop may be None for 100% synchronous support, only used
        # by get_input.  Not documented because you shouldn't be doing it.
        if self._input_timeout and event_loop:
            event_loop.remove_alarm(self._input_timeout)
            self._input_timeout = None

        original_codes = codes
        processed = []
        try:
            while codes:
                run, codes = escape.process_keyqueue(
                    codes, wait_for_more)
                processed.extend(run)
        except escape.MoreInputRequired:
            # Set a timer to wait for the rest of the input; if it goes off
            # without any new input having come in, use the partial input
            k = len(original_codes) - len(codes)
            processed_codes = original_codes[:k]
            self._partial_codes = codes

            def _parse_incomplete_input():
                self._input_timeout = None
                self._partial_codes = None
                self.parse_input(
                    event_loop, callback, codes, wait_for_more=False)
            if event_loop:
                self._input_timeout = event_loop.alarm(
github iacchus / birdears / birdears / urwid / raw_display.py View on Github external
if b & 2 and last & 2 == 0:
                append_button( 1 )
                next |= 2
            if b & 1 and last & 4 == 0:
                append_button( 2 )
                next |= 4
        elif ev == 146: # drag
            if b & 4:
                append_button( 0 + escape.MOUSE_DRAG_FLAG )
            elif b & 2:
                append_button( 1 + escape.MOUSE_DRAG_FLAG )
            elif b & 1:
                append_button( 2 + escape.MOUSE_DRAG_FLAG )
        else: # release
            if b & 4 and last & 1:
                append_button( 0 + escape.MOUSE_RELEASE_FLAG )
                next &= ~ 1
            if b & 2 and last & 2:
                append_button( 1 + escape.MOUSE_RELEASE_FLAG )
                next &= ~ 2
            if b & 1 and last & 4:
                append_button( 2 + escape.MOUSE_RELEASE_FLAG )
                next &= ~ 4
        if ev == 40: # double click (release)
            if b & 4 and last & 1:
                append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
            if b & 2 and last & 2:
                append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
            if b & 1 and last & 4:
                append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        elif ev == 52:
            if b & 4 and last & 1:
github iacchus / birdears / birdears / urwid / curses_display.py View on Github external
append_button( 2 )
            next |= 4
        if bstate & curses.BUTTON4_PRESSED and last & 8 == 0:
            append_button( 64 )
            next |= 8
        if bstate & curses.BUTTON1_RELEASED and last & 1:
            append_button( 0 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 1
        if bstate & curses.BUTTON2_RELEASED and last & 2:
            append_button( 1 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 2
        if bstate & curses.BUTTON3_RELEASED and last & 4:
            append_button( 2 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 4
        if bstate & curses.BUTTON4_RELEASED and last & 8:
            append_button( 64 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 8

        if bstate & curses.BUTTON1_DOUBLE_CLICKED:
            append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON2_DOUBLE_CLICKED:
            append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON3_DOUBLE_CLICKED:
            append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON4_DOUBLE_CLICKED:
            append_button( 64 + escape.MOUSE_MULTIPLE_CLICK_FLAG )

        if bstate & curses.BUTTON1_TRIPLE_CLICKED:
            append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 )
        if bstate & curses.BUTTON2_TRIPLE_CLICKED:
            append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 )
        if bstate & curses.BUTTON3_TRIPLE_CLICKED:
github iacchus / birdears / birdears / urwid / curses_display.py View on Github external
next &= ~ 2
        if bstate & curses.BUTTON3_RELEASED and last & 4:
            append_button( 2 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 4
        if bstate & curses.BUTTON4_RELEASED and last & 8:
            append_button( 64 + escape.MOUSE_RELEASE_FLAG )
            next &= ~ 8

        if bstate & curses.BUTTON1_DOUBLE_CLICKED:
            append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON2_DOUBLE_CLICKED:
            append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON3_DOUBLE_CLICKED:
            append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG )
        if bstate & curses.BUTTON4_DOUBLE_CLICKED:
            append_button( 64 + escape.MOUSE_MULTIPLE_CLICK_FLAG )

        if bstate & curses.BUTTON1_TRIPLE_CLICKED:
            append_button( 0 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 )
        if bstate & curses.BUTTON2_TRIPLE_CLICKED:
            append_button( 1 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 )
        if bstate & curses.BUTTON3_TRIPLE_CLICKED:
            append_button( 2 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 )
        if bstate & curses.BUTTON4_TRIPLE_CLICKED:
            append_button( 64 + escape.MOUSE_MULTIPLE_CLICK_FLAG*2 )

        self.last_bstate = next
        return l
github iacchus / birdears / birdears / urwid / raw_display.py View on Github external
"4;" * a.underline + "5;" * a.blink +
              "7;" * a.standout + "9;" * a.strikethrough)
        if a.background_high:
            bg = "48;5;%d" % a.background_number
        elif a.background_basic:
            if a.background_number > 7:
                if self.bg_bright_is_blink:
                    bg = "5;%d" % (a.background_number - 8 + 40)
                else:
                    # this doesn't work on most terminals
                    bg = "%d" % (a.background_number - 8 + 100)
            else:
                bg = "%d" % (a.background_number + 40)
        else:
            bg = "49"
        return escape.ESC + "[0;%s;%s%sm" % (fg, st, bg)