Skip to content

Commit

Permalink
Merge pull request #114 from sepandhaghighi/nextline-bug
Browse files Browse the repository at this point in the history
Nextline bug
  • Loading branch information
sadrasabouri authored Mar 7, 2020
2 parents 17cf0d4 + 40017c3 commit 2a0f13e
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- `NON_ASCII_ARTS` list
- `decor_dic.py` file
- `codecov.yml` file
- `decor` function
- `decor_list` function
- `DecorList.ipynb` notebook
Expand Down Expand Up @@ -54,6 +55,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `test` parameter removed from `font_list` function
- `mode` parameter added to `font_list` and `art_list` functions
- `decoration` parameter added to `text2art`, `tprint` and `tsave` functions
- `\n` support bug fixed
### Removed
- `requirements.txt`
## [4.5] - 2020-01-29
Expand Down
23 changes: 14 additions & 9 deletions art/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def mix_letters():
return letters


def __word2art(word, font, chr_ignore, letters):
def __word2art(word, font, chr_ignore, letters, next_word):
"""
Return art word.
Expand All @@ -428,11 +428,17 @@ def __word2art(word, font, chr_ignore, letters):
:type chr_ignore: bool
:param letters: font letters table
:type letters: dict
:param next_word: next word flag
:type next_word: bool
:return: ascii art as str
"""
split_list = []
result_list = []
splitter = "\n"
if "win32" != sys.platform:
splitter = "\r\n"
if len(word) == 0 and next_word:
return splitter
for i in word:
if (ord(i) == 9) or (ord(i) == 32 and font == "block"):
continue
Expand All @@ -458,9 +464,9 @@ def __word2art(word, font, chr_ignore, letters):
temp = temp + " "
temp = temp + split_list[j][i]
result_list.append(temp)
if "win32" != sys.platform:
splitter = "\r\n"
result = (splitter).join(result_list)
if result[-1] != "\n" and next_word:
result += splitter
return result


Expand Down Expand Up @@ -498,12 +504,11 @@ def text2art(text, font=DEFAULT_FONT, chr_ignore=True, decoration=None):
result = ""
if decoration is not None:
result += decor(decoration)
for word in word_list:
if len(word) != 0:
result = result + __word2art(word=word,
font=font,
chr_ignore=chr_ignore,
letters=letters)
next_word_flag = True
for index,word in enumerate(word_list):
if index == len(word_list)-1:
next_word_flag = False
result = result + __word2art(word=word,font=font,chr_ignore=chr_ignore,letters=letters,next_word=next_word_flag)
if decoration is not None:
result = result + decor(decoration, reverse=True)
return result
Expand Down
80 changes: 80 additions & 0 deletions art/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3591,6 +3591,86 @@
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
>>> tprint("test1\ntest2\ntest3")
_ _ _
| |_ ___ ___ | |_ / |
| __| / _ \/ __|| __|| |
| |_ | __/\__ \| |_ | |
\__| \___||___/ \__||_|
<BLANKLINE>
_ _ ____
| |_ ___ ___ | |_ |___ \
| __| / _ \/ __|| __| __) |
| |_ | __/\__ \| |_ / __/
\__| \___||___/ \__||_____|
<BLANKLINE>
_ _ _____
| |_ ___ ___ | |_ |___ /
| __| / _ \/ __|| __| |_ \
| |_ | __/\__ \| |_ ___) |
\__| \___||___/ \__||____/
<BLANKLINE>
<BLANKLINE>
>>> tprint("\n\ntest1\ntest2\ntest3")
<BLANKLINE>
<BLANKLINE>
_ _ _
| |_ ___ ___ | |_ / |
| __| / _ \/ __|| __|| |
| |_ | __/\__ \| |_ | |
\__| \___||___/ \__||_|
<BLANKLINE>
_ _ ____
| |_ ___ ___ | |_ |___ \
| __| / _ \/ __|| __| __) |
| |_ | __/\__ \| |_ / __/
\__| \___||___/ \__||_____|
<BLANKLINE>
_ _ _____
| |_ ___ ___ | |_ |___ /
| __| / _ \/ __|| __| |_ \
| |_ | __/\__ \| |_ ___) |
\__| \___||___/ \__||____/
<BLANKLINE>
<BLANKLINE>
>>> tprint("\n\ntest1\ntest2\ntest3\n\n\n",font="lcd")
<BLANKLINE>
<BLANKLINE>
_
| | |
-+- - - -+- +
| |/ \ | |
- -- - - ---
<BLANKLINE>
___
| | |
-+- - - -+- -+-
| |/ \ | |
- -- - - ---
<BLANKLINE>
___
| | |
-+- - - -+- -+-
| |/ \ | |
- -- - - ---
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
>>> tprint("",font="lcd")
<BLANKLINE>
>>> tprint("\n",font="lcd")
<BLANKLINE>
<BLANKLINE>
>>> tprint("\n\n",font="lcd")
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
>>> text2art("")
''
>>> text2art("",font="lcd")
''
>>> art_list(mode="ascii")
alien
::)
Expand Down
20 changes: 20 additions & 0 deletions art/test2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,26 @@
zombie
'º_º'
******************************
>>> tprint("test1\ntest2\ntest3","fancy42")
ţ€$ţ1
ţ€$ţ2
ţ€$ţ3
>>> tprint("test1\ntest2\ntest3\n","fancy44")
тεƨт1
тεƨт2
тεƨт3
<BLANKLINE>
>>> tprint("","fancy44")
<BLANKLINE>
>>> tprint("\n","fancy44")
<BLANKLINE>
<BLANKLINE>
>>> tprint("\n\n","fancy44")
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
>>> text2art("",font="fancy44")
''
>>> decor_list()
barcode1
▌│█║▌║▌║ ƭεรƭ ║▌║▌║█│▌
Expand Down
11 changes: 11 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
codecov:
require_ci_to_pass: yes

coverage:
precision: 2
round: up
range: "70...100"
status:
patch:
default:
enabled: no

0 comments on commit 2a0f13e

Please sign in to comment.