Update vendored vistir

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2019-02-26 12:03:26 -05:00
parent 05d3b5af26
commit bc3d50b8be
3 changed files with 84 additions and 6 deletions
+5 -2
View File
@@ -17,6 +17,7 @@ from .contextmanagers import (
spinner,
replaced_stream
)
from .cursor import show_cursor, hide_cursor
from .misc import (
load_path,
partialclass,
@@ -35,7 +36,7 @@ from .path import mkdir_p, rmtree, create_tracked_tempdir, create_tracked_tempfi
from .spin import create_spinner
__version__ = '0.3.0'
__version__ = '0.3.1'
__all__ = [
@@ -67,5 +68,7 @@ __all__ = [
"StringIO",
"get_wrapped_stream",
"StreamWrapper",
"replaced_stream"
"replaced_stream",
"show_cursor",
"hide_cursor"
]
+76
View File
@@ -0,0 +1,76 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function
import ctypes
import os
import sys
__all__ = ["hide_cursor", "show_cursor"]
class CONSOLE_CURSOR_INFO(ctypes.Structure):
_fields_ = [('dwSize', ctypes.c_int),
('bVisible', ctypes.c_int)]
WIN_STDERR_HANDLE_ID = ctypes.c_ulong(-12)
WIN_STDOUT_HANDLE_ID = ctypes.c_ulong(-11)
def get_stream_handle(stream=sys.stdout):
"""
Get the OS appropriate handle for the corresponding output stream.
:param str stream: The the stream to get the handle for
:return: A handle to the appropriate stream, either a ctypes buffer
or **sys.stdout** or **sys.stderr**.
"""
handle = stream
if os.name == "nt":
from ctypes import windll
handle_id = WIN_STDOUT_HANDLE_ID
handle = windll.kernel32.GetStdHandle(handle_id)
return handle
def hide_cursor(stream=sys.stdout):
"""
Hide the console cursor on the given stream
:param stream: The name of the stream to get the handle for
:return: None
:rtype: None
"""
handle = get_stream_handle(stream=stream)
if os.name == "nt":
from ctypes import windll
cursor_info = CONSOLE_CURSOR_INFO()
windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(cursor_info))
cursor_info.visible = False
windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(cursor_info))
else:
handle.write("\033[?25l")
handle.flush()
def show_cursor(stream=sys.stdout):
"""
Show the console cursor on the given stream
:param stream: The name of the stream to get the handle for
:return: None
:rtype: None
"""
handle = get_stream_handle(stream=stream)
if os.name == "nt":
from ctypes import windll
cursor_info = CONSOLE_CURSOR_INFO()
windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(cursor_info))
cursor_info.visible = True
windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(cursor_info))
else:
handle.write("\033[?25h")
handle.flush()
+3 -4
View File
@@ -12,18 +12,17 @@ import colorama
import six
from .compat import to_native_string
from .cursor import hide_cursor, show_cursor
from .termcolors import COLOR_MAP, COLORS, colored, DISABLE_COLORS
from .misc import decode_for_output
from io import StringIO
try:
import yaspin
import cursor
except ImportError:
yaspin = None
Spinners = None
SpinBase = None
cursor = None
else:
import yaspin.spinners
import yaspin.core
@@ -421,13 +420,13 @@ class VistirSpinner(SpinBase):
def _hide_cursor(target=None):
if not target:
target = sys.stdout
cursor.hide(stream=target)
hide_cursor(stream=target)
@staticmethod
def _show_cursor(target=None):
if not target:
target = sys.stdout
cursor.show(stream=target)
show_cursor(stream=target)
@staticmethod
def _clear_err():