예제 #1
0
    def _get_completions(self):
        """Return a list of possible completions for the string ending at the point.

        Also set begidx and endidx in the process.
        """
        completions = []
        self.begidx = self.l_buffer.point
        self.endidx = self.l_buffer.point
        buf = self.l_buffer.line_buffer
        if self.completer:
            # get the string to complete
            while self.begidx > 0:
                self.begidx -= 1
                if buf[self.begidx] in self.completer_delims:
                    self.begidx += 1
                    break
            text = ensure_str("".join(buf[self.begidx: self.endidx]))
            log('complete text="%s"' % ensure_unicode(text))
            i = 0
            while 1:
                try:
                    r = self.completer(ensure_unicode(text), i)
                except IndexError:
                    break
                i += 1
                if r is None:
                    break
                elif r and r not in completions:
                    completions.append(r)
                else:
                    pass
            log("text completions=<%s>" %
                list(map(ensure_unicode, completions)))
        if (self.complete_filesystem == "on") and not completions:
            # get the filename to complete
            while self.begidx > 0:
                self.begidx -= 1
                if buf[self.begidx] in " \t\n":
                    self.begidx += 1
                    break
            text = ensure_str("".join(buf[self.begidx: self.endidx]))
            log('file complete text="%s"' % ensure_unicode(text))
            completions = list(
                map(
                    ensure_unicode,
                    glob.glob(os.path.expanduser(text) + "*".encode("ascii")),
                )
            )
            if self.mark_directories == "on":
                mc = []
                for f in completions:
                    if os.path.isdir(f):
                        mc.append(f + os.sep)
                    else:
                        mc.append(f)
                completions = mc
            log("fnames=<%s>" % list(map(ensure_unicode, completions)))
        return completions
예제 #2
0
 def _get_completions(self):
     """Return a list of possible completions for the string ending at the point.
     Also set begidx and endidx in the process."""
     completions = []
     self.begidx = self.l_buffer.point
     self.endidx = self.l_buffer.point
     buf = self.l_buffer.line_buffer
     if self.completer:
         # get the string to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in self.completer_delims:
                 self.begidx += 1
                 break
         text = ensure_str(''.join(buf[self.begidx:self.endidx]))
         log('complete text="%s"' % ensure_unicode(text))
         i = 0
         while 1:
             try:
                 r = self.completer(ensure_unicode(text), i)
             except IndexError:
                 break
             except AttributeError:
                 # This is a quick hotfix, completer throws an error whenever
                 # it finds nothing.
                 break
             i += 1
             if r is None:
                 break
             elif r and r not in completions:
                 completions.append(r)
             else:
                 pass
         log('text completions=<%s>' %
             list(map(ensure_unicode, completions)))
     if (self.complete_filesystem == "on") and not completions:
         # get the filename to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in ' \t\n':
                 self.begidx += 1
                 break
         text = ensure_str(''.join(buf[self.begidx:self.endidx]))
         log('file complete text="%s"' % ensure_unicode(text))
         completions = list(
             map(ensure_unicode,
                 glob.glob(os.path.expanduser(text) + '*'.encode('ascii'))))
         if self.mark_directories == 'on':
             mc = []
             for f in completions:
                 if os.path.isdir(f):
                     mc.append(f + os.sep)
                 else:
                     mc.append(f)
             completions = mc
         log('fnames=<%s>' % list(map(ensure_unicode, completions)))
     return completions
예제 #3
0
 def write_plain(self, text, attr=None):
     u"""write text at current cursor position."""
     text = ensure_unicode(text)
     log(u'write("%s", %s)' % (text, attr))
     if attr is None:
         attr = self.attr
     junk = DWORD(0)
     self.SetConsoleTextAttribute(self.hout, attr)
     for short_chunk in split_block(chunk):
         self.WriteConsoleW(self.hout, ensure_unicode(short_chunk), len(short_chunk), byref(junk), None)
     return len(text)
예제 #4
0
    def write_plain(self, text, attr=None):
        text = ensure_unicode(text)
        log('write("%s", %s)' % (text, attr))
        if attr is None:
            attr = self.attr
        junk = DWORD(0)
        self.SetConsoleTextAttribute(self.hout, attr)
        for short_chunk in split_block(chunk):
            self.WriteConsoleW(self.hout, ensure_unicode(short_chunk),
                               len(short_chunk), byref(junk), None)

        return len(text)
예제 #5
0
 def write_plain(self, text, attr=None):
     u'''write text at current cursor position.'''
     text = ensure_unicode(text)
     log(u'write("%s", %s)' % (text, attr))
     if attr is None:
         attr = self.attr
     n = c_int(0)
     self.SetConsoleTextAttribute(self.hout, attr)
     for short_chunk in split_block(chunk):
         self.WriteConsoleW(self.hout, ensure_unicode(short_chunk),
                            len(short_chunk), byref(junk), None)
     return len(text)
예제 #6
0
 def _get_completions(self):
     """Return a list of possible completions for the string ending at the point.
     Also set begidx and endidx in the process."""
     completions = []
     self.begidx = self.l_buffer.point
     self.endidx = self.l_buffer.point
     buf=self.l_buffer.line_buffer
     if self.completer:
         # get the string to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in self.completer_delims:
                 self.begidx += 1
                 break
         text = ensure_str(''.join(buf[self.begidx:self.endidx]))
         log('complete text="%s"' % ensure_unicode(text))
         i = 0
         while 1:
             try:
                 r = self.completer(ensure_unicode(text), i)
             except IndexError:
                 break
             except TypeError:
                 break
             i += 1
             if r is None:
                 break
             elif r and r not in completions:
                 completions.append(r)
             else:
                 pass
         log('text completions=<%s>' % list(map(ensure_unicode, completions)))
     if (self.complete_filesystem == "on") and not completions:
         # get the filename to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in ' \t\n':
                 self.begidx += 1
                 break
         text = ensure_str(''.join(buf[self.begidx:self.endidx]))
         log('file complete text="%s"' % ensure_unicode(text))
         completions = list(map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'.encode('ascii'))))
         if self.mark_directories == 'on':
             mc = []
             for f in completions:
                 if os.path.isdir(f):
                     mc.append(f + os.sep)
                 else:
                     mc.append(f)
             completions = mc
         log('fnames=<%s>' % list(map(ensure_unicode, completions)))
     return completions
예제 #7
0
 def _get_completions(self):
     """Return a list of possible completions for the string ending at the point.
     Also set begidx and endidx in the process."""
     completions = []
     self.begidx = self.l_buffer.point
     self.endidx = self.l_buffer.point
     buf = self.l_buffer.line_buffer
     if self.completer:
         # get the string to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in self.completer_delims:
                 self.begidx += 1
                 break
         text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
         log(u'complete text="%s"' % ensure_unicode(text))
         i = 0
         while 1:
             try:
                 r = ensure_unicode(self.completer(text, i))
             except:
                 break
             i += 1
             if r and r not in completions:
                 completions.append(r)
             else:
                 break
         log(u'text completions=<%s>' % map(ensure_unicode, completions))
     if not completions:
         # get the filename to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in u' \t\n':
                 self.begidx += 1
                 break
         text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
         log(u'file complete text="%s"' % ensure_unicode(text))
         completions = map(ensure_unicode,
                           glob.glob(os.path.expanduser(text) + '*'))
         if self.mark_directories == u'on':
             mc = []
             for f in completions:
                 if os.path.isdir(f):
                     mc.append(f + os.sep)
                 else:
                     mc.append(f)
             completions = mc
         log(u'fnames=<%s>' % map(ensure_unicode, completions))
     return completions
예제 #8
0
 def _get_completions(self):
     """Return a list of possible completions for the string ending at the point.
     Also set begidx and endidx in the process."""
     completions = []
     self.begidx = self.l_buffer.point
     self.endidx = self.l_buffer.point
     buf=self.l_buffer.line_buffer
     if self.completer:
         # get the string to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in self.completer_delims:
                 self.begidx += 1
                 break
         text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
         log(u'complete text="%s"' % ensure_unicode(text))
         i = 0
         while 1:
             try:
                 r = ensure_unicode(self.completer(text, i))
             except:
                 break
             i += 1
             if r and r not in completions:
                 completions.append(r)
             else:
                 break
         log(u'text completions=<%s>' % map(ensure_unicode, completions))
     if not completions:
         # get the filename to complete
         while self.begidx > 0:
             self.begidx -= 1
             if buf[self.begidx] in u' \t\n':
                 self.begidx += 1
                 break
         text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
         log(u'file complete text="%s"' % ensure_unicode(text))
         completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))
         if self.mark_directories == u'on':
             mc = []
             for f in completions:
                 if os.path.isdir(f):
                     mc.append(f + os.sep)
                 else:
                     mc.append(f)
             completions = mc
         log(u'fnames=<%s>' % map(ensure_unicode, completions))
     return completions
예제 #9
0
    def add_item(self, line, force=False):
        # Kludge. pyreadline is a pain in the ass.
        from pyreadline import lineobj
        from pyreadline.unicode_helper import ensure_unicode

        line = ensure_unicode(line.rstrip())
        readline.add_history(lineobj.ReadLineTextBuffer(line))
예제 #10
0
 def parse_history_from_string(self, string=None):
     '''Create a readline history from a string.
     Each history item must be separated by a newline character (\n)'''
     if not string:
         return
     for line in string.split("\n"):
         self.add_history(ensure_unicode(line.rstrip()))
예제 #11
0
 def add_history(self, line):
     '''Append a line to the history buffer, as if it was the last line typed.
     Empty lines are skipped.
     Repeated line, i.e. line equal to the last one is skipped as well
     modified history nformation is discarded
     '''
     line = ensure_unicode(line)
     log('add_history line="%s" currentlen is %d' %
         (line.get_line_text(), len(self.history)))
     if not hasattr(line, "get_line_text"):
         line = lineobj.ReadLineTextBuffer(line)
     else:
         line.end_of_line()
     if not line.get_line_text():
         if len(self.history) > 0 and len(
                 self.history[-1].get_line_text()) == 0:
             self.history = self.history[:-1]
         pass
     elif len(self.history) > 0 and self.history[-1].get_line_text(
     ) == line.get_line_text():
         pass
     elif len(self.history) > 0 and len(
             self.history[-1].get_line_text()) == 0:
         self.history[-1] = line
     else:
         self.history.append(line)
     self.history_cursor = len(self.history)
     self.clear_modified_history()
예제 #12
0
def check_key():
    if msvcrt is None:
        return False
    else:
        if msvcrt.kbhit():
            q = ensure_unicode(msvcrt.getch())
            return q
    return ""
예제 #13
0
def check_key():
    if msvcrt is None:
        return False
    else:
        if msvcrt.kbhit():
            q = ensure_unicode(msvcrt.getch())
            return q
    return ""
예제 #14
0
 def write_history_file(self, filename = None): 
     '''Save a readline history file.'''
     if filename is None:
         filename = self.history_filename
     fp = open(filename, 'w', encoding='utf-8')
     for line in self.history[-self.history_length:]:
         fp.write(ensure_unicode(line.get_line_text()))
         fp.write('\n')
     fp.close()
예제 #15
0
파일: console.py 프로젝트: Aha00a/play1
 def write_plain(self, text, attr=None):
     '''write text at current cursor position.'''
     log('write("%s", %s)' %(text,attr))
     if attr is None:
         attr = self.attr
     n = c_int(0)
     self.SetConsoleTextAttribute(self.hout, attr)
     self.WriteConsoleW(self.hout, ensure_unicode(chunk), len(chunk), byref(junk), None)
     return len(text)
예제 #16
0
파일: emacs.py 프로젝트: HBPSP8Repo/exareme
    def _readline_from_keyboard(self):
        c = self.console

        def nop(e):
            pass

        while 1:
            self._update_line()
            lbuf = self.l_buffer
            log_sock("point:%d mark:%d selection_mark:%d" % (lbuf.point, lbuf.mark, lbuf.selection_mark))
            try:
                event = c.getkeypress()
                log_sock(u">>%s" % event)
            except KeyboardInterrupt:
                from pyreadline.keysyms.common import KeyPress
                from pyreadline.console.event import Event
                event = Event(0, 0)
                event.char = "c"
                event.keyinfo = KeyPress("c", shift=False, control=True, meta=False, keyname=None)
                log_sock("KBDIRQ")
                if self.allow_ctrl_c:
                    now = time.time()
                    if (now - self.ctrl_c_timeout) < self.ctrl_c_tap_time_interval:
                        raise
                    else:
                        self.ctrl_c_timeout = now
                    pass
                else:
                    raise
            if self.next_meta:
                self.next_meta = False
                control, meta, shift, code = event.keyinfo
                event.keyinfo = (control, True, shift, code)

            # Process exit keys. Only exit on empty line
            keyinfo = event.keyinfo.tuple()
            if keyinfo in self.exit_dispatch:
                if lineobj.EndOfLine(self.l_buffer) == 0:
                    raise EOFError
            if len(keyinfo[-1]) > 1:
                default = nop
            else:
                default = self.self_insert
            dispatch_func = self.key_dispatch.get(keyinfo, default)

            log("readline from keyboard:%s,%s" % (keyinfo, dispatch_func))
            log_sock((u"%s|%s" % (ensure_unicode(format(keyinfo)), dispatch_func.__name__)), "bound_function")
            r = None
            if dispatch_func:
                r = dispatch_func(event)
                self._keylog(dispatch_func, self.l_buffer)
                self.l_buffer.push_undo()

            self.previous_func = dispatch_func
            if r:
                self._update_line()
                break
예제 #17
0
    def write_scrolling(self, text, attr=None):
        '''write text at current cursor position while watching for scrolling.

        If the window scrolls because you are at the bottom of the screen
        buffer, all positions that you are storing will be shifted by the
        scroll amount. For example, I remember the cursor position of the
        prompt so that I can redraw the line but if the window scrolls,
        the remembered position is off.

        This variant of write tries to keep track of the cursor position
        so that it will know when the screen buffer is scrolled. It
        returns the number of lines that the buffer scrolled.

        '''
        text = ensure_unicode(text)
        x, y = self.pos()
        w, h = self.size()
        scroll = 0  # the result
        # split the string into ordinary characters and funny characters
        chunks = self.motion_char_re.split(text)
        for chunk in chunks:
            n = self.write_color(chunk, attr)
            if len(chunk) == 1:  # the funny characters will be alone
                if chunk[0] == '\n':  # newline
                    x = 0
                    y += 1
                elif chunk[0] == '\r':  # carriage return
                    x = 0
                elif chunk[0] == '\t':  # tab
                    x = 8 * (int(x / 8) + 1)
                    if x > w:  # newline
                        x -= w
                        y += 1
                elif chunk[0] == '\007':  # bell
                    pass
                elif chunk[0] == '\010':
                    x -= 1
                    if x < 0:
                        y -= 1  # backed up 1 line
                else:  # ordinary character
                    x += 1
                if x == w:  # wrap
                    x = 0
                    y += 1
                if y == h:  # scroll
                    scroll += 1
                    y = h - 1
            else:  # chunk of ordinary characters
                x += n
                l = int(x / w)  # lines we advanced
                x = x % w  # new x value
                y += l
                if y >= h:  # scroll
                    scroll += y - h + 1
                    y = h - 1
        return scroll
예제 #18
0
파일: console.py 프로젝트: 0x0mar/OWASP-ZSC
    def write_scrolling(self, text, attr=None):
        '''write text at current cursor position while watching for scrolling.

        If the window scrolls because you are at the bottom of the screen
        buffer, all positions that you are storing will be shifted by the
        scroll amount. For example, I remember the cursor position of the
        prompt so that I can redraw the line but if the window scrolls,
        the remembered position is off.

        This variant of write tries to keep track of the cursor position
        so that it will know when the screen buffer is scrolled. It
        returns the number of lines that the buffer scrolled.

        '''
        text = ensure_unicode(text)
        x, y = self.pos()
        w, h = self.size()
        scroll = 0 # the result
        # split the string into ordinary characters and funny characters
        chunks = self.motion_char_re.split(text)
        for chunk in chunks:
            n = self.write_color(chunk, attr)
            if len(chunk) == 1: # the funny characters will be alone
                if chunk[0] == '\n': # newline
                    x = 0
                    y += 1
                elif chunk[0] == '\r': # carriage return
                    x = 0
                elif chunk[0] == '\t': # tab
                    x = 8 * (int(x / 8) + 1)
                    if x > w: # newline
                        x -= w
                        y += 1
                elif chunk[0] == '\007': # bell
                    pass
                elif chunk[0] == '\010':
                    x -= 1
                    if x < 0:
                        y -= 1 # backed up 1 line
                else: # ordinary character
                    x += 1
                if x == w: # wrap
                    x = 0
                    y += 1
                if y == h: # scroll
                    scroll += 1
                    y = h - 1
            else: # chunk of ordinary characters
                x += n
                l = int(x / w) # lines we advanced
                x = x % w # new x value
                y += l
                if y >= h: # scroll
                    scroll += y - h + 1
                    y = h - 1
        return scroll
예제 #19
0
 def read_history_file(self, filename=None): 
     '''Load a readline history file.'''
     if filename is None:
         filename = self.history_filename
     try:
         for line in open(filename, 'r'):
             self.add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip())))
     except IOError:
         self.history = []
         self.history_cursor = 0
예제 #20
0
 def read_history_file(self, filename=None): 
     '''Load a readline history file.'''
     if filename is None:
         filename = self.history_filename
     try:
         for line in open(filename, 'r', encoding='utf-8', errors='replace'):
             self.add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip())))
     except IOError:
         self.history = []
         self.history_cursor = 0
예제 #21
0
파일: console.py 프로젝트: BahBalia/Cloud
 def write_plain(self, text, attr=None):
     '''write text at current cursor position.'''
     log('write("%s", %s)' % (text, attr))
     if attr is None:
         attr = self.attr
     n = c_int(0)
     self.SetConsoleTextAttribute(self.hout, attr)
     self.WriteConsoleW(self.hout, ensure_unicode(chunk), len(chunk),
                        byref(junk), None)
     return len(text)
예제 #22
0
파일: console.py 프로젝트: BahBalia/Cloud
 def write_color(self, text, attr=None):
     text = ensure_unicode(text)
     n, res = self.ansiwriter.write_color(text, attr)
     junk = c_int(0)
     for attr, chunk in res:
         log(unicode(attr))
         log(unicode(chunk))
         self.SetConsoleTextAttribute(self.hout, attr.winattr)
         self.WriteConsoleW(self.hout, chunk, len(chunk), byref(junk), None)
     return n
예제 #23
0
파일: console.py 프로젝트: Aha00a/play1
 def write_color(self, text, attr=None):
     text = ensure_unicode(text)
     n,res= self.ansiwriter.write_color(text,attr)
     junk = c_int(0)
     for attr,chunk in res:
         log(unicode(attr))
         log(unicode(chunk))
         self.SetConsoleTextAttribute(self.hout, attr.winattr)
         self.WriteConsoleW(self.hout, chunk, len(chunk), byref(junk), None)
     return n
예제 #24
0
def GetClipboardText():
    text = ""
    if OpenClipboard(0):
        hClipMem = GetClipboardData(CF_TEXT)
        if hClipMem:
            GlobalLock.restype = c_char_p
            text = GlobalLock(hClipMem)
            GlobalUnlock(hClipMem)
        CloseClipboard()
    return ensure_unicode(text)
def GetClipboardText():
    text = u""
    if OpenClipboard(0):
        hClipMem = GetClipboardData(CF_TEXT)
        if hClipMem:        
            GlobalLock.restype = c_char_p
            text = GlobalLock(hClipMem)
            GlobalUnlock(hClipMem)
        CloseClipboard()
    return ensure_unicode(text)
예제 #26
0
 def write_color(self, text, attr=None):
     text = ensure_unicode(text)
     n, res = self.ansiwriter.write_color(text, attr)
     junk = DWORD(0)
     for attr, chunk in res:
         log(u"console.attr:%s" % unicode(attr))
         log(u"console.chunk:%s" % unicode(chunk))
         self.SetConsoleTextAttribute(self.hout, attr.winattr)
         for short_chunk in split_block(chunk):
             self.WriteConsoleW(self.hout, short_chunk, len(short_chunk), byref(junk), None)
     return n
예제 #27
0
 def read_history_file(self, filename=None):
     """Load a readline history file."""
     if filename is None:
         filename = self.history_filename
     try:
         for line in open(filename, "r"):
             self.add_history(
                 lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip())))
     except IOError:
         self.history = []
         self.history_cursor = 0
예제 #28
0
 def write_color(self, text, attr=None):
     text = ensure_unicode(text)
     n, res = self.ansiwriter.write_color(text, attr)
     junk = c_int(0)
     for attr, chunk in res:
         log(u"console.attr:%s" % unicode(attr))
         log(u"console.chunk:%s" % unicode(chunk))
         self.SetConsoleTextAttribute(self.hout, attr.winattr)
         for short_chunk in split_block(chunk):
             self.WriteConsoleW(self.hout, short_chunk, len(short_chunk),
                                byref(junk), None)
     return n
예제 #29
0
def SetClipboardText(text):
    buffer = create_unicode_buffer(ensure_unicode(text))
    bufferSize = sizeof(buffer)
    hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize))
    GlobalLock.restype = c_void_p
    lpGlobalMem = GlobalLock(c_int(hGlobalMem))
    memcpy(lpGlobalMem, addressof(buffer), c_int(bufferSize))
    GlobalUnlock(c_int(hGlobalMem))
    if OpenClipboard(0):
        EmptyClipboard()
        SetClipboardData(c_int(CF_UNICODETEXT), c_int(hGlobalMem))
        CloseClipboard()
예제 #30
0
 def add_history(self, line):
     '''Append a line to the history buffer, as if it was the last line typed.'''
     line = ensure_unicode(line)
     if not hasattr(line, "get_line_text"):
         line = lineobj.ReadLineTextBuffer(line)
     if not line.get_line_text():
         pass
     elif len(self.history) > 0 and self.history[-1].get_line_text() == line.get_line_text():
         pass
     else:
         self.history.append(line)
     self.history_cursor = len(self.history)
예제 #31
0
 def add_history(self, line):
     '''Append a line to the history buffer, as if it was the last line typed.'''
     line = ensure_unicode(line)
     if not hasattr(line, "get_line_text"):
         line = lineobj.ReadLineTextBuffer(line)
     if not line.get_line_text():
         pass
     elif len(self.history) > 0 and self.history[-1].get_line_text() == line.get_line_text():
         pass
     else:
         self.history.append(line)
     self.history_cursor = len(self.history)
예제 #32
0
def SetClipboardText(text):
    buffer = create_unicode_buffer(ensure_unicode(text))
    bufferSize = sizeof(buffer)
    hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize))
    GlobalLock.restype = c_void_p
    lpGlobalMem = GlobalLock(c_int(hGlobalMem))
    memcpy(lpGlobalMem, addressof(buffer), c_int(bufferSize))
    GlobalUnlock(c_int(hGlobalMem))
    if OpenClipboard(0):
        EmptyClipboard()
        SetClipboardData(c_int(CF_UNICODETEXT), c_int(hGlobalMem))
        CloseClipboard()
예제 #33
0
def SetClipboardText(text):
    buffer = create_unicode_buffer(ensure_unicode(text))
    bufferSize = sizeof(buffer)
    hGlobalMem = GlobalAlloc(GHND, c_size_t(bufferSize))
    GlobalLock.restype = c_void_p
    lpGlobalMem = GlobalLock(hGlobalMem)
    _strncpy(cast(lpGlobalMem, c_wchar_p), cast(addressof(buffer), c_wchar_p),
             c_size_t(bufferSize))
    GlobalUnlock(c_int(hGlobalMem))
    if OpenClipboard(0):
        EmptyClipboard()
        SetClipboardData(CF_UNICODETEXT, hGlobalMem)
        CloseClipboard()
예제 #34
0
def SetClipboardText(text):
    buffer = create_unicode_buffer(ensure_unicode(text))
    bufferSize = sizeof(buffer)
    hGlobalMem = GlobalAlloc(GHND, c_size_t(bufferSize))
    GlobalLock.restype = c_void_p
    lpGlobalMem = GlobalLock(hGlobalMem)
    _strncpy(cast(lpGlobalMem, c_wchar_p),
             cast(addressof(buffer), c_wchar_p),
             c_size_t(bufferSize))
    GlobalUnlock(c_int(hGlobalMem))
    if OpenClipboard(0):
        EmptyClipboard()
        SetClipboardData(CF_UNICODETEXT, hGlobalMem)
        CloseClipboard()
예제 #35
0
파일: console.py 프로젝트: Aha00a/play1
    def get(self):
        '''Get next event from queue.'''
        inputHookFunc = c_int.from_address(self.inputHookPtr).value

        Cevent = INPUT_RECORD()
        count = c_int(0)
        while 1:
            if inputHookFunc:
                call_function(inputHookFunc, ())
            status = self.ReadConsoleInputW(self.hin, byref(Cevent), 1, byref(count))
            if status and count.value == 1:
                e = event(self, Cevent)
                log_sock(ensure_unicode(e.keyinfo),"keypress")
                return e
예제 #36
0
파일: console.py 프로젝트: BahBalia/Cloud
    def get(self):
        '''Get next event from queue.'''
        inputHookFunc = c_int.from_address(self.inputHookPtr).value

        Cevent = INPUT_RECORD()
        count = c_int(0)
        while 1:
            if inputHookFunc:
                call_function(inputHookFunc, ())
            status = self.ReadConsoleInputW(self.hin, byref(Cevent), 1,
                                            byref(count))
            if status and count.value == 1:
                e = event(self, Cevent)
                log_sock(ensure_unicode(e.keyinfo), "keypress")
                return e
예제 #37
0
def hook_wrapper_23(stdin, stdout, prompt):
    '''Wrap a Python readline so it behaves like GNU readline.'''
    try:
        # call the Python hook
        res = ensure_str(readline_hook(ensure_unicode(prompt)))
        # make sure it returned the right sort of thing
        if res and not isinstance(res, bytes):
            raise TypeError('readline must return a string.')
    except KeyboardInterrupt:
        # GNU readline returns 0 on keyboard interrupt
        return 0
    except EOFError:
        # It returns an empty string on EOF
        res = ensure_str('')
    except:
        print('Readline internal error', file=sys.stderr)
        traceback.print_exc()
        res = ensure_str('\n')
    # we have to make a copy because the caller expects to free the result
    n = len(res)
    p = Console.PyMem_Malloc(n + 1)
    _strncpy(cast(p, c_char_p), res, n + 1)
    return p
예제 #38
0
 def add_history(self, line):
     '''Append a line to the history buffer, as if it was the last line typed.
     Empty lines are skipped.
     Repeated line, i.e. line equal to the last one is skipped as well
     modified history nformation is discarded
     '''
     line = ensure_unicode(line)
     log('add_history line="%s" currentlen is %d' % (line.get_line_text(), len(self.history)))
     if not hasattr(line, "get_line_text"):
         line = lineobj.ReadLineTextBuffer(line)
     else:
         line.end_of_line()
     if not line.get_line_text():
         if len(self.history) > 0 and len(self.history[-1].get_line_text()) == 0:
             self.history = self.history[:-1]
         pass
     elif len(self.history) > 0 and self.history[-1].get_line_text() == line.get_line_text():
         pass
     elif len(self.history) > 0 and len(self.history[-1].get_line_text()) == 0:
         self.history[-1] = line
     else:
         self.history.append(line)
     self.history_cursor = len(self.history)
     self.clear_modified_history()
예제 #39
0
 def read_history_file(self, filename=None): 
     u'''Load a readline history file. The default filename is ~/.history.'''
     if filename is None:
         filename = self.mode._history.history_filename
     log(u"read_history_file from %s"%ensure_unicode(filename))
     self.mode._history.read_history_file(filename)
예제 #40
0
 def write(self, text):
     text = ensure_unicode(text)
     log(u'write("%s")' % text)
     return self.write_color(text)
예제 #41
0
파일: console.py 프로젝트: 0x0mar/OWASP-ZSC
 def write(self, text):
     text = ensure_unicode(text)
     log('write("%s")' % text)
     return self.write_color(text)
예제 #42
0
    def _readline_from_keyboard(self):
        c = self.console

        def nop(e):
            pass

        while 1:
            self._update_line()
            lbuf = self.l_buffer
            log_sock("point:%d mark:%d selection_mark:%d" %
                     (lbuf.point, lbuf.mark, lbuf.selection_mark))
            try:
                event = c.getkeypress()
                log_sock(u">>%s" % event)
            except KeyboardInterrupt:
                from pyreadline.keysyms.common import KeyPress
                from pyreadline.console.event import Event
                event = Event(0, 0)
                event.char = "c"
                event.keyinfo = KeyPress("c",
                                         shift=False,
                                         control=True,
                                         meta=False,
                                         keyname=None)
                log_sock("KBDIRQ")
                if self.allow_ctrl_c:
                    now = time.time()
                    if (now - self.ctrl_c_timeout
                        ) < self.ctrl_c_tap_time_interval:
                        raise
                    else:
                        self.ctrl_c_timeout = now
                    pass
                else:
                    raise
            if self.next_meta:
                self.next_meta = False
                control, meta, shift, code = event.keyinfo
                event.keyinfo = (control, True, shift, code)

            #Process exit keys. Only exit on empty line
            keyinfo = event.keyinfo.tuple()
            if keyinfo in self.exit_dispatch:
                if lineobj.EndOfLine(self.l_buffer) == 0:
                    raise EOFError
            if len(keyinfo[-1]) > 1:
                default = nop
            else:
                default = self.self_insert
            dispatch_func = self.key_dispatch.get(keyinfo, default)

            log("readline from keyboard:%s,%s" % (keyinfo, dispatch_func))
            log_sock(
                (u"%s|%s" %
                 (ensure_unicode(format(keyinfo)), dispatch_func.__name__)),
                "bound_function")
            r = None
            if dispatch_func:
                r = dispatch_func(event)
                self._keylog(dispatch_func, self.l_buffer)
                self.l_buffer.push_undo()

            self.previous_func = dispatch_func
            if r:
                self._update_line()
                break
예제 #43
0
 def read_history_file(self, filename=None):
     if filename is None:
         filename = self.mode._history.history_filename
     log('read_history_file from %s' % ensure_unicode(filename))
     self.mode._history.read_history_file(filename)
     return