-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Log ========== - Deprecate Python 2.7 (This is dead) - Deprecate Python 3.4 (No longer supported by colorama) - Add test support for Python 3.8 - Rework of columnify with tests - Start using [HTML Color Names](https://www.w3schools.com/colors/colors_names.asp) - Add support for hex codes for color definitions - Some refactoring of modules/files - Reduce API footprint (only export a small number of useful functions) - Minor documentation updates
- Loading branch information
Showing
41 changed files
with
733 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ exclude_lines = | |
ignore_errors = True | ||
omit = | ||
test/* | ||
lilies/base.py | ||
lilies/objects/base.py | ||
lilies/__main__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
ignore = E203, E741, W503 | ||
max-line-length = 79 | ||
max-complexity = 18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ lilies.egg-info/* | |
MANIFEST | ||
.python-version | ||
.coverage | ||
dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
sudo: false | ||
language: python | ||
cache: pip | ||
python: | ||
- 3.5 | ||
- 3.6 | ||
- 3.7 | ||
- 3.8 | ||
|
||
matrix: | ||
include: | ||
- python: 2.7 | ||
env: TOXENV=py27 | ||
- python: 3.4 | ||
env: TOXENV=py34 | ||
- python: 3.5 | ||
env: TOXENV=py35 | ||
- python: 3.6 | ||
env: TOXENV=py36 | ||
- python: 3.7 | ||
env: TOXENV=py37,codecov | ||
dist: xenial # required for Python 3.7 (travis-ci/travis-ci#9069) | ||
sudo: required # required for Python 3.7 (travis-ci/travis-ci#9069) | ||
before_install: | ||
- python --version | ||
- pip install -U pip | ||
|
||
install: | ||
- pip install -r requirements-test.txt | ||
|
||
before_script: | ||
# Run flake8 tests only on Python 2.7 and 3.7... | ||
# Run flake8 tests only on Python 3.7... | ||
# 1) stop the build if there are Python syntax errors or undefined names | ||
# 2) exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
- if [[ $TRAVIS_PYTHON_VERSION == *.7 ]]; then | ||
flake8 --config tox.ini lilies; | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then | ||
flake8 ./lilies; | ||
fi | ||
|
||
script: | ||
- tox | ||
- pytest -v --cov=lilies | ||
|
||
after_success: | ||
- codecov # submit coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
# Lilies | ||
|
||
[![Build Status](https://travis-ci.org/mrz1988/lilies.svg?branch=master)](https://travis-ci.org/mrz1988/lilies) | ||
[![Code Coverage](https://codecov.io/gh/mrz1988/lilies/branch/master/graphs/badge.svg)](https://codecov.io/gh/mrz1988/lilies/branch/master) | ||
|
||
Lilies is currently in alpha. Parts of the API are highly subject to change. A fresh README is in the works. | ||
|
||
Lilies is a cross-platform, colored CLI text-formatting tool for python. It provides lots of text coloring and formatting tools, bridged across almost any console. This includes older Windows support powered by popular coloring library [colorama](https://pypi.org/project/colorama/). Lilies will attempt to reproduce the original colors as close as possible, regardless of the current terminal's capabilities. | ||
|
||
Lilies is supported on python 2.7, 3.4, 3.5, 3.6, and 3.7. It probably works in some other releases, too. No promises. | ||
|
||
![Sup, world?](https://raw.githubusercontent.com/mrz1988/lilies/master/screenshots/screenshot01.png) | ||
|
||
## Why not use alternatives? | ||
There are [many options](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python) to help you build colored text in terminal output. Many developers prefer to directly add their own ANSI sequences. Since this isn't great for complex things, [termcolor](https://pypi.org/project/termcolor/) provides a convenient abstraction. However, termcolor does not work on windows, and doesn't respect compatibility of other terminals. Formatting text once it has already been colored is also hard, since the `len()` function will include ANSI characters. | ||
|
||
Lilies provides more powerful string tools, 2D text manipulation, and comfort that your coloring will respect the wishes of others' terminals. | ||
|
||
## Getting started | ||
Install us via [pip](https://pypi.org/project/lilies/)! | ||
``` | ||
pip install lilies | ||
``` | ||
|
||
## Contributing | ||
You can find information about contributing [here](https://github.com/mrz1988/lilies/blob/master/docs/contributing.rst) | ||
|
||
## License | ||
[MIT](https://github.com/mrz1988/lilies/blob/master/LICENSE) | ||
# Lilies | ||
|
||
[![Build Status](https://travis-ci.org/mrz1988/lilies.svg?branch=master)](https://travis-ci.org/mrz1988/lilies) | ||
[![Code Coverage](https://codecov.io/gh/mrz1988/lilies/branch/master/graphs/badge.svg)](https://codecov.io/gh/mrz1988/lilies/branch/master) | ||
|
||
Lilies is currently in alpha. Parts of the API are highly subject to change. A fresh README is in the works. | ||
|
||
Lilies is a cross-platform, colored CLI text-formatting tool for python. It provides lots of text coloring and formatting tools, bridged across almost any console. This includes older Windows support powered by popular coloring library [colorama](https://pypi.org/project/colorama/). Lilies will attempt to reproduce the original colors as close as possible, regardless of the current terminal's capabilities. | ||
|
||
Lilies is supported on python 3.5, 3.6, 3.7, and 3.8. | ||
|
||
![Sup, world?](https://raw.githubusercontent.com/mrz1988/lilies/master/screenshots/screenshot01.png) | ||
|
||
## Why not use alternatives? | ||
There are [many options](https://stackoverflow.com/questions/287871/how-to-print-colored-text-in-terminal-in-python) to help you build colored text in terminal output. Many developers prefer to directly add their own ANSI sequences. Since this isn't great for complex things, [termcolor](https://pypi.org/project/termcolor/) provides a convenient abstraction. However, termcolor does not work on windows, and doesn't respect compatibility of other terminals. Formatting text once it has already been colored is also hard, since the `len()` function will include ANSI characters. | ||
|
||
Lilies provides more powerful string tools, 2D text manipulation, and comfort that your coloring will respect the wishes of others' terminals. | ||
|
||
## Getting started | ||
Install us via [pip](https://pypi.org/project/lilies/)! | ||
``` | ||
pip install lilies | ||
``` | ||
|
||
## Contributing | ||
You can find information about contributing [here](https://github.com/mrz1988/lilies/blob/master/docs/contributing.rst) | ||
|
||
## License | ||
[MIT](https://github.com/mrz1988/lilies/blob/master/LICENSE) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from .borders import bordered | ||
from .columnify import columnify | ||
from .grow import grow | ||
from .sortify import sortify | ||
|
||
__all__ = ["bordered", "columnify", "grow", "sortify"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from .grow import grow | ||
from .sortify import sortify | ||
from ..objects.lilyblock import block | ||
|
||
|
||
class ColumnBuilder: | ||
def __init__( | ||
self, column_count=0, total_width=80, justify="left", min_spacing=3 | ||
): | ||
self.column_count = column_count | ||
self.total_width = total_width | ||
self.justify = justify | ||
self.min_spacing = min_spacing | ||
|
||
def make_columns(self, iterable, sort=True, horizontal=False): | ||
if not iterable: | ||
return block("") | ||
|
||
iterable = [grow(item) for item in iterable] | ||
column_count = self._get_column_count(iterable) | ||
entries_per_column, remainder = divmod(len(iterable), column_count) | ||
if remainder > 0: | ||
entries_per_column += 1 | ||
|
||
if sort: | ||
iterable = sortify(iterable) | ||
iterable = self._resize_all(iterable, column_count) | ||
|
||
if horizontal: | ||
rows = self._make_rows_horizontally( | ||
iterable, column_count, entries_per_column | ||
) | ||
else: | ||
rows = self._make_rows_vertically( | ||
iterable, column_count, entries_per_column | ||
) | ||
|
||
return self._merge_rows_to_lilyblock(rows) | ||
|
||
def _make_rows_horizontally( | ||
self, iterable, column_count, entries_per_column | ||
): | ||
rows = [] | ||
for i in range(entries_per_column): | ||
start = column_count * i | ||
stop = start + column_count | ||
rows.append(iterable[start:stop]) | ||
return rows | ||
|
||
def _make_rows_vertically( | ||
self, iterable, column_count, entries_per_column | ||
): | ||
rows = [] | ||
for i in range(entries_per_column): | ||
rows.append(iterable[i::entries_per_column]) | ||
return rows | ||
|
||
def _get_column_count(self, iterable): | ||
if self.column_count != 0: | ||
return self.column_count | ||
|
||
longest_item_size = max([len(item) for item in iterable]) | ||
columns = self.total_width // (longest_item_size + self.min_spacing) | ||
|
||
# If we have fewer items than columns, we aren't going to | ||
# fill all of the columns. | ||
if len(iterable) < columns: | ||
columns = len(iterable) | ||
if columns == 0: | ||
return 1 | ||
return columns | ||
|
||
def _resize_all(self, iterable, column_count): | ||
total_spacing = self.min_spacing * (column_count - 1) | ||
usable_width = self.total_width - total_spacing | ||
max_cell_size = usable_width // column_count | ||
max_item_size = max([len(item) for item in iterable]) | ||
item_size = min([max_cell_size, max_item_size]) | ||
return [ | ||
s.resize(item_size, self.justify, add_elipsis=True, fillchar=" ") | ||
for s in iterable | ||
] | ||
|
||
def _merge_rows_to_lilyblock(self, rows): | ||
space = grow(" " * self.min_spacing) | ||
rows = [space.join(row) for row in rows] | ||
return block(rows) | ||
|
||
|
||
def columnify( | ||
iterable, | ||
columns=0, | ||
width=80, | ||
justify="left", | ||
sort=True, | ||
min_spacing=3, | ||
horizontal=False, | ||
): | ||
builder = ColumnBuilder( | ||
column_count=columns, | ||
total_width=width, | ||
justify=justify, | ||
min_spacing=min_spacing, | ||
) | ||
return builder.make_columns(iterable, sort=sort, horizontal=horizontal) |
Oops, something went wrong.