예제 #1
0
    def __init__(self, player):
        self.player = player

        self.on_menu = True  # Shifts the focus between menu and board, = show new ship
        self.menu_hi = 0  # Which ele is hightlighted in the menu
        self.menu_sel = -1  # Current item selected, relevant when board is active
        self.num_ships_set = 0

        self.menu = self.player.left_to_set()

        self.new_ship_x = 0
        self.new_ship_y = 0
        self.new_ship_hor = True

        self.title = f'Set ships for player: {self.player.name}'

        self.max_y, self.max_x = uc.getmaxyx(stdscr)

        uc.noecho()  # Disable typing on the screen
        uc.cbreak()  # catching characters directly without waiting for [ENTER]
        uc.curs_set(0)  # Disable blinking curser
        uc.keypad(stdscr, True)  # for catching the arrow keys
        uc.start_color()

        self.init_wins()
def initInteractive(setup):
    logging.info("Initializing Nexus migration tool.")
    os.environ.setdefault('ESCDELAY', '25')
    try:
        stdscr = unicurses.initscr()
        unicurses.noecho()
        unicurses.cbreak()
        try:
            unicurses.start_color()
        except:
            pass
        scr = Screen(stdscr, setup.args)
        saf = Safety(scr)
        win = Main(scr)
        scr.render()
        while True:
            win.show()
            if not scr.modified() or saf.show(): break
    except:
        logging.exception("Error running Nexus migration tool:")
        raise
    finally:
        logging.info("Terminating Nexus migration tool.")
        logging.shutdown()
        if 'stdscr' in locals():
            unicurses.echo()
            unicurses.nocbreak()
            unicurses.endwin()
예제 #3
0
def main():
    try:
        stdscr = unicurses.initscr()
        unicurses.cbreak()
        # unicurses.noecho()
        unicurses.start_color()
        stdscr.keypad(1)
        # Determine if we need color
        if args.nocolor:
            unicurses.init_pair(1, unicurses.COLOR_WHITE, unicurses.COLOR_BLACK)
            unicurses.init_pair(2, unicurses.COLOR_WHITE, unicurses.COLOR_BLACK)
        else:
            unicurses.init_pair(1, unicurses.COLOR_BLUE, unicurses.COLOR_BLACK)
            unicurses.init_pair(2, unicurses.COLOR_RED, unicurses.COLOR_BLACK)
            unicurses.init_pair(3, unicurses.COLOR_GREEN, unicurses.COLOR_BLACK)
        # Game loop after this point
        gameLoop(stdscr)
    except KeyboardInterrupt:
        pass
        # TODO: Use global variables to fix this
        #saveGame( playerName )
    finally:
        stdscr.erase()
        stdscr.refresh()
        stdscr.keypad(0)
        unicurses.echo()
        unicurses.nocbreak()
        unicurses.endwin()
예제 #4
0
def main():
  ## Curses normal init sequence
  stdscr = curses.initscr()
  curses.noecho() # no echo, but we still see the cursor
  curses.curs_set(False) #turns off the cursor drawing
  stdscr.keypad(True) # allows special keys and arrow keys
  
  try:
    curses.start_color()

    window = curses.newwin(2, 25, 3, 5)
    window.addstr(0,0,"Hello, World!")

    # this window will now be displayed. Since we are doing getch
    # on window, that one is brought to front, window 2 isn't.
    # We can tackle this with panels. Or, explicitly call window2.refresh()
    window2 = curses.newwin(2, 25, 3, 50)
    window2.addstr(0,0,"Hello, World again!")
    
    while True:
      key = window.getch()
      if key == 27:
        break

  except Exception as e:
    stdscr.addstr(0,0,str(e))
    stdscr.getch()
  finally:
    
    curses.endwin()
  
  return 0
예제 #5
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        window = curses.newwin(10, 25, 3, 3)
        window.addstr(1, 1, "Hey there!")

        window.box()

        while True:
            key = window.getch()
            if key == 27:
                break

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #6
0
    def _start(self):
        """
        Initialize the screen and input mode.
        """
        self.stdscr = curses.initscr()
        self.has_color = curses.has_colors()
        if self.has_color:
            curses.start_color()
            if curses_.COLORS < 8:
                # not colourful enough
                self.has_color = False
        if self.has_color:
            try:
                curses.use_default_colors()
                self.has_default_colors=True
            except _curses.error:
                self.has_default_colors=False
        self._setup_colour_pairs()
        curses.noecho()
        # curses.meta(None, 1)
        #todo
        curses.meta( None,1)
        curses.halfdelay(1) # use set_input_timeouts to adjust
        self.stdscr.keypad(True)

        if not self._signal_keys_set:
            self._old_signal_keys = self.tty_signal_keys()
            
        self.set_mouse_tracking(True)

        super(Screen, self)._start()
예제 #7
0
파일: terminal.py 프로젝트: Chiel92/tfate
def init_colors():
    """
    Initialize color pairs from the terminal color palette.
    Pair 0 is the default, pairs 1-16 are the palette colors,
    pairs 17-32 are palette colors with a different background.
    We assume that color 8 has good contrast with other colors.
    """

    global HAS_COLORS
    HAS_COLORS = curses.has_colors()

    if HAS_COLORS:
        curses.start_color()
        curses.use_default_colors()

        global HAS_BACKGROUND_COLORS
        HAS_BACKGROUND_COLORS = True
        if HAS_BACKGROUND_COLORS:
            info('Terminal supports background colors.')
        else:
            info('Terminal does not support background colors.')

        global COLOR_PAIRS
        #COLOR_PAIRS = min(16, curses.COLORS)
        COLOR_PAIRS = 16
        info('Terminal supports {} colors. Using {} colorpairs.'.format(16, COLOR_PAIRS))

        for i in range(COLOR_PAIRS):
            curses.init_pair(i + 1, i, -1)
            try:
                curses.init_pair(i + 1 + COLOR_PAIRS, i, 8)
                curses.init_pair(i + 1 + COLOR_PAIRS + COLOR_PAIRS, i, 9)
            except:
                HAS_BACKGROUND_COLORS = False
def initInteractive(setup):
    logging.info("Initializing Nexus migration tool.")
    os.environ.setdefault('ESCDELAY', '25')
    try:
        stdscr = unicurses.initscr()
        unicurses.noecho()
        unicurses.cbreak()
        try: unicurses.start_color()
        except: pass
        scr = Screen(stdscr, setup.args)
        saf = Safety(scr)
        win = Main(scr)
        scr.render()
        while True:
            win.show()
            if not scr.modified() or saf.show(): break
    except:
        logging.exception("Error running Nexus migration tool:")
        raise
    finally:
        logging.info("Terminating Nexus migration tool.")
        logging.shutdown()
        if 'stdscr' in locals():
            unicurses.echo()
            unicurses.nocbreak()
            unicurses.endwin()
예제 #9
0
def main():
    try:
        stdscr = unicurses.initscr()
        unicurses.cbreak()
        # unicurses.noecho()
        unicurses.start_color()
        stdscr.keypad(1)
        # Determine if we need color
        if args.nocolor:
            unicurses.init_pair(1, unicurses.COLOR_WHITE,
                                unicurses.COLOR_BLACK)
            unicurses.init_pair(2, unicurses.COLOR_WHITE,
                                unicurses.COLOR_BLACK)
        else:
            unicurses.init_pair(1, unicurses.COLOR_BLUE, unicurses.COLOR_BLACK)
            unicurses.init_pair(2, unicurses.COLOR_RED, unicurses.COLOR_BLACK)
            unicurses.init_pair(3, unicurses.COLOR_GREEN,
                                unicurses.COLOR_BLACK)
        # Game loop after this point
        gameLoop(stdscr)
    except KeyboardInterrupt:
        pass
        # TODO: Use global variables to fix this
        #saveGame( playerName )
    finally:
        stdscr.erase()
        stdscr.refresh()
        stdscr.keypad(0)
        unicurses.echo()
        unicurses.nocbreak()
        unicurses.endwin()
예제 #10
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #11
0
    def __init__(self):
        global stdscr
        global _BASE_SCREEN

        stdscr = unicurses.initscr()
        unicurses.start_color()
        unicurses.use_default_colors()
        self.screen = stdscr

        _BASE_SCREEN = self
예제 #12
0
def initializeCursesTerminal():
    """Initialize the curses terminal and return the window object."""

    stdscr = unicurses.initscr()
    
    unicurses.start_color()
    unicurses.noecho()
    unicurses.cbreak()
    unicurses.keypad(stdscr, True)
    unicurses.timeout(False)
    unicurses.curs_set(False)

    return stdscr
예제 #13
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        window = curses.newwin(3, 20, 5, 5)
        window.addstr(1, 1, "Hey there!")
        window.box()

        window2 = curses.newwin(3, 20, 4, 4)
        window2.addstr(1, 1, "Hey there, again!")
        window2.box()

        panel = curses.new_panel(window)
        panel2 = curses.new_panel(window2)

        #curses.move_panel(panel, 10, 30)

        curses.update_panels()
        curses.doupdate()

        top_p = None

        while True:
            key = curses.getch()
            if key == 27:
                break

            top_p = panel if top_p is panel2 else panel2
            curses.top_panel(top_p)

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #14
0
def start():
    global screen
    screen = curses.initscr()
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
    screen.keypad(1)
    screen.nodelay(1)
    curses.nonl()
    screen.scrollok(False)
    curses.start_color()

    for i in range(0, 17):
        curses.init_pair(i+1, i, 0)
        #log.log("Pair : ({}, {}, 0)".format(i+1,i))

    h, w = screen.getmaxyx()
    log.log("Screen size : {}x{}".format(h, w))
예제 #15
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_GREEN)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_GREEN)

        dude = curses.newwin(1, 1, 10, 30)
        curses.waddstr(dude, "@", curses.color_pair(2) + curses.A_BOLD)
        dude_panel = curses.new_panel(dude)

        grass = curses.newwin(10, 50, 5, 5)
        grass.bkgd(" ", curses.color_pair(1))
        grass_panel = curses.new_panel(grass)

        curses.top_panel(dude_panel)

        curses.update_panels()
        curses.doupdate()

        while True:
            key = curses.getch()
            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #16
0
def main():

    if not curses.has_colors():
        print("Your terminal emulator needs to have colors.")
        return 0

    ## Curses normal init sequence
    stdscr = curses.initscr()
    curses.noecho()  # no echo, but we still see the cursor
    curses.curs_set(False)  #turns off the cursor drawing
    stdscr.keypad(True)  # allows special keys and arrow keys

    try:
        curses.start_color()

        avatar = Player(stdscr, "@", curses.COLOR_RED, curses.COLOR_BLACK,
                        curses.A_BOLD)

        curses.attron(curses.color_pair(1))
        curses.vline("|", 10)
        curses.hline("-", 10)
        curses.attroff(curses.color_pair(1))

        while True:
            key = curses.getch()

            avatar.move(key)

            if key == 27:
                break

            curses.update_panels()
            curses.doupdate()

    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #17
0
파일: main.py 프로젝트: akiky/manageri
def main():
    stdscr = curses.initscr()
    curses.keypad(stdscr, True)
    curses.curs_set(False)
    curses.noecho()
    curses.start_color()

    select = mainmenu()
    curses.erase()
    if (select == 3):
        pass

    elif (select == 2):
        curses.mvaddstr(1, 1, "Lataa peli")

    elif (select == 1):
        newgame()
        create_game()
        game_main_loop()

    curses.endwin()
예제 #18
0
def main():
    ## Curses normal init sequence
    stdscr = curses.initscr()
    try:
        curses.start_color()
        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_RED, curses.COLOR_WHITE)

        stdscr.addstr("Hello World!", curses.color_pair(1))
        stdscr.addstr("\nHello World!", curses.color_pair(2) + curses.A_BLINK)
        stdscr.addstr("\nHello World!",
                      curses.color_pair(1) + curses.A_REVERSE)
        stdscr.getch()
    except Exception as e:
        stdscr.addstr(0, 0, str(e))
        stdscr.getch()
    finally:

        curses.endwin()

    return 0
예제 #19
0
 def __init__(self):
     self.stdscr = unicurses.initscr()
     self.client = Client()
     self.client.connect()
     self.receive_data_thread = threading.Thread(
         target=self.display_received_data)
     self.receive_data_thread.daemon = True
     unicurses.start_color()
     unicurses.init_pair(1, unicurses.COLOR_GREEN, unicurses.COLOR_BLACK)
     self.height, self.width = self.stdscr.getmaxyx()
     self.displayWindow = unicurses.newwin(self.height - 6, self.width, 0,
                                           0)
     self.infoWindow = unicurses.newwin(3, self.width, self.height - 6, 0)
     self.inputWindow = unicurses.newwin(3, self.width, self.height - 3, 0)
     self.inputWindow.move(1, 1)
     self.msg = ''
     self.init_display_screen()
     self.init_info_screen()
     try:
         self.receive_data_thread.start()
     except (KeyboardInterrupt, SystemExit):
         sys.exit()
예제 #20
0
 def __init__(self):
     # Initialize screen
     self.stdscr = uni.initscr()
     # Hide cursor
     uni.curs_set(0)
     # Characters available one-by-one
     uni.cbreak()
     # Prevent displying user input
     uni.noecho()
     # Allow user input
     uni.keypad(self.stdscr, True)
     # Enable colors
     uni.start_color()
     # Enable mouse
     uni.mouseinterval(0)
     uni.mousemask(uni.ALL_MOUSE_EVENTS)
     # Window dimensions
     y, x = uni.getmaxyx(self.stdscr)
     # Make maxx/maxy the last row/col visible
     self.maxy = y - 1
     self.maxx = x - 1
     # Drawing order of contained widgets
     self.widgets = []
예제 #21
0
파일: codetest.py 프로젝트: johndpope/works
import sys

import time, random
import unicurses as curses

screen = curses.initscr()
screen.nodelay(1)
screen.border()
curses.noecho()
curses.curs_set(0)
dims = screen.getmaxyx()
height, width = dims[0] - 1, dims[1] - 1
curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)

row, col = 0, 0
for i in range(256):
    screen.addch(row, col, i, curses.color_pair(0))
    col += 1
    if col > 75:
        row += 1
        col = 1
    screen.refresh()
    time.sleep(0.051)
curses.endwin()
    'Q',
    81
]

# Window
NLINES = 10
NCOLS = 40
#my_wins = [0] * 3

stdscr = uni.initscr()
uni.cbreak()
uni.noecho()
uni.keypad(stdscr, True)
uni.curs_set(0)

uni.start_color()

# Sub window
# Max coords of parent window
maxy, maxx = uni.getmaxyx(stdscr)
menu_height = 3
menu = uni.newwin(menu_height, maxx, 0, 0)
starty, startx = uni.getbegyx(menu)
height, width = uni.getmaxyx(menu)

# Box line
uni.box(menu, 0, 0)
#uni.bkgd(uni.COLOR_PAIR(1))

# Box label
예제 #23
0
 def __init__(self):
     stdscr = uni.initscr()
     uni.start_color()
     uni.cbreak()
     uni.noecho()
     uni.keypad(stdscr, True)
예제 #24
0
파일: main.py 프로젝트: pqlime/jsrlive-cli
import time
import unicurses
import wave


os.chdir(os.path.dirname(os.path.realpath(__file__)))  # Changes working directory to the script's parent directory


# Screen config

stdscr = unicurses.initscr()  # initiates the unicurses module & returns a writable screen obj

unicurses.noecho()  # disables echoing of user input
unicurses.cbreak()  # characters are read one-by-one
unicurses.curs_set(0)  # Hide the cursor from view by the user
unicurses.start_color()  # enables color in terminal

stdscr.keypad(True)  # returns special keys like PAGE_UP, etc.
stdscr.nodelay(False)  # enables input blocking to keep CPU down

locale.setlocale(locale.LC_ALL, '')
encoding = locale.getpreferredencoding()  # get the preferred system encoding for unicode support

if sys.platform == 'win32':  # Windows: set codepage to 65001 for unicode support
    os.system('chcp 65001')

# Settings

broadcaster_names = {  # Broadcaster names for the 'BCST' bar
    'djprofessork': 'DJ Professor K',
    'noisetanks': 'Noise Tanks',
예제 #25
0
        elif self.main_menu.enabled and self.game_menu_interface.blocked:
            self.main_menu.key_event(key)
        elif not self.main_menu.enabled and self.game_menu_interface.blocked:
            self.game_field.key_event(key)
        else:
            self.game_menu_interface.key_event(key)


if __name__ == "__main__":
    stdscr = initscr()
    clear()
    noecho()
    cbreak()
    curs_set(0)
    keypad(stdscr, True)
    start_color()
    use_default_colors()
    nodelay(stdscr, True)
    init_pair(1, COLOR_BLACK, COLOR_WHITE)
    init_pair(2, COLOR_WHITE, COLOR_BLUE)
    init_pair(3, COLOR_BLACK, COLOR_BLUE)
    init_pair(4, COLOR_WHITE, COLOR_CYAN)
    init_pair(5, COLOR_YELLOW, COLOR_GREEN)
    init_pair(6, COLOR_GREEN, COLOR_BLACK)
    init_pair(7, COLOR_RED, COLOR_BLACK)
    init_pair(8, COLOR_BLUE, COLOR_YELLOW)
    init_pair(9, COLOR_RED, COLOR_YELLOW)
    init_pair(10, COLOR_WHITE, COLOR_RED)
    init_pair(11, COLOR_RED, COLOR_CYAN)

    WHITE_BLACK = COLOR_PAIR(1)
예제 #26
0
            self.main_menu.key_event(key)
        elif self.main_menu.enabled and self.game_menu_interface.blocked:
            self.main_menu.key_event(key)
        elif not self.main_menu.enabled and self.game_menu_interface.blocked:
            self.game_field.key_event(key)
        else:
            self.game_menu_interface.key_event(key)

if __name__ == "__main__":
    stdscr = initscr()
    clear()
    noecho()
    cbreak()
    curs_set(0)
    keypad(stdscr, True)
    start_color()
    use_default_colors()
    nodelay(stdscr, True)
    init_pair(1, COLOR_BLACK, COLOR_WHITE)
    init_pair(2, COLOR_WHITE, COLOR_BLUE)
    init_pair(3, COLOR_BLACK, COLOR_BLUE)
    init_pair(4, COLOR_WHITE, COLOR_CYAN)
    init_pair(5, COLOR_YELLOW, COLOR_GREEN)
    init_pair(6, COLOR_GREEN, COLOR_BLACK)
    init_pair(7, COLOR_RED, COLOR_BLACK)
    init_pair(8, COLOR_BLUE, COLOR_YELLOW)
    init_pair(9, COLOR_RED, COLOR_YELLOW)
    init_pair(10, COLOR_WHITE, COLOR_RED)
    init_pair(11, COLOR_RED, COLOR_CYAN)

    WHITE_BLACK = COLOR_PAIR(1)
from nex2art.core import Setup, Screen

# Start the tool by initializing unicurses and creating a new Screen object.
# Before doing so, set the ESCDELAY environment variable to 25, in an attempt to
# mitigate the delay following the pressing of the escape key during line
# editing.
if __name__ == '__main__':
    setup = Setup()
    logging.info("Initializing Nexus migration tool.")
    os.environ.setdefault('ESCDELAY', '25')
    try:
        stdscr = unicurses.initscr()
        unicurses.noecho()
        unicurses.cbreak()
        try:
            unicurses.start_color()
        except:
            pass
        scr = Screen(stdscr)
        saf = Safety(scr)
        win = Main(scr)
        scr.render()
        while True:
            win.show()
            if not scr.modified() or saf.show(): break
    except:
        logging.exception("Error running Nexus migration tool:")
        raise
    finally:
        logging.info("Terminating Nexus migration tool.")
        logging.shutdown()
            kw['ssl_version'] = ssl.PROTOCOL_TLSv1
            return func(*args, **kw)
        return bar
    ssl.wrap_socket = sslwrap(ssl.wrap_socket)

# Start the tool by initializing unicurses and creating a new Screen object.
# Before doing so, set the ESCDELAY environment variable to 25, in an attempt to
# mitigate the delay following the pressing of the escape key during line
# editing.
if __name__ == '__main__':
    os.environ.setdefault('ESCDELAY', '25')
    fixssl()
    try:
        stdscr = unicurses.initscr()
        unicurses.noecho()
        unicurses.cbreak()
        try: unicurses.start_color()
        except: pass
        scr = Screen(stdscr)
        saf = Safety(scr)
        win = Main(scr)
        scr.render()
        while True:
            win.show()
            if not scr.modified() or saf.show(): break
    finally:
        if 'stdscr' in locals():
            unicurses.echo()
            unicurses.nocbreak()
            unicurses.endwin()
예제 #29
0
 def enable_colors(self):
     """Turns terminal colors on."""
     uni.start_color()
예제 #30
0
파일: codetest.py 프로젝트: MeetLuck/works
import sys

import time, random
import unicurses as curses 

screen = curses.initscr()
screen.nodelay(1)
screen.border()
curses.noecho()
curses.curs_set(0)
dims = screen.getmaxyx()
height,width = dims[0]-1, dims[1]-1
curses.start_color()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)

row,col= 0,0
for i in range(256):
    screen.addch(row,col,i,curses.color_pair(0) )
    col +=1
    if col>75:
        row +=1
        col = 1
    screen.refresh()
    time.sleep(0.051)
curses.endwin()
예제 #31
0
def initCurses():
    stdscr = uc.initscr()
    uc.noecho()
    uc.curs_set(False)
    uc.keypad(stdscr, True)
    uc.start_color()