Skip to content

Commit

Permalink
Merge branch 'master' into colored-text-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vito Šemrov authored Nov 5, 2018
2 parents bc5e751 + ef0a6db commit e014082
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 73 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,11 @@ cover/
# tests
tests/*.txt

# OS-specific files
.DS_Store

# IDE settings
.vscode/

# Idea
.idea
.idea
24 changes: 16 additions & 8 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ ignore-patterns=

# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
init-hook="exec 'aW1wb3J0IHN5cywgb3MKCmlmICdWSVJUVUFMX0VOVicgbm90IGluIG9zLmVudmlyb246CiAgICBz \
eXMuZXhpdCgwKQoKdmVfZGlyID0gb3MuZW52aXJvblsnVklSVFVBTF9FTlYnXQp2ZV9kaXIgaW4g \
c3lzLnBhdGggb3Igc3lzLnBhdGguaW5zZXJ0KDAsIHZlX2RpcikKYWN0aXZhdGVfdGhpcyA9IG9z \
LnBhdGguam9pbihvcy5wYXRoLmpvaW4odmVfZGlyLCAnYmluJyksICdhY3RpdmF0ZV90aGlzLnB5 \
JykKCiMgRml4IGZvciB3aW5kb3dzCmlmIG5vdCBvcy5wYXRoLmV4aXN0cyhhY3RpdmF0ZV90aGlz \
KToKICAgIGFjdGl2YXRlX3RoaXMgPSBvcy5wYXRoLmpvaW4ob3MucGF0aC5qb2luKHZlX2Rpciwg \
J1NjcmlwdHMnKSwgJ2FjdGl2YXRlX3RoaXMucHknKQoKZXhlY2ZpbGUoYWN0aXZhdGVfdGhpcywg \
ZGljdChfX2ZpbGVfXz1hY3RpdmF0ZV90aGlzKSkK'.decode('base64')"
init-hook=
import sys, os

if 'VIRTUAL_ENV' not in os.environ: \
sys.exit(0)

ve_dir = os.environ['VIRTUAL_ENV']
ve_dir in sys.path or sys.path.insert(0, ve_dir)
activate_this = os.path.join(os.path.join(ve_dir, 'bin'), 'activate_this.py')

# Fix for windows
if not os.path.exists(activate_this): \
activate_this = os.path.join(os.path.join(ve_dir, 'Scripts'), 'activate_this.py')

with open(activate_this) as fp: \
exec(fp.read(), dict(__file__=activate_this))

# Use multiple processes to speed up Pylint.
jobs=1
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
halo
</h1>

[![Build Status](https://travis-ci.org/manrajgrover/halo.svg?branch=master)](https://travis-ci.org/manrajgrover/halo) [![Build status](https://ci.appveyor.com/api/projects/status/wa6t414gltr403ff?svg=true)](https://ci.appveyor.com/project/manrajgrover/halo)
[![Build Status](https://travis-ci.org/manrajgrover/halo.svg?branch=master)](https://travis-ci.org/manrajgrover/halo) [![Build status](https://ci.appveyor.com/api/projects/status/wa6t414gltr403ff?svg=true)](https://ci.appveyor.com/project/manrajgrover/halo) [![Coverage Status](https://coveralls.io/repos/github/manrajgrover/halo/badge.svg?branch=master)](https://coveralls.io/github/manrajgrover/halo?branch=master)
[![PyPI](https://img.shields.io/pypi/v/halo.svg)](https://github.com/manrajgrover/halo) ![awesome](https://img.shields.io/badge/awesome-yes-green.svg)
> Beautiful spinners for terminal, IPython and Jupyter
![halo](art/doge_spin.svg)
![halo](https://raw.github.com/manrajgrover/halo/master/art/doge_spin.svg?sanitize=true)

## Install

Expand Down Expand Up @@ -171,7 +171,7 @@ Symbol to replace the spinner with. Defaults to `' '`.

Text to be persisted. Defaults to instance text.

![Persist spin](art/persist_spin.svg)
![Persist spin](https://raw.github.com/manrajgrover/halo/master/art/persist_spin.svg?sanitize=true)

#### `spinner.text`
Change the text of spinner.
Expand All @@ -188,7 +188,7 @@ Please see [Contributing guidelines](https://github.com/manrajgrover/halo/blob/m

## Like it?

:star2: this repo to show support. Let me know you liked it on [Twitter](https://twitter.com/manrajsgrover).
🌟 this repo to show support. Let me know you liked it on [Twitter](https://twitter.com/manrajsgrover).
Also, share the [project](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fmanrajgrover%2Fhalo&via=manrajsgrover&text=Checkout%20%23halo%20-%20a%20beautiful%20%23terminal%20%23spinners%20library%20for%20%23python&hashtags=github%2C%20pypi).

## Related
Expand Down
27 changes: 14 additions & 13 deletions halo/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import six
try:
from shutil import get_terminal_size
except:
except ImportError:
from backports.shutil_get_terminal_size import get_terminal_size

from colorama import init
Expand All @@ -17,7 +17,7 @@

def is_supported():
"""Check whether operating system supports main symbols or not.
Returns
-------
boolean
Expand All @@ -31,6 +31,7 @@ def is_supported():

return False


def get_environment():
"""Get the environment in which halo is running
Expand All @@ -43,31 +44,31 @@ def get_environment():
from IPython import get_ipython
except ImportError:
return 'terminal'

try:
shell = get_ipython().__class__.__name__

if shell == 'ZMQInteractiveShell': # Jupyter notebook or qtconsole
if shell == 'ZMQInteractiveShell': # Jupyter notebook or qtconsole
return 'jupyter'
elif shell == 'TerminalInteractiveShell': # Terminal running IPython
elif shell == 'TerminalInteractiveShell': # Terminal running IPython
return 'ipython'
else:
return 'terminal' # Other type (?)
return 'terminal' # Other type (?)

except NameError:
return 'terminal'


def colored_frame(frame, color):
"""Color the frame with given color and returns.
Parameters
----------
frame : str
Frame to be colored
color : str
Color to be applied
Returns
-------
str
Expand All @@ -78,12 +79,12 @@ def colored_frame(frame, color):

def is_text_type(text):
"""Check if given parameter is a string or not
Parameters
----------
text : *
Parameter to be checked for text type
Returns
-------
bool
Expand All @@ -97,20 +98,20 @@ def is_text_type(text):

def decode_utf_8_text(text):
"""Decode the text from utf-8 format
Parameters
----------
text : str
String to be decoded
Returns
-------
str
Decoded string
"""
try:
return codecs.decode(text, 'utf-8')
except:
except (TypeError, ValueError):
return text


Expand Down
20 changes: 8 additions & 12 deletions halo/halo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# pylint: disable=unsubscriptable-object
"""Beautiful terminal spinners in Python.
"""
from __future__ import unicode_literals, absolute_import
from __future__ import absolute_import, unicode_literals

import atexit
import functools
import sys
import threading
import time
import functools
import atexit

import cursor
from spinners.spinners import Spinners
from log_symbols.symbols import LogSymbols
from spinners.spinners import Spinners

from halo._utils import colored_frame, is_text_type, decode_utf_8_text, get_terminal_columns, \
get_environment, is_supported
from halo._utils import (colored_frame, decode_utf_8_text, get_environment,
get_terminal_columns, is_supported, is_text_type)


class Halo(object):
Expand Down Expand Up @@ -97,12 +97,8 @@ def __enter__(self):
return self.start()

def __exit__(self, type, value, traceback):
"""Stops the spinner. For use in context managers.
Returns
-------
None
"""
return self.stop()
"""Stops the spinner. For use in context managers."""
self.stop()

def __call__(self, f):
"""Allow the Halo object to be used as a regular function decorator."""
Expand Down
2 changes: 1 addition & 1 deletion halo/halo_notebook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import unicode_literals, absolute_import, print_function
from __future__ import absolute_import, print_function, unicode_literals

import sys
import threading
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage==4.4.1
nose==1.3.7
pylint==1.7.2
tox==2.8.2
twine==1.12.1
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ def dependencies(file):
return f.read().splitlines()


with open("README.md") as infile:
long_description = infile.read()

setup(
name='halo',
packages=find_packages(exclude=('tests', 'examples')),
version='0.0.18',
version='0.0.21',
license='MIT',
description='Beautiful terminal spinners in Python',
long_description='Beautiful terminal spinners in Python. Find the documentation here: https://github.com/ManrajGrover/halo',
long_description=long_description,
long_description_content_type="text/markdown",
author='Manraj Singh',
author_email='[email protected]',
url='https://github.com/manrajgrover/halo',
Expand Down
18 changes: 8 additions & 10 deletions tests/_utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
"""Utilities for tests.
"""
import errno
import codecs
import os
import re


def strip_ansi(string):
"""Strip ANSI encoding from given string.
Parameters
----------
string : str
String from which encoding needs to be removed
Returns
-------
str
Expand Down Expand Up @@ -41,37 +39,37 @@ def find_colors(string):

def decode_utf_8_text(text):
"""Decodes the text from utf-8 format.
Parameters
----------
text : str
Text to be decoded
Returns
-------
str
Decoded text
"""
try:
return codecs.decode(text, 'utf-8')
except:
except (TypeError, ValueError):
return text


def encode_utf_8_text(text):
"""Encodes the text to utf-8 format
Parameters
----------
text : str
Text to be encoded
Returns
-------
str
Encoded text
"""
try:
return codecs.encode(text, 'utf-8')
except:
except (TypeError, ValueError):
return text
Loading

0 comments on commit e014082

Please sign in to comment.