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


Python shutil.get_terminal_size方法代碼示例

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


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

示例1: get_terminal_size

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_terminal_size():
    """
    Detect terminal size and return tuple = (width, height).

    Only to be used when running in a terminal. Note that the IPython notebook,
    IPython zmq frontends, or IDLE do not run in a terminal,
    """
    import platform

    if PY3:
        return shutil.get_terminal_size()

    current_os = platform.system()
    tuple_xy = None
    if current_os == 'Windows':
        tuple_xy = _get_terminal_size_windows()
        if tuple_xy is None:
            tuple_xy = _get_terminal_size_tput()
            # needed for window's python in cygwin's xterm!
    if (current_os == 'Linux' or current_os == 'Darwin' or
            current_os.startswith('CYGWIN')):
        tuple_xy = _get_terminal_size_linux()
    if tuple_xy is None:
        tuple_xy = (80, 25)      # default value
    return tuple_xy 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:terminal.py

示例2: do_pp

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def do_pp(self, arg):
        """[width]pp expression
        Pretty-print the value of the expression.
        """
        width = getattr(arg, "cmd_count", None)
        try:
            val = self._getval(arg)
        except:
            return
        if width is None:
            try:
                width, _ = self.get_terminal_size()
            except Exception as exc:
                self.message("warning: could not get terminal size ({})".format(exc))
                width = None
        try:
            pprint.pprint(val, self.stdout, width=width)
        except:
            exc_info = sys.exc_info()[:2]
            self.error(traceback.format_exception_only(*exc_info)[-1].strip()) 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:22,代碼來源:pdbpp.py

示例3: get_terminal_size

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_terminal_size():
        fallback = (80, 24)
        try:
            from shutil import get_terminal_size
        except ImportError:
            try:
                import termios
                import fcntl
                import struct
                call = fcntl.ioctl(0, termios.TIOCGWINSZ, "\x00"*8)
                height, width = struct.unpack("hhhh", call)[:2]
            except (SystemExit, KeyboardInterrupt):
                raise
            except:
                width = int(os.environ.get('COLUMNS', fallback[0]))
                height = int(os.environ.get('COLUMNS', fallback[1]))
            # Work around above returning width, height = 0, 0 in Emacs
            width = width if width != 0 else fallback[0]
            height = height if height != 0 else fallback[1]
            return width, height
        else:
            return get_terminal_size(fallback) 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:24,代碼來源:pdbpp.py

示例4: refresh

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def refresh(self, cur_len):
        terminal_width = get_terminal_size().columns  # 獲取終端寬度
        info = "%s '%s'...  %.2f%%" % (
            self.prefix_info,
            self.title,
            cur_len / self.total * 100,
        )
        while len(info) > terminal_width - 20:
            self.title = self.title[0:-4] + "..."
            info = "%s '%s'...  %.2f%%" % (
                self.prefix_info,
                self.title,
                cur_len / self.total * 100,
            )
        end_str = "\r" if cur_len < self.total else "\n"
        print(info, end=end_str) 
開發者ID:gyh1621,項目名稱:GetSubtitles,代碼行數:18,代碼來源:util.py

示例5: test_stty_match

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def test_stty_match(self):
        """Check if stty returns the same results ignoring env

        This test will fail if stdin and stdout are connected to
        different terminals with different sizes. Nevertheless, such
        situations should be pretty rare.
        """
        try:
            size = subprocess.check_output(['stty', 'size']).decode().split()
        except (FileNotFoundError, subprocess.CalledProcessError):
            self.skipTest("stty invocation failed")
        expected = (int(size[1]), int(size[0])) # reversed order

        with support.EnvironmentVarGuard() as env:
            del env['LINES']
            del env['COLUMNS']
            actual = shutil.get_terminal_size()

        self.assertEqual(expected, actual) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:21,代碼來源:test_shutil.py

示例6: get_data

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_data(self, wrap=True):
        if wrap:
            terminal_size = shutil.get_terminal_size((80, 40))
            wrap_columns = terminal_size.columns
            if wrap_columns > int(config.CONFIG.parser['info_display_max_columns']):
                wrap_columns = int(config.CONFIG.parser['info_display_max_columns'])
            return '\n'.join([textwrap.fill(x, wrap_columns) for x in ''.join(self.fed).split('\n')])
        return ''.join(self.fed) 
開發者ID:kmac,項目名稱:mlbv,代碼行數:10,代碼來源:util.py

示例7: get_width

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_width() -> int:
        """
        Get the width of the terminal window
        """
        width, _ = shutil.get_terminal_size(TERMINAL_SIZE_FALLBACK)
        return width 
開發者ID:greenbone,項目名稱:autohooks,代碼行數:8,代碼來源:terminal.py

示例8: __init__

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def __init__(self, prog):
        terminal_width = shutil.get_terminal_size().columns
        os.environ['COLUMNS'] = str(terminal_width)
        max_help_position = min(max(24, terminal_width // 3), 40)
        super().__init__(prog, max_help_position=max_help_position) 
開發者ID:rrwick,項目名稱:Rebaler,代碼行數:7,代碼來源:misc.py

示例9: _getdimensions

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def _getdimensions():
    if py33:
        import shutil
        size = shutil.get_terminal_size()
        return size.lines, size.columns
    else:
        import termios, fcntl, struct
        call = fcntl.ioctl(1, termios.TIOCGWINSZ, "\000" * 8)
        height, width = struct.unpack("hhhh", call)[:2]
        return height, width 
開發者ID:pytest-dev,項目名稱:py,代碼行數:12,代碼來源:terminalwriter.py

示例10: get_terminal_width

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_terminal_width() -> int:
    return shutil.get_terminal_size().columns 
開發者ID:kiwicom,項目名稱:schemathesis,代碼行數:4,代碼來源:default.py

示例11: _format_exc_for_sticky

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def _format_exc_for_sticky(self, exc):
        if len(exc) != 2:
            return "pdbpp: got unexpected __exception__: %r" % (exc,)

        exc_type, exc_value = exc
        s = ''
        try:
            try:
                s = exc_type.__name__
            except AttributeError:
                s = str(exc_type)
            if exc_value is not None:
                s += ': '
                s += str(exc_value)
        except KeyboardInterrupt:
            raise
        except Exception as exc:
            try:
                s += '(unprintable exception: %r)' % (exc,)
            except:
                s += '(unprintable exception)'
        else:
            # Use first line only, limited to terminal width.
            s = s.replace("\r", r"\r").replace("\n", r"\n")
            width, _ = self.get_terminal_size()
            if len(s) > width:
                s = s[:width - 1] + "…"

        if self.config.highlight:
            s = Color.set(self.config.line_number_color, s)

        return s 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:34,代碼來源:pdbpp.py

示例12: handle

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def handle(self, project: Project, options: argparse.Namespace) -> None:
        result = project.get_repository().search(options.query)
        terminal_width = None
        if sys.stdout.isatty():
            terminal_width = get_terminal_size()[0]
        print_results(result, project.environment.get_working_set(), terminal_width) 
開發者ID:frostming,項目名稱:pdm,代碼行數:8,代碼來源:search.py

示例13: get_terminal_size

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_terminal_size():
        """
        Returns a tuple (x, y) representing the width(x) and the height(y)
        in characters of the terminal window.
        """
        return tuple(shutil.get_terminal_size()) 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:8,代碼來源:compat.py

示例14: size

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def size(fallback=(80, 24)) -> tuple:
    """Get the size of the terminal window."""
    return tuple(shutil.get_terminal_size(fallback=fallback)) 
開發者ID:nil0x42,項目名稱:phpsploit,代碼行數:5,代碼來源:__init__.py

示例15: get_terminal_size

# 需要導入模塊: import shutil [as 別名]
# 或者: from shutil import get_terminal_size [as 別名]
def get_terminal_size():
    """
    Detect terminal size and return tuple = (width, height).

    Only to be used when running in a terminal. Note that the IPython notebook,
    IPython zmq frontends, or IDLE do not run in a terminal,
    """
    import platform

    if PY3:
        return shutil.get_terminal_size()

    current_os = platform.system()
    tuple_xy = None
    if current_os == 'Windows':
        tuple_xy = _get_terminal_size_windows()
        if tuple_xy is None:
            tuple_xy = _get_terminal_size_tput()
            # needed for window's python in cygwin's xterm!
    if current_os == 'Linux' or \
        current_os == 'Darwin' or \
            current_os.startswith('CYGWIN'):
        tuple_xy = _get_terminal_size_linux()
    if tuple_xy is None:
        tuple_xy = (80, 25)      # default value
    return tuple_xy 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:28,代碼來源:terminal.py


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