Beispiel #1
0
    def set_focus_screen(self, new_focus_index):
        if self.focus_cursor != None:
            self.cursors[self.focus_screen_index] = self.focus_cursor
            echo_remove_cursor(self.focus_cursor, self.focus_screen)

        self.focus_screen_index = new_focus_index
        self.cursors = [
            csr.Cursor(int(a_screen.origin[0]), int(a_screen.origin[1]), self.term) for a_screen in self.screens
        ]
        self.focus_cursor = self.cursors[self.focus_screen_index]
        self.focus_screen = self.screens[self.focus_screen_index]
        self.new_focus_cursor = self.focus_cursor
Beispiel #2
0
    def handle_input(self, inp):
        term = self.term

        if inp == chr(3) or self.exit_signal_received:
            if self.logger != None:
                self.logger.log("handle_input: exiting")
            # ^c exits
            return -1
        elif self.command != None:
            self.handle_command()

            if self.logger != None:
                self.logger.log("handle_input: calling handle_command, command: {}".format(self.command))
            return 0

        elif inp.code == term.KEY_ESCAPE:
            self.read_command()

            if self.logger != None:
                self.logger.log("handle_input: called read_command, command: {}".format(self.command))

            return 0
        elif inp == chr(12):
            # ^l refreshes
            self.draw()

            if self.logger != None:
                self.logger.log("handle_input: refreshing, calling draw")

            return 0
        elif inp.code in [term.KEY_BACKSPACE, term.KEY_DELETE]:
            echo_remove_cursor(self.focus_cursor, self.focus_screen, logger=self.logger)
            self.focus_cursor = csr.left_of(self.focus_cursor, 1, screen=self.focus_screen, logger=self.logger)
            self.focus_screen.delete_cell(self.focus_cursor, logger=self.logger)

            return 0
        else:
            echo_remove_cursor(self.focus_cursor, self.focus_screen, logger=self.logger)
            self.focus_cursor, move_made = csr.lookup_move(
                inp.code, self.focus_cursor, screen=self.focus_screen, logger=self.logger
            )
            if move_made:
                return 0

        if input_filter(inp):
            self.logger.log("Attempting to write {} to screen.".format(str(inp)))
            self.focus_screen.write_cell(self.focus_cursor, str(inp), logger=self.logger)
            echo_remove_cursor(self.focus_cursor, self.focus_screen, logger=self.logger)
            self.focus_cursor = csr.right_of(self.focus_cursor, 1, screen=self.focus_screen, logger=self.logger)
            return 0
        else:
            self.logger.log("{} not considered input.".format(str(inp)))

        return 1