diff --git a/README.md b/README.md index 53ed9ad7..9921cd90 100644 --- a/README.md +++ b/README.md @@ -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 + +#### 1. lprint + +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` +* Note2: The default values are `length=15`, `height=1`, `char='#'` + +#### 2. line + +This function returns a grid (`length` by `height`) of any given character as `str` in normal mode and raise `artError` in exception. +```pycon +>>> line(length=15, height=2, char="*") +'***************\n***************' +``` + +* Note1: This feature has been added since `Version 6.4` +* Note2: The default values are `length=15`, `height=1`, `char='#'` + + ### Decoration ⚠️ Some environments don't support all decorations diff --git a/art/functions.py b/art/functions.py index 34ad1713..154072b3 100644 --- a/art/functions.py +++ b/art/functions.py @@ -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 @@ -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) diff --git a/art/params.py b/art/params.py index 9cf02f5b..d4a855f2 100644 --- a/art/params.py +++ b/art/params.py @@ -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 = """ diff --git a/art/tests/test.py b/art/tests/test.py index dc115f59..979e1dab 100644 --- a/art/tests/test.py +++ b/art/tests/test.py @@ -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") .----------------.