コード例 #1
0
ファイル: test.py プロジェクト: netknow/python-for-android
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
コード例 #2
0
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
コード例 #3
0
ファイル: window.py プロジェクト: LukeB42/Window
 def start(self):
     """
     Window event loop
     """
     self.window = _curses.initscr()
     _curses.savetty()
     _curses.start_color()
     _curses.use_default_colors()
     self.window.leaveok(1)
     _curses.raw()
     self.window.keypad(1)
     _curses.noecho()
     _curses.cbreak()
     _curses.nonl()
     _curses.curs_set(0)
     if self.blocking:
         self.window.nodelay(0)
     else:
         self.window.nodelay(1)
     self.running = True
     while self.running:
         self.cycle()
         if self.friendly and not self.blocking:
             time.sleep(self.delay)
     self.stop()
コード例 #4
0
 def start(self):
     """
     Window event loop
     """
     self.window = _curses.initscr()
     _curses.savetty()
     _curses.start_color()
     _curses.use_default_colors()
     self.window.leaveok(1)
     _curses.raw()
     self.window.keypad(1)
     _curses.noecho()
     _curses.cbreak()
     _curses.nonl()
     _curses.curs_set(0)
     if self.blocking:
         self.window.nodelay(0)
     else:
         self.window.nodelay(1)
     self.running = True
     while self.running:
         self.draw()
         self.process_input()
         if self.friendly and not self.blocking:
             time.sleep(self.delay)
     self.stop()
コード例 #5
0
 def init(cls):
     # sets up the initial state of the console - performs bootstrapping of the curses library
     # note this isn't an instance initialisation method (they're called __init__)
     cls.__screen = _curses.initscr()
     _curses.start_color()
     _curses.noecho()
     _curses.cbreak()
     _curses.curs_set(0)
コード例 #6
0
ファイル: __init__.py プロジェクト: msegeya/fbroute
def initscr():
    import _curses, curses
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr
コード例 #7
0
ファイル: __init__.py プロジェクト: doom38/jython_v2.2.1
def initscr():
    import _curses, curses
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)
    
    return stdscr
コード例 #8
0
def initscr():
    import _curses, curses
    setupterm(term=_os.environ.get('TERM', 'unknown'), fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr
コード例 #9
0
ファイル: __init__.py プロジェクト: webiumsk/WOT-0.9.12-CT
def initscr():
    import _curses, curses
    setupterm(term=_os.environ.get('TERM', 'unknown'), fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr
コード例 #10
0
ファイル: repl.py プロジェクト: valeness/Emissary
    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)
コード例 #11
0
ファイル: repl.py プロジェクト: LukeB42/Emissary
    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)
コード例 #12
0
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr
コード例 #13
0
ファイル: __init__.py プロジェクト: jitrc/real-racer
def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr
コード例 #14
0
ファイル: login.py プロジェクト: LukeB42/microauth-login
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
コード例 #15
0
ファイル: curses.py プロジェクト: moreati/stubtool
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')
コード例 #16
0

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
コード例 #17
0
ファイル: has_key.py プロジェクト: webiumsk/WOT-0.9.12
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)
コード例 #18
0
#origin from https://gist.github.com/msimpson/1096950

import _curses, random

screen = _curses.initscr()

width = screen.getmaxyx()[1]

height = screen.getmaxyx()[0]

size = width * height

char = [" ", ".", ":", "^", "*", "x", "s", "S", "#", "$"]

b = []

_curses.curs_set(0)

_curses.start_color()

_curses.init_pair(1, 0, 0)

_curses.init_pair(2, 1, 0)

_curses.init_pair(3, 3, 0)

_curses.init_pair(4, 4, 0)

screen.clear

for i in range(size + width + 1):
コード例 #19
0
import _curses

window = _curses.initscr()
window.getch()
_curses.endwin()
コード例 #20
0
"""curses