示例#1
0
    def set(self):
        self.gap: int = 5
        """Additional gap for term height, to accommodate space for header and nav options"""
        self.height: int = _get_terminal_size()[1] - self.gap
        """DataTerminal height, used to determine # of items that can be displayed"""

        self._set_clear_method()
示例#2
0
文件: style.py 项目: naryal2580/dore
def clear_line():
    """
    This function simply clears a line
    
    NOTE: Make sure the line you want to clear has not sent you to a new line..
    """
    line_width = _get_terminal_size()[0]
    print('\r' + ' '*line_width + '\r', end='', flush=True)
示例#3
0
文件: style.py 项目: naryal2580/dore
def bar_animation(progress, size=100, text='', division=2):
    """
    Simple bar animation
    
        Parameters:
            progress (int): Progress (eg.: In 5/7 `5` is progress here)
            size (int): Progress length (eg.: In 5/7 `7` is progress length here)
            text (str): Text to be displayed on the animation, during the animation
            division (int): Size of bar to be divided with width of the terminal
    """
    global TERM_WIDTH
    if TERM_WIDTH != _get_terminal_size()[0]:
        TERM_WIDTH = _get_terminal_size()[0]
        clear_line()
    if text:
        text = ' ' + str(text)
    total_width = int( ( _get_terminal_size()[0] - 2 ) / division)
    _progress = int( total_width * (progress / size) )
    if text:
        if len(text) > _progress:
            text1 = text[:_progress]
            text2 = text[_progress:]
            if len(text2) > total_width - _progress:
                text2 = text2[:total_width - _progress - 3] + '...'
            if _progress == total_width:
                text = text[:total_width - 3] + '...'
                print(f'\r|{invert}{text}{rst}|', end='', flush=True)
            elif total_width in (_progress + 1, _progress + 2):
                text = text[:total_width - 3] + '...'
                print(f'\r|{invert}{text}{rst}|', end='', flush=True)
            elif _progress < total_width:
                print(f'\r|{invert}{text1}{" "*(_progress - len(text1))}{rst}{text2}{" "*(total_width - _progress - len(text2))}|', end='', flush=True)
            # else:
            #     print('F')
        else:
            print(f'\r|{invert}{text}{" "*(_progress - len(text))}{rst}{" "*(total_width - _progress)}|', end='', flush=True)
    else:
        print(f'\r|{invert}{" "*_progress}{rst}{" "*(total_width - _progress)}|', end='', flush=True)
示例#4
0
文件: Utils.py 项目: rameshg87/topydo
def get_terminal_size():
    """
    Try to determine terminal size at run time. If that is not possible,
    returns the default size of 80x24.
    """
    try:
        sz = _get_terminal_size()
    except ValueError:
        """
        This can result from the 'underlying buffer being detached', which
        occurs during running the unittest on Windows (but not on Linux?)
        """
        terminal_size = namedtuple('Terminal_Size', 'columns lines')
        sz = terminal_size(80, 24)

    return sz
示例#5
0
            def inner():
                try:
                    # shutil.get_terminal_size was added to the standard
                    # library in Python 3.3
                    from shutil import \
                        get_terminal_size as \
                        _get_terminal_size  # pylint: disable=no-name-in-module

                    size = _get_terminal_size()
                except ValueError:
                    # This can result from the 'underlying buffer being detached', which
                    # occurs during running the unittest on Windows (but not on Linux?)
                    terminal_size = namedtuple('Terminal_Size',
                                               'columns lines')
                    size = terminal_size(80, 24)

                return size
示例#6
0
文件: Utils.py 项目: bram85/topydo
            def inner():
                try:
                    # shutil.get_terminal_size was added to the standard
                    # library in Python 3.3
                    try:
                        from shutil import get_terminal_size as _get_terminal_size  # pylint: disable=no-name-in-module
                    except ImportError:
                        from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size  # pylint: disable=import-error

                    size = _get_terminal_size()
                except ValueError:
                    # This can result from the 'underlying buffer being detached', which
                    # occurs during running the unittest on Windows (but not on Linux?)
                    terminal_size = namedtuple('Terminal_Size', 'columns lines')
                    size = terminal_size(80, 24)

                return size
示例#7
0
            def inner():
                try:
                    # shutil.get_terminal_size was added to the standard
                    # library in Python 3.3
                    try:
                        from shutil import get_terminal_size as _get_terminal_size  # pylint: disable=no-name-in-module
                    except ImportError:
                        from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size  # pylint: disable=import-error

                    sz = _get_terminal_size()
                except ValueError:
                    """
                    This can result from the 'underlying buffer being detached', which
                    occurs during running the unittest on Windows (but not on Linux?)
                    """
                    terminal_size = namedtuple('Terminal_Size',
                                               'columns lines')
                    sz = terminal_size(80, 24)

                return sz
示例#8
0
def get_terminal_size():
    """Returns terminal dimensions
    :return: Returns ``(width, height)``.  If there's no terminal
             to be found, we'll just return ``(80, 24)``.
    """
    try:
        # shutil.get_terminal_size was added to the standard
        # library in Python 3.3
        try:
            from shutil import get_terminal_size as _get_terminal_size  # pylint: disable=no-name-in-module
        except ImportError:
            from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size  # pylint: disable=import-error

        sz = _get_terminal_size()
    except ValueError:
        """
        This can result from the 'underlying buffer being detached', which
        occurs during running the unittest on Windows (but not on Linux?)
        """
        terminal_size = namedtuple('Terminal_Size', 'columns lines')
        sz = terminal_size(80, 24)

    return sz
示例#9
0
def get_terminal_size(defaultx=80, defaulty=25):
    return _get_terminal_size((defaultx, defaulty))
示例#10
0
def get_terminal_size(defaultx=80, defaulty=25):
    return _get_terminal_size((defaultx, defaulty))
示例#11
0
文件: style.py 项目: naryal2580/dore
from stoyled import *
from shutil import get_terminal_size as _get_terminal_size
from random import randint as _randint
from time import sleep
from threading import Thread as _Thread
from threading import Event

TERM_WIDTH = _get_terminal_size()[0]
ANIMATE = False


def banner(version, color=True):
    """
    A fancy banner, how can we forget this ;)

        Parameters:
            version: Version to be displayed in the banner
            color (bool): This just makes the banner look bold
    """
    logo = r'''
     ___  |/|
    (   ) |/|
  .-.| |  |_|  ___ .-. .--.   
 /   \ | (___)(   )   \    \  
|  .-. | (___) | ' .-. ;.-. ; 
| |  | | // \\ |  / (___) | | 
| |  | |// _ \\| |    | |/  | 
| |  | || | | || |    | ' _.' 
| '  | || |_| || |    | .'.-. 
' `-'  /\\_._//| |    ' `-' / 
 `.__,'  \_|_/(___)    `.__.'  --v{version} by naryal2580