コード例 #1
0
ファイル: cursesColors.py プロジェクト: idrmhyprbls/termCube
 def init(self):
     self.window = curses.initscr()
     self.initted = True
     self.ymax, self.xmax = self.window.getmaxyx()
     terminfo = curses.longname()
     assert '256' in terminfo  # your env TERM must be xterm-256color!
     assert curses.has_colors()
     curses.start_color()
     curses.use_default_colors()
     ctr = 1
     for fg in CLRS:
         for bg in CLRS:
             if ctr <= curses.COLORS-1 and fg != bg:
                 curses.init_pair(ctr, CLRS[fg], CLRS[bg])
                 pairs[(fg,bg)] = curses.color_pair(ctr)
                 ctr += 1
     curses.meta(1)
     curses.noecho()
     curses.cbreak()
     curses.curs_set(0)
     curses.delay_output(0)
     curses.mouseinterval(150)
     availmask,_ = curses.mousemask(curses.ALL_MOUSE_EVENTS)
     assert availmask != 0  # mouse must be available!
     self.window.leaveok(1)
     self.window.scrollok(0)
     self.window.keypad(1)
     if NONBLOCKING:
         self.window.nodelay(1)
         self.window.timeout(NONBLOCKING_TIMEOUT)
     else:
         self.window.nodelay(0)
         self.window.timeout(-1)
     self.window.refresh()
コード例 #2
0
ファイル: display.py プロジェクト: kosciak/kosciak-misc
def main(scrn):
    box = scrn.subwin(3,5, 0,0)
    box.box()
    box.addstr(1,1, "box")
    
    border = scrn.subwin(3,8, 0,6)
    border.border()
    border.addstr(1,1, "border")
    
    background = scrn.subwin(3,14, 0,15)
    curses.init_pair(7, curses.COLOR_RED, curses.COLOR_GREEN)
    curses.init_pair(8, curses.COLOR_BLUE, curses.COLOR_WHITE)
    background.bkgd("#", curses.color_pair(7))
    background.addstr(1,2, "background", curses.color_pair(8))
    background.refresh
    
    background2 = scrn.subwin(4,14, 0,30)
    background2.bkgdset("#")
    background2.addstr("              ")
    background2.addstr("  background  ")
    background2.addstr("              ")
    
    
    lines = scrn.subwin(3,11, 0,45)
    lines.hline(1,0, curses.ACS_HLINE, 11)
    lines.vline(0,2, curses.ACS_VLINE, 3)
    lines.vline(0,8, curses.ACS_VLINE, 3)
    lines.addstr(0,3, "lines")
    lines.addch(1,2, curses.ACS_SSSS)
    lines.addch(1,8, curses.ACS_SSSS)
    
    text = scrn.subwin(10,9, 4,0)
    text.addstr(0,0, "dim", curses.A_DIM)
    text.addstr(1,0, "normal", curses.A_NORMAL)
    text.addstr(2,0, "underline", curses.A_UNDERLINE)
    text.addstr(3,0, "bold", curses.A_BOLD)
    text.addstr(4,0, "standout", curses.A_STANDOUT)
    text.addstr(5,0, "reverse", curses.A_REVERSE)
    text.addstr(6,0, "blink", curses.A_BLINK)
    text.addstr(7,0, "invisible", curses.A_INVIS)
    
    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
    text.move(8,0)
    text.addch("c", curses.color_pair(1) | curses.A_BOLD)
    text.addch("o", curses.color_pair(2) | curses.A_BOLD)
    text.addch("l", curses.color_pair(3) | curses.A_BOLD)
    text.addch("o", curses.color_pair(2) | curses.A_BOLD)
    text.addch("r", curses.color_pair(1) | curses.A_BOLD)
    
    scrn.addstr(15,0, curses.termname())
    scrn.addstr(": " + curses.longname())
    
    scrn.getch()
    curses.flash()
    scrn.getch()
コード例 #3
0
def safescreen(termstr=None):
    """A context manager that acts like curses.wrapper.
    
    Example:
    with safescreen('xterm-256color') as scr:
        scr.addstr('123456')
        scr.getch()
    """
    try:
        if 'TERM' in os.environ:
            oldterm = os.environ['TERM']
        else:
            oldterm = None
        if termstr: # modify enviornmental variables to duplicate another term
            os.environ['TERM'] = termstr # only way 
        stdscr=curses.initscr()
        log('colors:', curses.tigetnum('colors'),curses.longname())
        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        
        # try to start colors, and ignore errors
        try:
            curses.start_color()
            curses.use_default_colors()
            log('colors started')
        except:
            log('safescreen:','ERROR STARTING COLORS')
            pass
        
        yield stdscr
        
    finally:
        if termstr and oldterm is not None:
            os.environ['TERM'] = oldterm
        try:
            stdscr.keypad(0)
        except:
            pass
        try:
            curses.echo()
            curses.nocbreak()
            curses.endwin()
        except:
            pass
コード例 #4
0
ファイル: cursesui.py プロジェクト: svk/harmless7drl
 x, y = 15, 15
 controls = {
     'h': (-1, 0),
     'l': (1, 0),
     'j': (0, 1),
     'k': (0, -1),
     'y': (-1, -1),
     'u': (1, -1),
     'b': (-1, 1),
     'n': (1, 1),
 }
 while True:
     cui.clear()
     cui.putString( 10, 10, "Hello world!" )
     cui.putString( 10, 11, "This window is %dx%d" % (w,h) )
     cui.putString( 10, 13, "longname(): %s" % curses.longname() )
     cui.putString( 10, 14, "COLOR_PAIRS: %d" % curses.COLOR_PAIRS )
     cui.putString( 10, 15, "can_change_color(): %s" % curses.can_change_color() )
     cui.put( x, y, "@", fg = 'red' )
     cui.show()
     rv = None
     try:
         rv = cui.get()
     except ResizedException:
         w, h = cui.dimensions()
     if rv:
         if rv.type == "keypress":
             if rv.key == 'q': break
             if controls.has_key( rv.key ):
                 dx, dy = controls[ rv.key ]
                 x += dx
コード例 #5
0
import curses

print "Imported"

w1 = curses.initscr()
print "initscr"

print "Type:", type(w1)

print curses.longname()
print "Baudrate:", curses.baudrate()

print "Has colors:", curses.has_colors()

curses.curs_set(1)

w2 = curses.newwin(0, 0)
print "New window (fullscreen)"

w2.addch(ord('A'))
w2.addch('B')

w2.addstr("some text")
print "some text"

w2.addstr(" more text")
print "more text"

w2.addstr(" even more text")
print "even more text"
コード例 #6
0
import curses, sys

try:
    try:
        curses.initscr()

        print 1
        print curses.version
        curses.longname()
        print curses.baudrate()
        print curses.can_change_color()
        curses.start_color()
        print curses.color_pair(curses.A_BLINK)
    finally:
        curses.endwin()
except:
    print sys.exc_info()[1]
コード例 #7
0
ファイル: curses_test.py プロジェクト: H8ter/pyston
import curses, sys

try:
    try:
        curses.initscr()

        print 1
        print curses.version
        print curses.longname()
        print curses.baudrate()
        print curses.can_change_color()
        curses.start_color()
        print curses.color_pair(curses.A_BLINK)
    finally:
        curses.endwin()
except:
    print sys.exc_info()[1]