General Module

This model includes frequently employed functionalities. There are 14 functions and one class in it.

The General Module’s img_to_ascii() function

This module, which converts images into ASCII code and returns a string, is really intriguing.

Function’s structure: img_to_ascii(Path: str) -> str

Example

To convert an image into ASCII art.

Python3




from Designer.General import *
 
a = img_to_ascii(".../.../.../.../path")
 
with open("sample.txt",'w') as f:
    f.writelines(a)
f.close()


Output:

 

The General Module’s image_art() function

The program, which converts images into colorful text code, is also extremely intriguing. The colored text in the terminal replicates the image. The string is the return data type.

Function’s structure: image_art(Character: str, Path: str, Type: str = “fg”) -> str

  • Character = it accepts a string (or) character, and using this output is used to replicate the provided image.
  • path = Its necessity is the path. File’s location
  • Type = inputs like Foreground[“fg”] or Background[“bg”] are required. Consequently, the outcome replicated that. to illustrate, use image art(“*”, /../../)

Example: 

Image to colorful text art conversion.

Python3




from Designer.General import *
 
image_art = image_art("*",".../.../.../file","fg")
#                      |   |                  |
#                      |   |                  |======= > You can alter the
                                # Pixel's foreground or background behaviour.
#                      |   |=====> File Path
#                      |
#                      |======= > Any charter is acceptable here.
                        # replicated into the output. It behaves like a Pixel.
print(image_art)


Output:

 

Original image:

original image

The General Module’s start() and stop() function

start(): The specified colors are applied in the terminal after calling this start function. Applying the specified color to text will continue until the stop function is called.

  • Function’s structure:  start( String : str ,Type_ : str =”fg”, style : int = 0) -> str :

stop(): It halts the coloring process, which is initiated by the start function.

  • Function’s structure: def stop() -> str :

Example: 

Printing text using the start and stop function.

Python3




from Designer.General import start,stop
 
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
 
# two attr
start("red","fg")
print("hello everyone")
stop()
# two attr
start("green",'bg',4)
print("it's print green background text with underline")
stop()
# single attr
start("blue")
print(a)
stop()


Output:

 

The General Module’s clrscreen() function

It just cleared the terminal’s display.

Example:

Python3




from Designer.General import clrscreen
 
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
 
print(a)
clrscreen()


Output:

It’s clear the terminal’s display.

 

The General Module’s Fullbgclr() function

According to the specified parameters, it applies background and foreground colors to the entire terminal screen.

Function’s structure: Fullbgclr( FColor : str, BColor :str ) -> None:

These Values make for suitable inputs

{‘BLACK’: 0, ‘BLUE’: 1, ‘GREEN’: 2,’AQUA’: 3, ‘RED’: 4, ‘PURPLE’: 5, ‘YELLOW’:6, ‘WHITE ‘: 7, ‘GRAY’: 8, ‘LIGHT BLUE: 9,’LIGHT GREEN’: ‘A’, ‘BRIGHT WHITE’: ‘F’,’LIGHT AQUA’: ‘B’, ‘LIGHT YELLOW’: ‘E’,’LIGHT RED’: ‘C’, ‘LIGHT PURPLE’: ‘D’}

Example:

Python3




from Designer.General import Fullbgclr
 
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
 
Fullbgclr("C","7")
print(a)


Output:

 

The General Module’s color() function :

It just returns the text’s colored text value after applying the specified color string.

Function’s structure: color(TColor : str, String:str)->str:

Example:

Python3




from Designer.General import color
 
a = '''Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.'''
 
colored_txt = color("brown",a)
print(colored_txt)
print("When the text for that function is given, the colour will be applied.")
print()


Output :

 

The General Module’s color convention functions

There are 6 different convention functions available in this module.

  • rgb_to_txt() function: It is utilized to print colored text using a specified RGB value.
  • rgb_to_name() function: The name of the data is returned along with the RGB values otherwise it returns 0.
  •  name_to_rgb() function: The data’s return value depends on the specified name; otherwise, it returns None.
  • hex_to_name() function: The specified hex in data will return the value of the module that is currently being developed; otherwise, it will return None.
  • rgb_to_hex() function: If RGB data is provided, that value is returned; otherwise, None is returned.
  • hex_to_rgb() function: The data’s return value is the supplied hex value; otherwise, None is returned.

Example:

Python3




from Designer.General import *
 
hex_to_name = hex_to_name("#FFFFFF")
hex_to_rgb=hex_to_rgb("#545454")
rgb_to_hex=rgb_to_hex((255,255,255))
rgb_to_name=rgb_to_name((1,1,1))
rgb_to_txt=rgb_to_txt("w3wiki",(0,0,0))
 
print(" hex_to_name",hex_to_name,"\n",
      "hex_to_rgb",hex_to_rgb,"\n",
      "rgb_to_hex",rgb_to_hex,"\n",
      "rgb_to_name",rgb_to_name,"\n",
      "rgb_to_txt",rgb_to_txt,"\n",     
      )


Output:

 



Python terminal processing with TerminalDesigner module

In this article, we’ll look at how to use TerminalDesigner to produce colorful text for the terminal in Python. This module is quite compact. This module can be used to change the font’s color, style, and background, print images onto terminals for video playback, convert images to ASCII art and serve a variety of other functions. You can install the TerminalDesigner module in Python 3 by using the following command:

pip install TerminalDesigner

This module contains 5 Python files:

  • BackGroundColor Module
  • ForeGroundColor Module
  • HexName Module
  • RandomColor Module
  • General Module

Similar Reads

The BackGroundColor Module

The set_default_stylebg() method in the Background Module:...

The FrontGroundColor Module

...

HaxName Module

...

RandomColor Module

It has 610 methods with color names and an additional function called set_default_style(). It is simple to utilize; all we have to do is call the names of the colors and import the ForeGroundColor function from Designer. The colorful ForeGround text will be returned....

General Module

...