コード例 #1
0
    def _display_msg(self, message):
        window_size = get_terminal_size()[0]
        if message is None:
            return ''

        if not isinstance(message, six.string_types):
            log.warning('Did not pass str')
            return ''

        # Home grown word wrap
        def format_msg():
            formatted = []
            finished = ['\n']
            count = 0
            words = message.split(' ')
            for w in words:
                w = w + ' '
                if count + len(w) > window_size / 2:
                    finished.append(''.join(formatted).center(window_size))
                    finished.append('\n')
                    count = len(w)
                    # Starting a new line.
                    formatted = []
                    formatted.append(w)
                else:
                    formatted.append(w)
                    count += len(w)
            finished.append(''.join(formatted).center(window_size))
            finished.append('\n')
            return ''.join(finished)

        print((format_msg()))
コード例 #2
0
ファイル: menu.py プロジェクト: JMSwag/Menus
    def _display_msg(self, message):
        window_size = get_terminal_size()[0]
        if message is None:
            return ''

        if not isinstance(message, six.string_types):
            log.warning('Did not pass str')
            return ''

        # Home grown word wrap
        def format_msg():
            formatted = []
            finished = ['\n']
            count = 0
            words = message.split(' ')
            for w in words:
                w = w + ' '
                if count + len(w) > window_size / 2:
                    finished.append(''.join(formatted).center(window_size))
                    finished.append('\n')
                    count = len(w)
                    # Starting a new line.
                    formatted = []
                    formatted.append(w)
                else:
                    formatted.append(w)
                    count += len(w)
            finished.append(''.join(formatted).center(window_size))
            finished.append('\n')
            return ''.join(finished)
        print(format_msg())
コード例 #3
0
    def _display_menu_header(self):
        window_size = get_terminal_size()[0]

        # Adding some styling to the header
        def add_style():
            top = '*' * window_size + '\n'
            bottom = '\n' + '*' * window_size + '\n'

            header = self.app_name + ' - ' + self.menu_name
            header = header.center(window_size)
            msg = top + header + bottom
            return msg

        os.system(clear_screen_cmd)
        print((add_style()))
コード例 #4
0
ファイル: menu.py プロジェクト: JMSwag/Menus
    def _display_menu_header(self):
        window_size = get_terminal_size()[0]

        # Adding some styling to the header
        def add_style():
            top = '*' * window_size + '\n'
            bottom = '\n' + '*' * window_size + '\n'

            header = self.app_name + ' - ' + self.menu_name
            header = header.center(window_size)
            msg = top + header + bottom
            return msg

        os.system(clear_screen_cmd)
        print(add_style())