Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit db406ea

Browse files
committed
simplified and add some deleter
1 parent 89c7934 commit db406ea

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

halo/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
__author__ = 'Manraj Singh'
33
__email__ = '[email protected]'
44

5+
all = ["cursor.py", "halo_notebook.py", "halo.py"]
6+
57
import logging
68

79
from .halo import Halo

halo/_utils.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ def is_supported():
2626

2727
os_arch = platform.system()
2828

29-
if os_arch != 'Windows':
30-
return True
29+
return True if os_arch != 'Windows' else False
3130

32-
return False
3331

3432

3533
def get_environment():
@@ -42,10 +40,7 @@ def get_environment():
4240
"""
4341
try:
4442
from IPython import get_ipython
45-
except ImportError:
46-
return 'terminal'
47-
48-
try:
43+
4944
shell = get_ipython().__class__.__name__
5045

5146
if shell == 'ZMQInteractiveShell': # Jupyter notebook or qtconsole
@@ -55,7 +50,7 @@ def get_environment():
5550
else:
5651
return 'terminal' # Other type (?)
5752

58-
except NameError:
53+
except (ImportError, NameError):
5954
return 'terminal'
6055

6156

@@ -90,10 +85,7 @@ def is_text_type(text):
9085
bool
9186
Whether parameter is a string or not
9287
"""
93-
if isinstance(text, six.text_type) or isinstance(text, six.string_types):
94-
return True
95-
96-
return False
88+
return True if isinstance(text, (six.text_type, six.string_types)) else False
9789

9890

9991
def decode_utf_8_text(text):
@@ -146,7 +138,4 @@ def get_terminal_columns():
146138

147139
# If column size is 0 either we are not connected
148140
# to a terminal or something else went wrong. Fallback to 80.
149-
if terminal_size.columns == 0:
150-
return 80
151-
else:
152-
return terminal_size.columns
141+
return 80 if terminal_size.columns == 0 else terminal_size.columns

halo/cursor.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import ctypes
1010

1111
class _CursorInfo(ctypes.Structure):
12-
_fields_ = [("size", ctypes.c_int), ("visible", ctypes.c_byte)]
12+
_fields_ = [("size", ctypes.c_int),
13+
("visible", ctypes.c_byte)]
1314

1415

1516
def hide(stream=sys.stdout):

halo/halo.py

+38-6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def __init__(
7777
stream : io, optional
7878
Output.
7979
"""
80+
81+
# To reset Values in deleter
82+
self.reset_values = {"text": text,
83+
"color": color,
84+
"text_color": text_color,
85+
"spinner": spinner,
86+
"animation": animation,
87+
"placement": placement,}
88+
8089
self._color = color
8190
self._animation = animation
8291

@@ -156,6 +165,12 @@ def spinner(self, spinner=None):
156165
self._frame_index = 0
157166
self._text_index = 0
158167

168+
@spinner.deleter
169+
def spinner(self):
170+
"""set spinner to None when delete spinner is
171+
"""
172+
self._spinner = self.reset_values["spinner"]
173+
159174
@property
160175
def text(self):
161176
"""Getter for text property.
@@ -176,6 +191,10 @@ def text(self, text):
176191
"""
177192
self._text = self._get_text(text)
178193

194+
@text.deleter
195+
def text(self):
196+
self.text = self.reset_values["text"]
197+
179198
@property
180199
def text_color(self):
181200
"""Getter for text color property.
@@ -196,6 +215,10 @@ def text_color(self, text_color):
196215
"""
197216
self._text_color = text_color
198217

218+
@text_color.deleter
219+
def text_color(self):
220+
self._text_color = self.reset_values["text_color"]
221+
199222
@property
200223
def color(self):
201224
"""Getter for color property.
@@ -216,6 +239,10 @@ def color(self, color):
216239
"""
217240
self._color = color
218241

242+
@color.deleter
243+
def color(self):
244+
self._color = self.reset_values["color"]
245+
219246
@property
220247
def placement(self):
221248
"""Getter for placement property.
@@ -242,6 +269,10 @@ def placement(self, placement):
242269
)
243270
self._placement = placement
244271

272+
@placement.deleter
273+
def placement(self):
274+
self.placement = self.reset_values["placement"]
275+
245276
@property
246277
def spinner_id(self):
247278
"""Getter for spinner id
@@ -273,6 +304,10 @@ def animation(self, animation):
273304
self._animation = animation
274305
self._text = self._get_text(self._text["original"])
275306

307+
@animation.deleter
308+
def animation(self):
309+
self._animation = self.reset_values["animation"]
310+
276311
def _check_stream(self):
277312
"""Returns whether the stream is open, and if applicable, writable
278313
Returns
@@ -334,10 +369,7 @@ def _get_spinner(self, spinner):
334369
return spinner
335370

336371
if is_supported():
337-
if all([is_text_type(spinner), spinner in Spinners.__members__]):
338-
return Spinners[spinner].value
339-
else:
340-
return default_spinner
372+
return Spinners[spinner].valueif if all([is_text_type(spinner), spinner in Spinners.__members__]) else default_spinner
341373
else:
342374
return Spinners["line"].value
343375

@@ -354,8 +386,8 @@ def _get_text(self, text):
354386
max_spinner_length = max([len(i) for i in self._spinner["frames"]])
355387

356388
# Subtract to the current terminal size the max spinner length
357-
# (-1 to leave room for the extra space between spinner and text)
358-
terminal_width = get_terminal_columns() - max_spinner_length - 1
389+
# (+1 to leave room for the extra space between spinner and text)
390+
terminal_width = get_terminal_columns() - (max_spinner_length + 1)
359391
text_length = len(stripped_text)
360392

361393
frames = []

tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
all = ["test_halo_notebook.py", "test_halo.py"]

0 commit comments

Comments
 (0)