Python curses 模块,ascii() 实例源码

我们从Python开源项目中,提取了以下40个代码示例,用于说明如何使用curses.ascii()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            # Possible reference before assignment fix
            oldch = None
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def setTextBuffer(self, textBuffer):
    app.controller.Controller.setTextBuffer(self, textBuffer)
    normalCommandSet = {
      ord('^'): textBuffer.cursorStartOfLine,
      ord('$'): textBuffer.cursorEndOfLine,
      ord('h'): textBuffer.cursorLeft,
      ord('i'): self.switchToCommandSetInsert,
      ord('j'): textBuffer.cursorDown,
      ord('k'): textBuffer.cursorUp,
      ord('l'): textBuffer.cursorRight,
    }
    self.commandSet = normalCommandSet
    self.commandSet_Insert = {
      curses.ascii.ESC: self.switchToCommandSetNormal,
    }
    self.commandDefault = self.textBuffer.insertPrintable
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def _insert_printable_char(self, ch):
        (y, x) = self.win.getyx()
        if y < self.maxy or x < self.maxx:
            if self.insert_mode:
                oldch = self.win.inch()
            # The try-catch ignores the error we trigger from some curses
            # versions by trying to write into the lowest-rightmost spot
            # in the window.
            try:
                self.win.addch(ch)
            except curses.error:
                pass
            if self.insert_mode:
                (backy, backx) = self.win.getyx()
                if curses.ascii.isprint(oldch):
                    self._insert_printable_char(oldch)
                    self.win.move(backy, backx)
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def CTRL(key):
    return curses.ascii.ctrl(key)
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def keys_init_noedit(self):
        """Define methods for each key for non-editing mode.

        """
        self.keys = {
            curses.ascii.ETX:               self.close,
            curses.KEY_DOWN:                self.down_noedit,
            CTRL('n'):                      self.down_noedit,
            'j':                            self.down_noedit,
            curses.KEY_F1:                  self.help,
            curses.KEY_NPAGE:               self.page_down,
            'J':                            self.page_down,
            CTRL('f'):                      self.page_up,
            curses.KEY_PPAGE:               self.page_up,
            'K':                            self.page_up,
            CTRL('b'):                      self.page_up,
            CTRL('x'):                      self.quit,
            curses.KEY_F2:                  self.quit,
            curses.KEY_F3:                  self.quit_nosave,
            curses.ascii.ESC:               self.quit_nosave,
            curses.KEY_RESIZE:              self.resize,
            -1:                             self.resize,
            curses.KEY_UP:                  self.up_noedit,
            CTRL('p'):                      self.up_noedit,
            'k':                            self.up_noedit,
        }
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def __init__(self, win, insert_mode=False, text=''):
        Textbox.__init__(self, win, insert_mode)

        for chr in text:
            if chr == '\n':
                Textbox.do_command(self, curses.ascii.NL)
            else:
                Textbox.do_command(self, chr)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def test_menu_textentryitem__eot_deletion(self):
        """Test that the input_caller returns the expected string value."""
        curses.initscr()
        curses.ungetch("\n")
        curses.ungetch("a")
        curses.ungetch(curses.ascii.EOT)
        curses.ungetch(curses.ascii.EOT)
        curses.ungetch(curses.KEY_LEFT)
        curses.ungetch(curses.ascii.EOT)
        curses.ungetch(curses.KEY_LEFT)
        curses.ungetch("a")
        curses.ungetch("a")
        self.textentryitem()
        self.assertEqual(self.textentryitem.get_value(), "a")
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def test_menu_textentryitem__ascii_bel(self):
        """Test that the input_caller returns the expected string value."""
        curses.initscr()
        curses.ungetch("\n")
        curses.ungetch(curses.ascii.BEL)
        # BEL is a non-printable character so the return value should be an empty string
        self.textentryitem()
        self.assertEqual(self.textentryitem.get_value(), "")
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last + 1)
                break
            elif last == 0:
                break
            last -= 1
        return last
项目:aws-ec2rescue-linux    作者:awslabs    | 项目源码 | 文件源码
def gather(self):
        """Collect and return the contents of the window."""
        result = ""
        for y in range(self.maxy + 1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx + 1):
                if self.stripspaces and x > stop:
                    break
                result += chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result += "\n"
        return result
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def get_key(self):
        code = self.win.getch()
        if code > 0:
            # Accept newline and carriage return as enter key
            if code == curses.ascii.NL or code == curses.ascii.CR:
                code = curses.KEY_ENTER

            # Accept newline and carriage return as enter key
            if code == curses.ascii.BS:
                code = curses.KEY_BACKSPACE

            return code
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def on_key(self, ch):
        x = self.pos

        # ascii 32-126 (inclusive)
        if curses.ascii.isprint(ch):
            if len(self.value) < self.max_length:
                self.value = self.value[:x] + chr(ch) + self.value[x:]
                self.pos += 1

        elif ch == curses.KEY_LEFT:
            if x > 0:
                self.pos -= 1

        elif ch == curses.KEY_RIGHT:
            if x < len(self.value):
                self.pos += 1

        elif ch == curses.KEY_BACKSPACE:
            if x > 0:
                self.value = self.value[:x - 1] + self.value[x:]
                self.pos -= 1

        elif ch == curses.KEY_DC:
            if x < len(self.value):
                self.value = self.value[:x] + self.value[x + 1:]

        elif ch == curses.KEY_HOME:
            self.pos = 0

        elif ch == curses.KEY_END:
            self.pos = len(self.value)

        else:
            return False

        self.update()
        return True
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def on_key(self, ch):
        if not self.active:
            return

        if self.selected:
            if ch in (curses.ascii.ESC, curses.KEY_BACKSPACE):
                self.cancel_selection()

            elif ch == curses.KEY_LEFT:
                if self.selection > 0 and self.selection < 4 or self.selection > 4:
                    self.set_selection(self.selection - 1)

            elif ch == curses.KEY_RIGHT:
                if self.selection < 3 or self.selection > 3 and self.selection < 7:
                    self.set_selection(self.selection + 1)

            elif ch == curses.KEY_UP:
                if self.selection > 3:
                    self.set_selection(self.selection - 4)

            elif ch == curses.KEY_DOWN:
                if self.selection < 4 and self.selected_source == 'hand':
                    self.set_selection(self.selection + 4)

            elif ch in (curses.KEY_ENTER, curses.ascii.SP):
                self.confirm_selection()

        else:
            if ch == curses.KEY_LEFT:
                if self.selection > 0:
                    self.set_selection(self.selection - 1)

            elif ch == curses.KEY_RIGHT:
                if self.selection + 1 < len(self.selectable_sources):
                    self.set_selection(self.selection + 1)

            elif ch in (curses.KEY_ENTER, curses.ascii.SP):
                self.confirm_selection()
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:wpm    作者:cslarsen    | 项目源码 | 文件源码
def is_escape(self, key):
        if len(key) == 1:
            return ord(key) == curses.ascii.ESC
        return False
项目:wpm    作者:cslarsen    | 项目源码 | 文件源码
def is_backspace(self, key):
        if len(key) > 1:
            return key == "KEY_BACKSPACE"
        elif ord(key) in (curses.ascii.BS, curses.ascii.DEL):
            return True
        return False
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def _end_of_line(self, y):
        """Go to the location of the first blank on the given line,
        returning the index of the last non-blank character."""
        last = self.maxx
        while True:
            if curses.ascii.ascii(self.win.inch(y, last)) != curses.ascii.SP:
                last = min(self.maxx, last+1)
                break
            elif last == 0:
                break
            last = last - 1
        return last
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def gather(self):
        "Collect and return the contents of the window."
        result = ""
        for y in range(self.maxy+1):
            self.win.move(y, 0)
            stop = self._end_of_line(y)
            if stop == 0 and self.stripspaces:
                continue
            for x in range(self.maxx+1):
                if self.stripspaces and x > stop:
                    break
                result = result + chr(curses.ascii.ascii(self.win.inch(y, x)))
            if self.maxy > 0:
                result = result + "\n"
        return result
项目:notex    作者:adiultra    | 项目源码 | 文件源码
def keys_init(self):
        """Define methods for each key.

        """
        self.keys = {
            curses.KEY_BACKSPACE:           self.backspace,
            CTRL('h'):                      self.backspace,
            curses.ascii.BS:                self.backspace,
            curses.ascii.DEL:               self.backspace,
            curses.ascii.ETX:               self.close,
            curses.KEY_DC:                  self.del_char,
            CTRL('d'):                      self.del_char,
            CTRL('u'):                      self.del_to_bol,
            CTRL('k'):                      self.del_to_eol,
            curses.KEY_DOWN:                self.down,
            CTRL('n'):                      self.down,
            curses.KEY_END:                 self.end,
            CTRL('e'):                      self.end,
            curses.KEY_F1:                  self.help,
            curses.KEY_HOME:                self.home,
            CTRL('a'):                      self.home,
            curses.KEY_ENTER:               self.insert_line_or_quit,
            curses.ascii.NL:                self.insert_line_or_quit,
            curses.ascii.LF:                self.insert_line_or_quit,
            "\n":                           self.insert_line_or_quit,
            curses.KEY_LEFT:                self.left,
            CTRL('b'):                      self.left,
            curses.KEY_NPAGE:               self.page_down,
            curses.KEY_PPAGE:               self.page_up,
            CTRL('v'):                      self.paste,
            CTRL('x'):                      self.quit,
            curses.KEY_F2:                  self.quit,
            curses.KEY_F3:                  self.quit_nosave,
            curses.ascii.ESC:               self.quit_nosave,
            curses.KEY_RESIZE:              self.resize,
            -1:                             self.resize,
            curses.KEY_RIGHT:               self.right,
            CTRL('f'):                      self.right,
            curses.KEY_UP:                  self.up,
            CTRL('p'):                      self.up,
        }
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def on_key(self, ch):
        if not self.active or self.disabled:
            return

        if not self.active.on_key(ch):
            y, x = self.position(self.active)

            if ch == curses.KEY_UP:
                if y > 0:
                    self.set_active(self.rows[y - 1][self.defaults[y - 1]])

            elif ch in (curses.KEY_DOWN, curses.KEY_ENTER):
                if y < len(self.rows) - 1:
                    self.set_active(self.rows[y + 1][self.defaults[y + 1]])

            elif ch == curses.KEY_LEFT:
                if x > 0:
                    self.set_active(self.rows[y][x - 1])

            elif ch == curses.KEY_RIGHT:
                if x < len(self.rows[y]) - 1:
                    self.set_active(self.rows[y][x + 1])

            elif ch == curses.ascii.TAB:
                # Right
                if x < len(self.rows[y]) - 1:
                    self.set_active(self.rows[y][x + 1])
                # Down, ignoring defaults
                elif y < len(self.rows) - 1:
                    self.set_active(self.rows[y + 1][0])
                else:
                    self.set_active(self.rows[0][0])

            elif ch == curses.KEY_BTAB:
                # Left
                if x > 0:
                    self.set_active(self.rows[y][x - 1])
                # Up
                elif y > 0:
                    col = len(self.rows[y - 1]) - 1
                    self.set_active(self.rows[y - 1][col])
                else:
                    row = len(self.rows) - 1
                    col = len(self.rows[row]) - 1
                    self.set_active(self.rows[row][col])