當前位置: 首頁>>代碼示例>>Python>>正文


Python os.terminal_size方法代碼示例

本文整理匯總了Python中os.terminal_size方法的典型用法代碼示例。如果您正苦於以下問題:Python os.terminal_size方法的具體用法?Python os.terminal_size怎麽用?Python os.terminal_size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.terminal_size方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_terminal_size_stderr

# 需要導入模塊: import os [as 別名]
# 或者: from os import terminal_size [as 別名]
def get_terminal_size_stderr(fallback=(80, 24)):
    """
    Unlike shutil.get_terminal_size, which looks at stdout, this looks at stderr.
    """
    try:
        size = os.get_terminal_size(sys.__stderr__.fileno())
    except (AttributeError, ValueError, OSError):
        size = os.terminal_size(fallback)
    return size 
開發者ID:rrwick,項目名稱:Rebaler,代碼行數:11,代碼來源:log.py

示例2: test_get_terminal_size

# 需要導入模塊: import os [as 別名]
# 或者: from os import terminal_size [as 別名]
def test_get_terminal_size(self, mock_os):
        ts = os.terminal_size((10, 5))
        mock_os.get_terminal_size.return_value = ts
        width = utils.terminal_width(sys.stdout)
        self.assertEqual(10, width)
        mock_os.get_terminal_size.side_effect = OSError()
        width = utils.terminal_width(sys.stdout)
        self.assertIs(None, width) 
開發者ID:openstack,項目名稱:cliff,代碼行數:10,代碼來源:test_utils.py

示例3: __enter__

# 需要導入模塊: import os [as 別名]
# 或者: from os import terminal_size [as 別名]
def __enter__(self) -> os.terminal_size:
        real_term_geometry = shutil.get_terminal_size((80, 80))
        if sys.stdin.isatty():
            tty.setcbreak(sys.stdin.fileno())
            if sys.stderr.isatty():
                tty.setcbreak(sys.stderr.fileno())
            if sys.stdout.isatty():
                tty.setcbreak(sys.stdout.fileno())
        return real_term_geometry 
開發者ID:actionless,項目名稱:pikaur,代碼行數:11,代碼來源:pikspect.py

示例4: get_terminal_size

# 需要導入模塊: import os [as 別名]
# 或者: from os import terminal_size [as 別名]
def get_terminal_size(fallback=(80, 24)):
    """Get the size of the terminal window.

    For each of the two dimensions, the environment variable, COLUMNS
    and LINES respectively, is checked. If the variable is defined and
    the value is a positive integer, it is used.

    When COLUMNS or LINES is not defined, which is the common case,
    the terminal connected to sys.__stdout__ is queried
    by invoking os.get_terminal_size.

    If the terminal size cannot be successfully queried, either because
    the system doesn't support querying, or because we are not
    connected to a terminal, the value given in fallback parameter
    is used. Fallback defaults to (80, 24) which is the default
    size used by many terminal emulators.

    The value returned is a named tuple of type os.terminal_size.
    """
    # columns, lines are the working values
    try:
        columns = int(os.environ['COLUMNS'])
    except (KeyError, ValueError):
        columns = 0

    try:
        lines = int(os.environ['LINES'])
    except (KeyError, ValueError):
        lines = 0

    # only query if necessary
    if columns <= 0 or lines <= 0:
        try:
            size = os.get_terminal_size(sys.__stdout__.fileno())
        except (NameError, OSError):
            size = os.terminal_size(fallback)
        if columns <= 0:
            columns = size.columns
        if lines <= 0:
            lines = size.lines

    return os.terminal_size((columns, lines)) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:44,代碼來源:shutil.py

示例5: get_terminal_size

# 需要導入模塊: import os [as 別名]
# 或者: from os import terminal_size [as 別名]
def get_terminal_size(fallback=(80, 24)):
    """Get the size of the terminal window.

    For each of the two dimensions, the environment variable, COLUMNS
    and LINES respectively, is checked. If the variable is defined and
    the value is a positive integer, it is used.

    When COLUMNS or LINES is not defined, which is the common case,
    the terminal connected to sys.__stdout__ is queried
    by invoking os.get_terminal_size.

    If the terminal size cannot be successfully queried, either because
    the system doesn't support querying, or because we are not
    connected to a terminal, the value given in fallback parameter
    is used. Fallback defaults to (80, 24) which is the default
    size used by many terminal emulators.

    The value returned is a named tuple of type os.terminal_size.
    """
    # columns, lines are the working values
    try:
        columns = int(os.environ['COLUMNS'])
    except (KeyError, ValueError):
        columns = 0

    try:
        lines = int(os.environ['LINES'])
    except (KeyError, ValueError):
        lines = 0

    # only query if necessary
    if columns <= 0 or lines <= 0:
        try:
            size = os.get_terminal_size(sys.__stdout__.fileno())
        except (AttributeError, ValueError, OSError):
            # stdout is None, closed, detached, or not a terminal, or
            # os.get_terminal_size() is unsupported
            size = os.terminal_size(fallback)
        if columns <= 0:
            columns = size.columns
        if lines <= 0:
            lines = size.lines

    return os.terminal_size((columns, lines)) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:46,代碼來源:shutil.py


注:本文中的os.terminal_size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。