Пример #1
0
    def run(self):
        try:
            curses.curs_set(0)
        except:
            pass

        curses.use_default_colors()
        self.stdscr.nodelay(1)
        curses.nonl()
        curses.noecho()

        self.generate_layout()

        self.update_active = True
        while (True):

            rc = self.wait_for_key_input()
            if not rc:
                break

            self.update_control()
            self.update_info()

            panel.update_panels()
            self.stdscr.refresh()
            sleep(0.1)
Пример #2
0
    def __init__(self, screen, data):
        self.stdscr = screen
        self.WIDTH = 0
        self.HEIGHT = 0
        self.PROMPT = 'QUERY> '
        self.has_default_colors = False
        self.selected = 0

        self.data = data
        self.filter_data = data

        self.stdscr.keypad(True)
        curses.raw()
        curses.noecho()
        curses.cbreak()
        curses.nonl()

        curses.start_color()
        curses.use_default_colors()
        FG_COLORS["default"] = -1
        BG_COLORS["on_default"] = -1
        self.init_color_pairs()
        self.HEIGHT, self.WIDTH = self.stdscr.getmaxyx()
        self.MAX_DISPLAY_COUNT = self.HEIGHT - 2

        self.keyword_style = self.attrs_to_style(keyword_style)
        self.keyword_highlight_style = self.attrs_to_style(keyword_style +
                                                           highlight_style)
        self.highlight_style = self.attrs_to_style(highlight_style)
        self.leader_style = self.attrs_to_style(leader_style)

        self.return_result = None
Пример #3
0
    def __init__(self, facade):
        """Create an initialize UI"""
        Thread.__init__(self)
        Observer.__init__(self)

        self.corefacade = facade  # Store the facade of the domain layer

        # curses initialization
        self.window = curses.initscr()

        if curses.COLS < 80 or curses.LINES < 24:
            curses.endwin()
            print("Please consider to use at least a 80x24 terminal size.")
            raise Exception()

        self.window.keypad(1)  # Let special keys be a single key
        curses.noecho()  # No echoing key pressed
        curses.nonl()  # Leave newline mode
        try:
            curses.curs_set(0)  # No cursor
        except:
            pass

        # Open the main window
        self.wmain = MainWindow(self)
Пример #4
0
    def __enter__(self):
        locale.setlocale(locale.LC_ALL, '')
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.nonl()
        curses.raw()

        termstate = termios.tcgetattr(0)
        termstate[6][termios.VINTR] = bytes([self.INTCHAR])
        nope = bytes([0])  # to disable a character
        termstate[6][termios.VQUIT] = nope
        termstate[6][termios.VSUSP] = nope
        if hasattr(termios, 'VDSUSP'):
            termstate[6][termios.VDSUSP] = nope  # pragma: nocover
        termstate[3] |= termios.ISIG
        termios.tcsetattr(0, termios.TCSANOW, termstate)

        self.stdscr.keypad(1)
        self.stdscr.nodelay(1)
        self.color_assigner = ttycolor.get_assigner()
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        self.orig_sigtstp = signal.signal(signal.SIGTSTP, self.sigtstp)
        self.main_pid = os.getpid()
        loop = asyncio.get_event_loop()
        loop.add_signal_handler(signal.SIGWINCH, self.sigwinch, loop)

        with mock.patch('asyncio.unix_events._sighandler_noop',
                        self.sighandler_op):
            loop.add_signal_handler(signal.SIGINT, self.sigint)

        return self
Пример #5
0
    def initialize(self):
        self._color_index_map = DEFAULT_COLOR_INDEX_MAP.copy()
        self._old_signal_handler = None

        # Init Curses
        self._screen = curses.initscr()
        curses.savetty()
        curses.raw(1)
        curses.nonl()
        curses.noecho()
        curses.curs_set(0)
        self._screen.keypad(1)
        self._screen.timeout(0)
        self._core.add_exit_handler(self.close)

        # Init Colors
        curses.start_color()
        self._init_colors()

        # Init Symbols
        self.symbols = {
            symbols.SYM_VLINE: curses.ACS_VLINE,
            symbols.SYM_HLINE: curses.ACS_HLINE,
            symbols.SYM_LTEE: curses.ACS_LTEE,
            symbols.SYM_LLCORNER: curses.ACS_LLCORNER,
            symbols.SYM_RARROW: curses.ACS_RARROW,
            symbols.SYM_DARROW: curses.ACS_DARROW,  #ord('v'),
        }

        # Init Event Handling
        self._core.io_selector.register(sys.stdin, self._read_input)
        self._core.io_selector.register_async(TERMINAL_RESIZE_EVENT,
                                              self._handle_resize)
        self._old_signal_handler = signal.getsignal(signal.SIGWINCH)
        signal.signal(signal.SIGWINCH, self._handle_resize_sig)
Пример #6
0
    def initcurse(self):
        
        # Check the terminal type.  If we fail, then assume that the
        # terminal has no capabilities.
        try: curses.setupterm()
        except: return
        
        #self.colors = cursescolors()
        
        self.cols = curses.tigetnum('cols')
        self.lines = curses.tigetnum('lines')
        self.wfilelines = self.lines-3

        self.w = curses.initscr()
        # fenetre                    hauteur          largeur    y             x
        self.wheader = curses.newwin(              1, self.cols,            0, 0)
        self.wfile   = curses.newwin(self.wfilelines, self.cols,            1, 0)
        self.wfooter = curses.newwin(              1, self.cols, self.lines-2, 0)
        self.wcmd    = curses.newwin(              1, self.cols, self.lines-1, 0)
        curses.noecho()
        curses.cbreak()
        curses.nonl() # permet d'activer la touche enter (code 13)
        curses.curs_set(0)
        curses.mousemask(0)
        curses.mouseinterval(0)
        self.w.keypad(1)
        self.w.nodelay(0)
        self.w.timeout(self.timeout)
        
        try:
            self.initcolors_1()
        except:
            self.initcolors_2()
Пример #7
0
 def int16(self):
     ah = self.ql.reg.ah
     if ah == 0x0:
         curses.nonl()
         key = self._parse_key(self.stdscr.getch())
         self.ql.dprint(0, f"Get key: {hex(key)}")
         if curses.ascii.isascii(key):
             self.ql.reg.al = key
         else:
             self.ql.reg.al = 0
         self.ql.reg.ah = self._get_scan_code(key)
         curses.nl()
     elif ah == 0x1:
         curses.nonl()
         # set non-blocking
         self.stdscr.timeout(0)
         key = self._parse_key(self.stdscr.getch())
         if key == -1:
             self.set_flag(0x40)
             self.ql.reg.ax = 0
         else:
             self.ql.dprint(0, f"Has key: {hex(key)} ({curses.ascii.unctrl(key)})")
             self.ql.reg.al = key
             self.ql.reg.ah = self._get_scan_code(key)
             self.clear_flag(0x40)
             # Buffer shouldn't be removed in this interrupt.
             curses.ungetch(key)
         self.stdscr.timeout(-1)
         curses.nl()
Пример #8
0
def init_screen(stdscr):
    curses.cbreak()
    curses.noecho()
    curses.nonl()
    curses.intrflush(False)
    stdscr.keypad(True)
    stdscr.refresh()
Пример #9
0
    def __init__(self, facade):
        """Create an initialize UI"""
        Thread.__init__(self)
        Observer.__init__(self)

        self.corefacade = facade  # Store the facade of the domain layer

        # curses initialization
        self.window = curses.initscr()

        # Use colours if the user wants it and if it's available
        ClientUI._define_colours()

        # Control terminal size
        if curses.COLS < 80 or curses.LINES < 24:
            curses.endwin()
            print("Please consider to use at least a 80x24 terminal size.")
            raise Exception()

        self.window.keypad(1)  # Let special keys be a single key
        curses.noecho()  # No echoing key pressed
        curses.nonl()  # Leave newline mode
        try:
            curses.curs_set(0)  # Hide cursor
        except:
            pass

        # Open the main window
        self.wmain = MainWindow(self)
Пример #10
0
    def __enter__(self):
        # init curses and it's wrapper
        self.screen  = curses.initscr()
        self.display = Display(self.screen, self.encoding)

        # create keyhandler
        self.keyhandler = key.KeyHandler(self.screen)

        # create view
        self.view = SelectorView(percol = self)

        # create command
        self.command_candidate = SelectorCommand(self.model_candidate, self.view)
        self.command_action = SelectorCommand(self.model_action, self.view)

        # suppress SIGINT termination
        signal.signal(signal.SIGINT, lambda signum, frame: None)

        # handle special keys like <f1>, <down>, ...
        self.screen.keypad(True)

        curses.raw()
        curses.noecho()
        curses.cbreak()
        # Leave newline mode. Make percol distinguish between "C-m" and "C-j".
        curses.nonl()

        return self
Пример #11
0
 def _setup_curses(self):
     self.screen.keypad(True)
     curses.raw()
     curses.noecho()
     curses.cbreak()
     curses.nonl()
     curses.curs_set(0)
Пример #12
0
    def run (self):
        try:
            curses.curs_set(0)
        except:
            pass

        curses.use_default_colors()        
        self.stdscr.nodelay(1)
        curses.nonl()
        curses.noecho()
     
        self.generate_layout()

        self.update_active = True
        while (True):

            rc = self.wait_for_key_input()
            if not rc:
                break

            self.update_control()
            self.update_info()

            panel.update_panels(); 
            self.stdscr.refresh()
            sleep(0.1)
Пример #13
0
    def run(self, win):
        curses.raw()
        curses.nonl()
        curses.noecho()

        while True:
            self.redraw(win)

            ch = win.getch()
            if ch in NEXT:
                self.blockno = min(self.blockno + 1, len(self.blocks) - 1)
            elif ch in PREV:
                self.blockno = max(self.blockno - 1, 0)
            elif ch in FIRST:
                self.blockno = 0
            elif ch in LAST:
                self.blockno = len(self.blocks) - 1
            elif ch in RANDOM:
                self.blockno = random.randint(0, len(self.blocks) - 1)
            elif ch in EDIT:
                self.edit(win)
            elif ch in HELP:
                self.print_help(win)
            elif ch in QUIT:
                return 0
Пример #14
0
    def __init__(self):
        self.input_string = ""
        self.all_entries = get_entries_from_file()
        self.matches = []
        self.selected_option_index = 0

        self.screen = curses.initscr()
        self.screen.clear()
        # signal.signal(signal.SIGINT, lambda signum, frame: None)
        self.screen.keypad(True)
        curses.raw()
        curses.noecho()
        curses.cbreak()
        curses.nonl()

        curses.start_color()
        curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_BLACK)
        curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_MAGENTA)
        curses.newwin(0, 0)
        self.screen.keypad(1)
        self.screen.addstr(0, 0, "QUERY>")

        try:
            self.process_new_input()
            while True:
                pressed_key = self.screen.getch()
                self._handle_keypress(pressed_key)
                self.process_new_input()
        except:
            #TODO: maybe catch only keyboard interrupt????
            curses.nocbreak()
            self.screen.keypad(False)
            curses.echo()
            curses.nl()
            curses.endwin()
Пример #15
0
 def __enter__(self):
     """Open ANSI interface."""
     VideoPlugin.__enter__(self)
     try:
         self.screen = curses.initscr()
         curses.noecho()
         curses.cbreak()
         curses.nonl()
         curses.raw()
         self.orig_size = self.screen.getmaxyx()
         self.window = curses.newwin(self.height + self.border_y * 2,
                                     self.width + self.border_x * 2, 0, 0)
         self.window.nodelay(True)
         self.window.keypad(True)
         self.window.scrollok(False)
         curses.start_color()
         # curses mistakenly believes changing palettes works on macOS's Terminal.app
         self.can_change_palette = (not MACOS) and (
             curses.can_change_color() and curses.COLORS >= 16
             and curses.COLOR_PAIRS > 128)
         self._set_default_colours(16)
         bgcolor = self._curses_colour(7, 0, False)
         self.set_border_attr(0)
         self._resize(self.height, self.width)
         self.screen.clear()
     except Exception as e:
         # if setup fails, don't leave the terminal raw
         self._close()
         raise
Пример #16
0
    def _init_curses(self):
        self._stdscr = curses.initscr()
        curses.curs_set(0)
        curses.noecho()
        curses.cbreak()
        curses.nonl()
        self._stdscr.keypad(True)
        self._stdscr.refresh()

        # set custom color pairs
        # TODO check COLORS for number of
        # supported pairs
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(1, -1, -1)
        curses.init_pair(2, -1, curses.COLOR_BLACK)
        curses.init_pair(3, curses.COLOR_RED, -1)
        curses.init_pair(4, curses.COLOR_GREEN, -1)
        curses.init_pair(5, curses.COLOR_BLUE, -1)
        curses.init_pair(6, curses.COLOR_CYAN, -1)
        curses.init_pair(7, curses.COLOR_YELLOW, -1)
        curses.init_pair(8, curses.COLOR_MAGENTA, -1)

        self.menu_box = curses.newwin(1, curses.COLS, 0, 0)
        self.main_box = curses.newwin(curses.LINES - 2, curses.COLS, 1, 0)
        self.info_box = curses.newwin(1, curses.COLS, curses.LINES - 1, 0)

        self.main_box.idlok(1)
        self.main_box.scrollok(True)
Пример #17
0
 def __enter__(self):
     """Open ANSI interface."""
     VideoPlugin.__enter__(self)
     self.screen = curses.initscr()
     curses.noecho()
     curses.cbreak()
     curses.nonl()
     curses.raw()
     self.orig_size = self.screen.getmaxyx()
     self.underlay = curses.newwin(
         self.height + self.border_y*2, self.width + self.border_x*2, 0, 0
     )
     self.window = curses.newwin(self.height, self.width, self.border_y, self.border_x)
     self.window.nodelay(True)
     self.window.keypad(True)
     self.window.scrollok(False)
     curses.start_color()
     # curses mistakenly believes changing palettes works on macOS's Terminal.app
     self.can_change_palette = (not MACOS) and (
         curses.can_change_color() and curses.COLORS >= 16 and curses.COLOR_PAIRS > 128
     )
     sys.stdout.write(SET_TITLE % self.caption.encode('utf-8', 'replace'))
     sys.stdout.flush()
     self._set_default_colours(16)
     bgcolor = self._curses_colour(7, 0, False)
     # text and colour buffer
     self.text = [[[(u' ', bgcolor)]*self.width for _ in range(self.height)]]
     self.set_border_attr(0)
     self.screen.clear()
Пример #18
0
Файл: ttyfe.py Проект: kcr/snipe
    def __enter__(self):
        locale.setlocale(locale.LC_ALL, '')
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.nonl()
        curses.raw()

        termstate = termios.tcgetattr(0)
        termstate[6][termios.VINTR] = bytes([self.INTCHAR])
        nope = bytes([0])  # to disable a character
        termstate[6][termios.VQUIT] = nope
        termstate[6][termios.VSUSP] = nope
        if hasattr(termios, 'VDSUSP'):
            termstate[6][termios.VDSUSP] = nope  # pragma: nocover
        termstate[3] |= termios.ISIG
        termios.tcsetattr(0, termios.TCSANOW, termstate)

        self.stdscr.keypad(1)
        self.stdscr.nodelay(1)
        self.color_assigner = ttycolor.get_assigner()
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        self.orig_sigtstp = signal.signal(signal.SIGTSTP, self.sigtstp)
        self.main_pid = os.getpid()
        loop = asyncio.get_event_loop()
        loop.add_signal_handler(signal.SIGWINCH, self.sigwinch, loop)

        with mock.patch(
                'asyncio.unix_events._sighandler_noop', self.sighandler_op):
            loop.add_signal_handler(signal.SIGINT, self.sigint)

        return self
Пример #19
0
def _start_hearts(win, names):
	curses.use_default_colors()
	curses.init_pair(1, curses.COLOR_RED,   -1)
	curses.init_pair(2, curses.COLOR_BLACK, -1)
	curses.nonl()
	curses.resetty()
	curses.curs_set(0)
	curses.halfdelay(1)
	game = HeartsGame(names)
	#game.force_first_card()
	game.render(win)
	curses.doupdate()
	while True:
		try:
			c = win.getch()
			if c == -1:
				idle(game, win)
				continue
			if c == ord('q'): break
			win.clear()
			if c in bindings:
				bindings[c](game)
			else:
				win.addstr(0, 0, "Unhandled input: %d" % c)
			game.render(win)
			curses.doupdate()
		except Exception:
			idle(game, win)
Пример #20
0
    def __init__(self):

        self.text = dlist.DoubleList()
        self.text.append(" ")

        # Tekuca pozicija kursora
        self.y = 0
        self.x = 0
        self.i = 1
        # Pozicija gornjeg levog ugla ekrana
        self.line = 0
        self.column = 0

        # Broj linija teksta
        self.lines = 1
        # Duzina najduze linije u tekstu
        self.columns = 1

        self.insert_mode = False
        self.select_mode = False

        # Inicijalizacija curses biblioteke
        self.stdscr = curses.initscr()
        curses.nonl()
        curses.noecho()
        curses.cbreak()
        self.stdscr.keypad(1)

        # Visina i sirina ekrana
        self.height, self.width = self.stdscr.getmaxyx()
        # Uzeti u obzir meni i statusnu liniju
        self.height -= 2
Пример #21
0
 def __init__(self, board):
     stdscr = curses.initscr()
     stdscr.nodelay(1)
     curses.start_color()
     curses.init_pair(1, curses.COLOR_RED, curses.COLOR_RED)
     curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLUE)
     curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_GREEN)
     curses.init_pair(4, curses.COLOR_MAGENTA, curses.COLOR_MAGENTA)
     curses.init_pair(5, curses.COLOR_CYAN, curses.COLOR_CYAN)
     curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_YELLOW)
     curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK)
     curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_WHITE)
     curses.init_pair(10, 10, 10)
     curses.cbreak()
     stdscr.keypad(1)
     curses.nonl()
     curses.curs_set(0)
     curses.noecho()
     self.stdscr = stdscr
     self.preview_column = board.preview_column
     self.preview_row = board.preview_row
     self.num_rows = board.num_rows
     self.num_columns = board.num_columns
     self.block_width = 2
     self.border_width = 1
Пример #22
0
 def show(self):
     super().show()
     curses.nonl()
     curses.echo()
     curses.nocbreak()
     curses.curs_set(1)
     self.clear_input()
Пример #23
0
    def run (self):
        try:
            curses.curs_set(0)
        except:
            pass

        curses.use_default_colors()        
        self.stdscr.nodelay(1)
        curses.nonl()
        curses.noecho()
     
        self.generate_layout()

        self.update_active = True
        while (True):

            rc = self.wait_for_key_input()
            if not rc:
                break

            self.server_info_panel.draw()
            self.general_info_panel.draw()
            self.control_panel.draw()

            # can be different kinds of panels
            self.stats_panel.panel.top()
            self.stats_panel.draw()

            panel.update_panels(); 
            self.stdscr.refresh()
            sleep(0.01)
Пример #24
0
    def start(self):
        '''
        _orig_ESCDELAY = ''
        try:
            _orig_ESCDELAY = os.environ['ESCDELAY']
        except KeyError:
            pass
        os.environ['ESCDELAY'] = str(0)  # Stop escape key from pausing game
        '''
        self.screen = curses.initscr()
        self.has_colors = curses.has_colors()
        if self.has_colors:
            curses.start_color()
        curses.noecho()  # Don't display kb-input
        curses.cbreak(
        )  # Send characters immediately to getch() instead of storing them in buffer.
        curses.nonl()  # Allow to detect Enter-key press
        self.screen.keypad(True)  # Allow curses.KEY_LEFT/KEY_RIGHT/... keys
        self.hide_cursor()  # Hide cursor
        self.set_keyboard_delay(0)  # By default don't block keyboard
        self.screen_height, self.screen_width = self.screen.getmaxyx()
        # init color attrs
        default_attr = curses.color_pair(0)
        default_pair = curses.pair_number(default_attr)
        self.fore_color, self.back_color = curses.pair_content(default_pair)

        self.color_attrs = dict(
        )  # dict{ (fg_color, bg_color) -> curses attr }
        self.color_attrs[(self.fore_color, self.back_color)] = default_attr
        self.next_color_pair = 1
Пример #25
0
    def run(self, win):
        curses.cbreak()
        curses.nonl()
        curses.noecho()
        curses.start_color()
        curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)

        while True:
            self.redraw(win)

            ch = win.getch()
            if ch in NEXT:
                self.blockno = min(self.blockno + 1, len(self.blocks) - 1)
            elif ch in PREV:
                self.blockno = max(self.blockno - 1, 0)
            elif ch in FIRST:
                self.blockno = 0
            elif ch in LAST:
                self.blockno = len(self.blocks) - 1
            elif ch in RANDOM:
                self.blockno = random.randint(0, len(self.blocks) - 1)
            elif ch in EDIT:
                self.edit(win)
            elif ch in EDIT_ALL:
                self.edit_all(win)
            elif ch in HELP:
                self.print_help(win)
            elif ch in QUIT:
                return 0
Пример #26
0
    def _init_curses(self):

        # initialize curses
        self.stdscr = curses.initscr()

        # set custom color pairs
        # TODO check COLORS for number of
        # supported pairs
        curses.start_color()
        curses.use_default_colors()
        curses.init_pair(1, -1, -1)
        curses.init_pair(2, curses.COLOR_BLUE, -1)
        curses.init_pair(3, curses.COLOR_RED, -1)
        curses.init_pair(4, curses.COLOR_CYAN, -1)
        curses.init_pair(5, curses.COLOR_YELLOW, -1)
        curses.init_pair(6, curses.COLOR_MAGENTA, -1)
        curses.init_pair(7, curses.COLOR_GREEN, -1)
        curses.init_pair(8, curses.COLOR_BLUE, -1)
        curses.init_pair(9, curses.COLOR_BLUE, -1)

        # change terminal behaviour
        curses.noecho()
        curses.cbreak()
        curses.nonl()
        self.stdscr.keypad(True)

        # create windows
        self._output_box = curses.newwin(curses.LINES - 3, curses.COLS, 0, 0)
        self._output_box.scrollok(True)
        self._output_box.idlok(1)
        self._info_box = curses.newwin(1, curses.COLS, curses.LINES - 2, 0)
        self._input_box = curses.newwin(1, curses.COLS, curses.LINES - 1, 0)
        self._input_buffer = ''
        self.set_input_status('none', 'none')
Пример #27
0
    async def __aenter__(self):
        locale.setlocale(locale.LC_ALL, '')
        self.stdscr = curses.initscr()
        curses.noecho()
        curses.nonl()
        curses.raw()

        termstate = termios.tcgetattr(0)
        termstate[6][termios.VINTR] = bytes([self.INTCHAR])
        nope = bytes([0])  # to disable a character
        termstate[6][termios.VQUIT] = nope
        termstate[6][termios.VSUSP] = nope
        if hasattr(termios, 'VDSUSP'):  # pragma: nocover
            termstate[6][termios.VDSUSP] = nope
        termstate[3] |= termios.ISIG
        termios.tcsetattr(0, termios.TCSANOW, termstate)

        self.stdscr.keypad(1)
        self.stdscr.nodelay(1)
        self.color_assigner = ttycolor.get_assigner()
        self.maxy, self.maxx = self.stdscr.getmaxyx()
        self.main_pid = os.getpid()
        self.supervisor = await imbroglio.get_supervisor()
        self.orig_sigtstp = signal.signal(signal.SIGTSTP, self.sigtstp)
        self.orig_sigwinch = signal.signal(signal.SIGWINCH, self.sigwinch)
        self.orig_sigint = signal.signal(signal.SIGINT, self.sigint)

        self.running = True

        return self
Пример #28
0
def mp_initialize():
    global q, \
            win_condition, \
            map_fog_of_war, \
            score_counter, \
            score_top

    # Set global variables
    q = -1
    win_condition = 0
    map_fog_of_war = set()
    score_counter = 0
    score_top = open('score', 'r').readlines()

    # Makes the cursor not blink
    curses.curs_set(False)

    # Speeds up vertical movement.
    curses.nonl()

    # Makes colors
    if curses.has_colors():
        curses.start_color()
    curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
    curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_WHITE)
    curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_WHITE)
    curses.init_pair(4, curses.COLOR_YELLOW, curses.COLOR_WHITE)
    curses.init_pair(5, curses.COLOR_BLACK, curses.COLOR_WHITE)
    curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_CYAN)
    curses.init_pair(7, curses.COLOR_YELLOW, curses.COLOR_CYAN)
Пример #29
0
 def __init__(self, game, screen):
     # special curses characters are initialized after initscr()
     if not config.ascii:
         global TILES
         TILES = (
             curses.ACS_BULLET,
             curses.ACS_DARROW,
             curses.ACS_UARROW,
             curses.ACS_DIAMOND,
             curses.ACS_DIAMOND,
             curses.ACS_DIAMOND,
             curses.ACS_BLOCK,
         )
     self.game = game
     curses.nonl()
     (self.lines, self.cols) = screen.getmaxyx()
     # message window
     self.wmsg = curses.newwin(self.lines - 21, self.cols, 0, 0)
     self.wmsg.idlok(True)
     self.wmsg.scrollok(True)
     # overhead game view
     self.main = curses.newwin(19, self.cols, self.lines - 21, 0)
     self.main.keypad(True)
     # status line
     self.stat = curses.newwin(2, self.cols, self.lines - 2, 0)
Пример #30
0
	def __init__(self, stdscr):
		# Initialize ncurses here.
		#curses.parent = Window()
		self.parent = CPPWindow(0, 0, 0, 0, stdscr, True)
		'''
		curses.keypad(stdscr, TRUE)
		curses.cbreak()
		curses.nonl()
		curses.noecho()'''
		stdscr.keypad(1)
		curses.cbreak()
		curses.nonl()
		curses.noecho()
		#curses.timeout(250) # 0.25 second getch() timeout!
		self.parent.ptr.timeout(250)
		curses.curs_set(0) # hide cursor

		# Get map dimensions.
		self.mapW = self.parent.w // 2 - 2
		self.mapH = self.parent.h - 3 - 2

		# Prepare each subwindow.
		self.title = CPPWindow(0, 0, self.parent.w, 3, 0, False)
		self.map = CPPWindow(0, 3, self.mapW + 2, self.mapH + 2, 0, False)
		self.menu = CPPWindow(self.parent.w / 2, 3, self.parent.w / 2, self.parent.h - 3, 0, False)

		# Init colors.
		if (curses.has_colors()):
			curses.start_color()
			curses.init_pair(1, curses.COLOR_WHITE,  curses.COLOR_BLACK)
			curses.init_pair(2, curses.COLOR_GREEN,  curses.COLOR_BLACK)
			curses.init_pair(3, curses.COLOR_BLUE,  curses.COLOR_BLACK)

		# Create map vector and initialize.
		self.m_map = [[Cell() for y in range(self.mapH)] for x in range(self.mapW)]
Пример #31
0
def _init(stdscr):
    curses.start_color()
    curses.use_default_colors()

    curses.raw()
    curses.nonl()
    stdscr.leaveok(1)
Пример #32
0
def main(stdscr):
    curses.curs_set(False) # make cursor invisble
    curses.use_default_colors()
    curses.nonl()
    config.init_all_color_pairs()

    interface = Interface(stdscr)
    interface.main()
Пример #33
0
 def __init__(self, **kwargs):
     """ Initialise the text interface. """
     video.VideoPlugin.__init__(self)
     self.curses_init = False
     if not curses:
         raise video.InitFailed()
     # set the ESC-key delay to 25 ms unless otherwise set
     # set_escdelay seems to be unavailable on python curses.
     if not os.environ.has_key('ESCDELAY'):
         os.environ['ESCDELAY'] = '25'
     self.curses_init = True
     self.screen = curses.initscr()
     self.orig_size = self.screen.getmaxyx()
     curses.noecho()
     curses.cbreak()
     curses.nonl()
     curses.raw()
     curses.start_color()
     self.screen.clear()
     self.height, self.width = 25, 80
     # border width percentage
     border_width = kwargs.get('border_width', 0)
     self.border_y = int(round((self.height * border_width)/200.))
     self.border_x = int(round((self.width * border_width)/200.))
     self.underlay = curses.newwin(
         self.height + self.border_y*2, self.width + self.border_x*2, 0, 0)
     self.window = curses.newwin(self.height, self.width, self.border_y, self.border_x)
     self.window.nodelay(True)
     self.window.keypad(True)
     self.window.scrollok(False)
     self.can_change_palette = (curses.can_change_color() and curses.COLORS >= 16
                           and curses.COLOR_PAIRS > 128)
     self.caption = kwargs.get('caption', '')
     sys.stdout.write(ansi.esc_set_title % self.caption)
     sys.stdout.flush()
     self._set_default_colours(16)
     # cursor is visible
     self.cursor_visible = True
     # 1 is line ('visible'), 2 is block ('highly visible'), 3 is invisible
     self.cursor_shape = 1
     # current cursor position
     self.cursor_row = 1
     self.cursor_col = 1
     # last colour used
     self.last_colour = None
     # text and colour buffer
     self.num_pages = 1
     self.vpagenum, self.apagenum = 0, 0
     bgcolor = self._curses_colour(7, 0, False)
     self.text = [[[(u' ', bgcolor)]*self.width for _ in range(self.height)]]
     self.f12_active = False
     self.set_border_attr(0)
     # set codepage
     try:
         self.codepage = kwargs['codepage']
     except KeyError:
         logging.error('No codepage supplied to text-based interface.')
         raise video.InitFailed()
Пример #34
0
def ncurses():
    """
    Context manager for curses applications.  This does a number of
    things beyond what curses.wrapper() does.

    - Redirect stdout to stderr.  This is done so that we can still
      use the ncurses interface from within a pipe or subshell.
    - Drop the escape delay down to 25ms, similar to vim.
    - Remove newline mode.

    An ncurses screen is returned by the manager.  If any exceptions
    occur, all of the setup performed by the manager is undone before
    raising the original exception.  This should guarantee that any
    bugs in the code will not leave the user with a messed up shell.
    """
    # Push stdout to stderr so that we still get the curses
    # output while inside of a pipe or subshell
    old_stdout = sys.__stdout__
    old_stdout_fd = os.dup(sys.stdout.fileno())
    os.dup2(sys.stderr.fileno(), sys.stdout.fileno())

    # Reduce the timeout after receiving an escape character, there
    # doesn't seem to be a way to do this via curses so we have to
    # set the environment variable before creating the screen.
    if 'ESCDELAY' not in os.environ:
        os.environ['ESCDELAY'] = '25'

    scr = curses.initscr()
    curses.start_color()
    curses.use_default_colors()
    for i in range(curses.COLORS):
        curses.init_pair(i + 1, i, -1)

    curses.noecho()
    curses.cbreak()
    curses.raw()
    curses.nonl()
    curses.curs_set(2)
    scr.keypad(1)

    exc = None
    try:
        yield scr
    except Exception:
        exc = sys.exc_info()

    scr.keypad(0)
    curses.nl()
    curses.nocbreak()
    curses.echo()
    curses.endwin()

    os.dup2(old_stdout_fd, sys.stdout.fileno())
    sys.stdout = old_stdout

    if exc is not None:
        exc[0].with_traceback(exc[1], exc[2])
Пример #35
0
 def __init__(self, input_queue, video_queue, **kwargs):
     """Initialise the text interface."""
     base.VideoPlugin.__init__(self, input_queue, video_queue)
     # we need to ensure setlocale() has been run first to allow unicode input
     self._encoding = locale.getpreferredencoding()
     self.curses_init = False
     if not curses:
         raise base.InitFailed()
     # set the ESC-key delay to 25 ms unless otherwise set
     # set_escdelay seems to be unavailable on python curses.
     if not os.environ.has_key('ESCDELAY'):
         os.environ['ESCDELAY'] = '25'
     self.curses_init = True
     self.screen = curses.initscr()
     self.orig_size = self.screen.getmaxyx()
     curses.noecho()
     curses.cbreak()
     curses.nonl()
     curses.raw()
     curses.start_color()
     self.screen.clear()
     self.height, self.width = 25, 80
     # border width percentage
     border_width = kwargs.get('border_width', 0)
     self.border_y = int(round((self.height * border_width) / 200.))
     self.border_x = int(round((self.width * border_width) / 200.))
     self.underlay = curses.newwin(self.height + self.border_y * 2,
                                   self.width + self.border_x * 2, 0, 0)
     self.window = curses.newwin(self.height, self.width, self.border_y,
                                 self.border_x)
     self.window.nodelay(True)
     self.window.keypad(True)
     self.window.scrollok(False)
     self.can_change_palette = (curses.can_change_color()
                                and curses.COLORS >= 16
                                and curses.COLOR_PAIRS > 128)
     self.caption = kwargs.get('caption', '')
     sys.stdout.write(ansi.esc_set_title % self.caption)
     sys.stdout.flush()
     self._set_default_colours(16)
     # cursor is visible
     self.cursor_visible = True
     # 1 is line ('visible'), 2 is block ('highly visible'), 3 is invisible
     self.cursor_shape = 1
     # current cursor position
     self.cursor_row = 1
     self.cursor_col = 1
     # last colour used
     self.last_colour = None
     # text and colour buffer
     self.num_pages = 1
     self.vpagenum, self.apagenum = 0, 0
     bgcolor = self._curses_colour(7, 0, False)
     self.text = [[[(u' ', bgcolor)] * self.width
                   for _ in range(self.height)]]
     self.f12_active = False
     self.set_border_attr(0)
Пример #36
0
def ncurses():
    """
    Context manager for curses applications.  This does a number of
    things beyond what curses.wrapper() does.

    - Redirect stdout to stderr.  This is done so that we can still
      use the ncurses interface from within a pipe or subshell.
    - Drop the escape delay down to 25ms, similar to vim.
    - Remove newline mode.

    An ncurses screen is returned by the manager.  If any exceptions
    occur, all of the setup performed by the manager is undone before
    raising the original exception.  This should guarantee that any
    bugs in the code will not leave the user with a messed up shell.
    """
    # Push stdout to stderr so that we still get the curses
    # output while inside of a pipe or subshell
    old_stdout = sys.__stdout__
    old_stdout_fd = os.dup(sys.stdout.fileno())
    os.dup2(sys.stderr.fileno(), sys.stdout.fileno())

    # Reduce the timeout after receiving an escape character, there
    # doesn't seem to be a way to do this via curses so we have to
    # set the environment variable before creating the screen.
    if not 'ESCDELAY' in os.environ:
        os.environ['ESCDELAY'] = '25'

    scr = curses.initscr()
    curses.start_color()
    curses.use_default_colors()
    _ = [curses.init_pair(i + 1, i, -1) for i in range(curses.COLORS)]

    curses.noecho()
    curses.cbreak()
    curses.raw()
    curses.nonl()
    curses.curs_set(2)
    scr.keypad(1)

    exc = None
    try:
        yield scr
    #pylint: disable=W0703
    except Exception:
        exc = sys.exc_info()

    scr.keypad(0)
    curses.nl()
    curses.nocbreak()
    curses.echo()
    curses.endwin()

    os.dup2(old_stdout_fd, sys.stdout.fileno())
    sys.stdout = old_stdout

    if exc is not None:
        six.reraise(exc[0], exc[1], exc[2])
Пример #37
0
 def start(self):
     self.started = True
     self.win = curses.initscr()
     self.cursor = Cursor(self.win)
     atexit.register(self.stop)
     curses.start_color()
     curses.nonl()
     self.cursor.hide()
     self.height, self.width = self.win.getmaxyx()
Пример #38
0
def start():
	global screen
	screen = curses.initscr()
	curses.noecho()
	curses.cbreak()
	curses.nonl()
	curses.curs_set(0)
	screen.keypad(1)
	screen.timeout(0)
	screen.scrollok(False)
Пример #39
0
 def __prepare_screen(self):
     screen = curses.initscr()
     screen.scrollok(True) 
     curses.noecho()
     curses.nonl()
     curses.cbreak()
     if curses.has_colors():
         curses.start_color()
         curses.use_default_colors()
     return screen
Пример #40
0
def init_rt():
    stdscr = curses.initscr()
    curses.start_color()
    curses.cbreak()
    curses.noecho()
    curses.nonl()
    curses.intrflush(0)
    stdscr.keypad(1)
    stdscr.nodelay(1)
    return stdscr
Пример #41
0
def begin_curses():
    win = curses.initscr()
    curses.noecho()
    curses.cbreak()
    curses.nonl()
    curses.curs_set(0)
    curses.meta(1)
    curses.start_color()
    curses.use_default_colors()
    return win
Пример #42
0
    def setup_screen(self):
        self.stdscr = curses.initscr()
        curses.start_color()
        self.init_colors()

        curses.noecho()
        curses.cbreak()
        curses.curs_set(0)
        curses.nonl()
        self.stdscr.keypad(1)
Пример #43
0
def begin_curses():
    win = curses.initscr()
    curses.noecho()
    curses.cbreak()
    curses.nonl()
    curses.curs_set(0)
    curses.meta(1)
    curses.start_color()
    curses.use_default_colors()
    return win
Пример #44
0
    def __init__(self):
        self.screen = curses.initscr()
        curses.cbreak()
        curses.noecho()
        curses.nonl()
        #self.screen.nodelay(1)
        self.screen.timeout(100)

        self.tty = open("/dev/tty", "r")
        set_nonblocking(self.tty)
Пример #45
0
 def _initscr_plus(self):
     self._scr = curses.initscr()
     self._max_y, self._max_x = self._scr.getmaxyx()
     curses.noecho()
     curses.nonl()
     curses.cbreak()
     curses.typeahead(-1)
     curses.curs_set(0)
     # in case curses has other ideas
     fcntl.fcntl(0, fcntl.F_SETFL, os.O_NONBLOCK)
Пример #46
0
    def setup_screen(self):
        self.stdscr = curses.initscr()
        curses.start_color()
        self.init_colors()

        curses.noecho()
        curses.cbreak()
        curses.curs_set(0)
        curses.nonl()
        self.stdscr.keypad(1)
Пример #47
0
 def _initscr_plus(self):
     self._scr = curses.initscr()
     self._max_y, self._max_x = self._scr.getmaxyx()
     curses.noecho()
     curses.nonl()
     curses.cbreak()
     curses.typeahead(-1)
     curses.curs_set(0)
     # in case curses has other ideas
     fcntl.fcntl(0, fcntl.F_SETFL, os.O_NONBLOCK)
Пример #48
0
 def init_display(self):
     self.max_y, self.max_x = self.screen.getmaxyx()
     self.lines = [""]*(self.max_y - 1)
     self.prev_lines = [""]*(self.max_y - 1)
     curses.noecho()
     curses.nonl()
     curses.cbreak()
     curses.typeahead(-1)
     curses.curs_set(0)
     self.screen.attron(curses.A_REVERSE)
Пример #49
0
def __leaf_00(ql: Qiling):
    curses.nonl()
    key = parse_key(ql.os.stdscr.getch())
    ql.log.debug(f"Get key: {hex(key)}")
    if curses.ascii.isascii(key):
        ql.arch.regs.al = key
    else:
        ql.arch.regs.al = 0
    ql.arch.regs.ah = get_scan_code(key)
    curses.nl()
Пример #50
0
def _init(stdscr):
    if not hasattr(stdscr, 'get_wch'):
        raise RuntimeError(
                'Kaa requires curses library with wide charater support.')
        
    curses.start_color()
    curses.use_default_colors()

    curses.raw()
    curses.nonl()
    stdscr.leaveok(1)
Пример #51
0
 def stop(self):
     """Stop UI and return to normal interaction"""
     try:
         curses.curs_set(2)
     except:
         pass
     curses.nonl()  # Enter newline mode
     curses.nocbreak()
     curses.echo()
     self.window.keypad(False)
     curses.endwin()
Пример #52
0
def _init_screen():
    os.environ.setdefault('ESCDELAY', '25')
    stdscr = curses.initscr()
    curses.noecho()
    curses.cbreak()
    # <enter> is not transformed into '\n' so it can be differentiated from ^J
    curses.nonl()
    # ^S / ^Q / ^Z / ^\ are passed through
    curses.raw()
    stdscr.keypad(True)
    return stdscr
Пример #53
0
def init_curses():
    global w

    w = curses.initscr()
    curses.nonl()
    curses.cbreak()
    curses.noecho()

    curses.start_color()
    for i in range(1, nr_curses_colors + 1):
        curses.init_pair(i, curses_colors[i - 1], curses.COLOR_BLACK)
Пример #54
0
def init_curses():
    global w

    w = curses.initscr()
    curses.nonl()
    curses.cbreak()
    curses.noecho()

    curses.start_color()
    for i in range(1, nr_curses_colors + 1):
        curses.init_pair(i, curses_colors[i - 1], curses.COLOR_BLACK)
Пример #55
0
def start():
    global screen

    screen = curses.initscr()
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
    curses.nonl()
    screen.keypad(1)
    screen.timeout(0)
    screen.scrollok(False)
Пример #56
0
 def stop(self):
     """Stop UI and return to normal interaction"""
     try:
         curses.curs_set(2)  # Show cursor
     except:
         pass
     curses.nonl()  # Enter newline mode
     curses.nocbreak()
     curses.echo()
     self.window.keypad(False)
     curses.endwin()
Пример #57
0
def init():
    screen=curses.initscr()
    curses.start_color()
    curses.cbreak()
    curses.meta(1)
    curses.noecho()
    curses.nonl()
    curses.def_prog_mode()
    curses.endwin()
    curses.def_shell_mode()
    curses.reset_prog_mode()
    return Screen(screen)
Пример #58
0
 def setup_screen(self):
     cur = curses.initscr()  # Initialize curses.
     curses.cbreak()
     curses.noecho()
     curses.nonl()
     cur.refresh()
     screen = curses.newwin(25,80)
     screen.nodelay(1)
     screen.keypad(1)
     screen.scrollok(True)
     screen.idlok(1)
     screen.refresh()
     return screen
Пример #59
0
 def __init__(self):
     if not self.stdscr:
         self.__class__.stdscr = curses.initscr()
         self.stdscr.notimeout(0)
         self.stdscr.keypad(1)
         curses.noecho()
         curses.cbreak()
         curses.raw()
         curses.nonl()
         if curses.has_colors():
             curses.start_color()
             curses.use_default_colors()
         self.stdscr.refresh()