def do_exit(self,line): try: _curses.endwin() except _curses.error: pass finally: raise SystemExit
def do_exit(self, line): try: _curses.endwin() except _curses.error: pass finally: raise SystemExit
def do_read(self, line): """ Usage: read <article_uid> Pipes article content into the system pager. Text column width can be configured with the width command. """ then = time.time() response = self.c._send_request("articles/" + line) if response[1] != 200: print response[1] return data = response[0] if not 'content' in data: print None else: p = Popen(['less', '-P', data['title']], stdin=PIPE) try: duration = tconv(int(then) - int(data['created'])) p.stdin.write('%s\n(%i paragraphs, fetched %s ago)\n%s\n\n' % \ (data['title'].encode("utf-8", "ignore"), len(data['content'].encode("utf-8","ignore").split("\n"))/2+1, duration, data['url'].encode("utf-8","ignore"))) content = data['content'].encode("utf-8", "ignore") # Get TTY width and wrap the text if self.width == "auto": s = _curses.initscr() width = s.getmaxyx()[1] _curses.endwin() else: width = self.width content = '\n'.join( textwrap.wrap(content, width, break_long_words=False, replace_whitespace=False)) p.stdin.write(content) except IOError as e: if e.errno == errno.EPIPE or e.errno == errno.EINVAL: sys.stderr.write("Error writing to pipe.\n") else: raise p.stdin.close() p.wait() now = time.time() duration = tconv(now - then)
def stop(self): """ Restore the TTY to its original state. """ _curses.nocbreak() self.window.keypad(0) _curses.echo() _curses.resetty() _curses.endwin() self.running = False
def do_read(self,line): """ Usage: read <article_uid> Pipes article content into the system pager. Text column width can be configured with the width command. """ then = time.time() response = self.c._send_request("articles/" + line) if response[1] != 200: print response[1] return data = response[0] if not 'content' in data: print None else: p = Popen(['less', '-P', data['title']], stdin=PIPE) try: duration = tconv(int(then) - int(data['created'])) p.stdin.write('%s\n(%i paragraphs, fetched %s ago)\n%s\n\n' % \ (data['title'].encode("utf-8", "ignore"), len(data['content'].encode("utf-8","ignore").split("\n"))/2+1, duration, data['url'].encode("utf-8","ignore"))) content = data['content'].encode("utf-8", "ignore") # Get TTY width and wrap the text if self.width == "auto": s = _curses.initscr() width = s.getmaxyx()[1] _curses.endwin() else: width = self.width content = '\n'.join( textwrap.wrap(content, width, break_long_words=False, replace_whitespace=False) ) p.stdin.write(content) except IOError as e: if e.errno == errno.EPIPE or e.errno == errno.EINVAL: sys.stderr.write("Error writing to pipe.\n") else: raise p.stdin.close() p.wait() now = time.time() duration = tconv(now-then)
def test0_curses(): # {{{2 import os if not os.environ.get("TERM", ""): os.environ["TERM"] = "vt100" os.environ["TERMINFO"] = ("/data/data/com.googlecode.pythonforandroid" "/files/python/share/terminfo") try: import _curses except: return False _curses.initscr() _curses.endwin() return True
def spawn_shell(username): """ Detach from the controlling terminal, change UID to that of username and spawn a shell in their home directory. """ passwd_file = read_passwd() if not username in passwd_file: log("Account not found.") return False user = passwd_file[username] uid = user[1] gid = user[2] home_dir = user[4] shell = user[5] log("Defining environment.") os.environ["HOME"] = home_dir os.environ["USER"] = username os.environ["SHELL"] = shell screen = _curses.initscr() terminal_width = screen.getmaxyx()[1] _curses.endwin() os.environ["COLUMNS"] = str(terminal_width) if not "TERM" in os.environ: os.environ["TERM"] = "dumb" log("Changing UID") os.setgid(int(gid)) os.setuid(int(uid)) if not os.path.isdir(home_dir): home_dir = "/" log("Moving into %s" % home_dir) os.chdir(home_dir) log("Detaching from TTY") log("Spawning shell.") pty.spawn(shell) if os.path.isfile("/usr/bin/clear"): os.system("clear") return True
def _init(): real_term = os.getenv('TERM') master, slave, savestdout = -1, -1, -1 try: os.putenv('TERM', 'ansi') master, slave = os.openpty() savestdout = os.dup(_STDOUT_FILENO) os.dup2(slave, _STDOUT_FILENO) win = _curses.initscr() panel = _curses_panel.new_panel(win) win_type = type(win) panel_type = type(panel) _curses.endwin() return win_type, panel_type finally: os.dup2(savestdout, _STDOUT_FILENO) os.close(savestdout) os.close(slave) os.close(master) if real_term is not None: os.putenv('TERM', real_term) else: os.unsetenv('TERM')
def has_key(ch): if type(ch) == type(''): ch = ord(ch) # Figure out the correct capability name for the keycode. capability_name = _capability_names[ch] #Check the current terminal description for that capability; #if present, return true, else return false. if _curses.tigetstr(capability_name): return 1 else: return 0 if __name__ == '__main__': # Compare the output of this implementation and the ncurses has_key, # on platforms where has_key is already available try: L = [] _curses.initscr() for key in _capability_names.keys(): system = _curses.has_key(key) python = has_key(key) if system != python: L.append('Mismatch for key %s, system=%i, Python=%i' % (_curses.keyname(key), system, python)) finally: _curses.endwin() for i in L: print i
def has_key(ch): if isinstance(ch, str): ch = ord(ch) capability_name = _capability_names.get(ch) if capability_name is None: return False elif _curses.tigetstr(capability_name): return True else: return False return if __name__ == '__main__': try: L = [] _curses.initscr() for key in _capability_names.keys(): system = key in _curses python = has_key(key) if system != python: L.append('Mismatch for key %s, system=%i, Python=%i' % (_curses.keyname(key), system, python)) finally: _curses.endwin() for i in L: print i # okay decompyling c:\Users\PC\wotsources\files\originals\res_bw\scripts\common\lib\curses\has_key.pyc # decompiled 1 files: 1 okay, 0 failed, 0 verify failed # 2015.11.18 12:02:51 Støední Evropa (bìžný èas)
def do_exit(self, line): _curses.endwin() raise SystemExit
def do_exit(self,line): _curses.endwin() raise SystemExit