Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor edits on line functionality #285

Merged
merged 8 commits into from
Nov 14, 2024
Merged
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,32 @@ Filename: test.txt
* Note2 : Use `NON_ASCII_FONTS` to access all Non-ASCII fonts name list (new in `Version 4.4`)
* Note3 : Use `ASCII_FONTS` to access all ASCII fonts name list (new in `Version 5.7`)

## Line
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved

### 1. lprint
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved

This function prints a grid (`length` by `height`) of any given character.
```pycon
>>> lprint(length=15, height=2, char="*")
***************
***************
```

* Note1: This feature has been added since `Version 6.4`.
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved
* Note2: The default values are `length=15`, `height=1`, `char='#'`.
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved

### 2. line
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved

This function return a grid (`length` by `height`) of any given character as `str` in and raise `artError` in exception.
```pycon
>>> line(length=15, height=2, char="*")
'***************\n***************'
```

* Note1: This feature has been added since `Version 6.4`.
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved
* Note2: The default values are `length=15`, `height=1`, `char='#'`.
sepandhaghighi marked this conversation as resolved.
Show resolved Hide resolved


### Decoration

⚠️ Some environments don't support all decorations
Expand Down
15 changes: 5 additions & 10 deletions art/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .params import DECORATION_TYPE_ERROR, TEXT_TYPE_ERROR, FONT_TYPE_ERROR, CHR_IGNORE_TYPE_ERROR, FILE_TYPE_ERROR
from .params import PRINT_STATUS_TYPE_ERROR, OVERWRITE_TYPE_ERROR, SEP_TYPE_ERROR, SPACE_TYPE_ERROR
from .params import DETAILED_RETURN_TYPE_ERROR, ART_TYPE_ERROR, NUMBER_TYPE_ERROR, ART_NAME_ERROR
from .params import LENGTH_TYPE_ERROR, LENGTH_RANGE_ERROR, HEIGHT_TYPE_ERROR, HEIGHT_RANGE_ERROR, CHAR_TYPE_ERROR
from .params import LINE_LENGTH_ERROR, LINE_HEIGHT_ERROR, CHAR_TYPE_ERROR
from .errors import artError


Expand Down Expand Up @@ -272,18 +272,13 @@ def line(length=15, height=1, char='#'):
:type char: str
:return: generated grid as str
"""
if not isinstance(length, int):
raise artError(LENGTH_TYPE_ERROR)
if not isinstance(height, int):
raise artError(HEIGHT_TYPE_ERROR)
if not isinstance(length, int) or length < 1:
raise artError(LINE_LENGTH_ERROR)
if not isinstance(height, int) or height < 1:
raise artError(LINE_HEIGHT_ERROR)
if not isinstance(char, str):
raise artError(CHAR_TYPE_ERROR)

if length < 1:
raise artError(LENGTH_RANGE_ERROR)
if height < 1:
raise artError(HEIGHT_RANGE_ERROR)

line_str = char * length
return "\n".join([line_str] * height)

Expand Down
6 changes: 2 additions & 4 deletions art/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
FONT_ENVIRONMENT_WARNING = "[Warning] '{0}' font is not printable in this environment."
FONT_OR_DECOR_ENVIRONMENT_WARNING = "[Warning] '{0}' font or '{1}' decoration is not printable in this environment."
PACKAGE_LOAD_WARNING = "[Warning] There is a problem loading the package 'coverage'."
HEIGHT_TYPE_ERROR = "The 'height' type must be int."
HEIGHT_RANGE_ERROR = "The 'height' parameter should be >= 1."
LENGTH_TYPE_ERROR = "The 'length' type must be int."
LENGTH_RANGE_ERROR = "The 'length' parameter should be >= 1."
LINE_LENGTH_ERROR = "The 'length' must be an int higher than 0."
LINE_HEIGHT_ERROR = "The 'height' must be an int higher than 0."
CHAR_TYPE_ERROR = "The 'char' type must be str."

CLI_HELP = """
Expand Down
14 changes: 14 additions & 0 deletions art/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@
>>> lprint(length=15, height=2, char="*")
***************
***************
>>> lprint(length=0, height=1, char="#")
The 'length' must be an int higher than 0.
>>> line(length=10, height=1, char="#")
'##########'
>>> line(length=15, height=2, char="*")
'***************\n***************'
>>> line(length=0, height=1, char="#")
Traceback (most recent call last):
...
art.art.artError: The 'length' must be an int higher than 0.
>>> line(length=15, height='test', char="#")
Traceback (most recent call last):
...
art.art.artError: The 'height' must be an int higher than 0.
>>> line(length=15, height=2, char=4)
Traceback (most recent call last):
...
art.art.artError: The 'char' type must be str.
>>> tprint("\t\t2","block")
<BLANKLINE>
.----------------.
Expand Down
Loading