当前位置: 首页>>代码示例>>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;未经允许,请勿转载。