diff options
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/progress/helpers.py')
-rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/progress/helpers.py | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/progress/helpers.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/progress/helpers.py new file mode 100644 index 0000000..96c8800 --- /dev/null +++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/progress/helpers.py | |||
@@ -0,0 +1,91 @@ | |||
1 | # Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com> | ||
2 | # | ||
3 | # Permission to use, copy, modify, and distribute this software for any | ||
4 | # purpose with or without fee is hereby granted, provided that the above | ||
5 | # copyright notice and this permission notice appear in all copies. | ||
6 | # | ||
7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
14 | |||
15 | from __future__ import print_function | ||
16 | |||
17 | |||
18 | HIDE_CURSOR = '\x1b[?25l' | ||
19 | SHOW_CURSOR = '\x1b[?25h' | ||
20 | |||
21 | |||
22 | class WriteMixin(object): | ||
23 | hide_cursor = False | ||
24 | |||
25 | def __init__(self, message=None, **kwargs): | ||
26 | super(WriteMixin, self).__init__(**kwargs) | ||
27 | self._width = 0 | ||
28 | if message: | ||
29 | self.message = message | ||
30 | |||
31 | if self.file.isatty(): | ||
32 | if self.hide_cursor: | ||
33 | print(HIDE_CURSOR, end='', file=self.file) | ||
34 | print(self.message, end='', file=self.file) | ||
35 | self.file.flush() | ||
36 | |||
37 | def write(self, s): | ||
38 | if self.file.isatty(): | ||
39 | b = '\b' * self._width | ||
40 | c = s.ljust(self._width) | ||
41 | print(b + c, end='', file=self.file) | ||
42 | self._width = max(self._width, len(s)) | ||
43 | self.file.flush() | ||
44 | |||
45 | def finish(self): | ||
46 | if self.file.isatty() and self.hide_cursor: | ||
47 | print(SHOW_CURSOR, end='', file=self.file) | ||
48 | |||
49 | |||
50 | class WritelnMixin(object): | ||
51 | hide_cursor = False | ||
52 | |||
53 | def __init__(self, message=None, **kwargs): | ||
54 | super(WritelnMixin, self).__init__(**kwargs) | ||
55 | if message: | ||
56 | self.message = message | ||
57 | |||
58 | if self.file.isatty() and self.hide_cursor: | ||
59 | print(HIDE_CURSOR, end='', file=self.file) | ||
60 | |||
61 | def clearln(self): | ||
62 | if self.file.isatty(): | ||
63 | print('\r\x1b[K', end='', file=self.file) | ||
64 | |||
65 | def writeln(self, line): | ||
66 | if self.file.isatty(): | ||
67 | self.clearln() | ||
68 | print(line, end='', file=self.file) | ||
69 | self.file.flush() | ||
70 | |||
71 | def finish(self): | ||
72 | if self.file.isatty(): | ||
73 | print(file=self.file) | ||
74 | if self.hide_cursor: | ||
75 | print(SHOW_CURSOR, end='', file=self.file) | ||
76 | |||
77 | |||
78 | from signal import signal, SIGINT | ||
79 | from sys import exit | ||
80 | |||
81 | |||
82 | class SigIntMixin(object): | ||
83 | """Registers a signal handler that calls finish on SIGINT""" | ||
84 | |||
85 | def __init__(self, *args, **kwargs): | ||
86 | super(SigIntMixin, self).__init__(*args, **kwargs) | ||
87 | signal(SIGINT, self._sigint_handler) | ||
88 | |||
89 | def _sigint_handler(self, signum, frame): | ||
90 | self.finish() | ||
91 | exit(0) | ||