Skip to main content

A modular CLI pattern engine

Project description

Pytterns

One stop library for all your Terminal Patterns

With pytterns, you can make your projects pop with patterns and shapes. With this, you can print any pattern, with high customization, in any senario in the terminal. You can even make your custom Patterns through .py based pattern template system. This project has solid security and large compatibility with terminal sizes, color rendering, and OS. If you are working on a terminal project, need a loading page or you need to print shapes in any case, No need to learn each and every pattern. Just use Pytterns!

How it works

Pytterns has default patterns which can be used to get basic shapes with quite a lot of customization directly printed in the console.

You may also make your own pattern theme by making your own .py templates. Once added to Pytterns, you can use it in your code RIGHT AWAY!

Installation

To get started, you can use 2 options.

  1. Download the files from git and integrate with your code.

OR

  1. Download the library through pip. → Download Through PIP

Get started with Default Pytterns

Each Pyttern Pattern file which is made by me is heavily documented, so if you open it in the /patterns folder, you can get a good understanding of the args and how its processed.

Once installed, just use this to start using Pytterns in your code

from pytterns import Pytterns
pt = Pytterns()

Basic Default Args for Patterns

To make any supported shape, we use the following method to print it in the terminal:

pt.<shape name>(<size>, char=<char>, center=<Bool>, color=<color> ...)

For a simple square of side length 10:

pt.square(10)

Output:

* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *

Char

To make this same square with different characters, we can use the char arg.

Char takes in a String Input.

For Example, to make the above square with "x":

pt.square(10,char="x")

You get a square made with x

Center

With the center arg, we can center most of the shapes perfectly in the terminal.

Center takes a boolean input, True/False

For Example, to center the above square, we use:

pt.square(10, char="x", center=True)

Color

With the color arg, you can color your shapes with the following colors:

  • red
  • green
  • blue
  • yellow
  • magenta
  • cyan
  • white
  • reset

For example, you can color the above square like:

pt.square(10, char="x", center=True,color="red")

Hollow

With the hollow arg, you can make shapes hollow, and just get its border.

The hollow arg takes in a Boolean, True/False.

For Example, you can make a Red Centered hollow square of radius 10, made with $ like:

pt.square(10, char="$",center=True,color="red",hollow=True)

Output:

-$ $ $ $ $ $ $ $ $ $
-$                 $
-$                 $
-$                 $
-$                 $
-$                 $
-$                 $
-$                 $
-$                 $
-$ $ $ $ $ $ $ $ $ $

Terminal render would be proper and centered.

Filler

As you may have noticed in above output examples, each shape has a space (filler) between the characters. This is a space by default, but we can customize this through the filler arg.

For Example, for the above hollow square filled with Spaces, we can make it fill with - through:

pt.square(10, char="$",center=True,color="red",hollow=True, filler="-")

Output:

- $-$-$-$-$-$-$-$-$-$
- $-----------------$
- $-----------------$
- $-----------------$
- $-----------------$
- $-----------------$
- $-----------------$
- $-----------------$
- $-----------------$
- $-$-$-$-$-$-$-$-$-$

Terminal render would be proper and centered.

Other Important Args

For special shapes like Triangles or Pyramids, which could be flipped upside down, Direction and Invert can be used.

Direction:

Used to set pointing direction of a supported shape.

For Example, We can make a triangle point to 2 directions, Left and Right:

pt.triangle(10, char="*",hollow=True,filler="-",direction="left")

Output:

*-
*-*-
*- -*-
*- - -*-
*- - - -*-
*- - - - -*-
*- - - - - -*-
*- - - - - - -*-
*- - - - - - - -*-
*-*-*-*-*-*-*-*-*-*-

Invert:

With this, we can make supported shapes Upside-Down. This can be used with direction arg to gain full control of the shape's pointing.

For example, to make a left triangle inverted we use:

pt.triangle(10, char="*",hollow=True,filler="-",direction="left",invert=True)

Output:

*-*-*-*-*-*-*-*-*-*-
*- - - - - - - -*-
*- - - - - - -*-
*- - - - - -*-
*- - - - -*-
*- - - -*-
*- - -*-
*- -*-
*-*-
*-

Custom Templates

Through templates, we can make custom patterns based on our own code, and seamlessly use it just like we did with the default code.

This may sound difficult, but we don't even need a bit of advanced programming for this.

Getting Started:

Firstly ensure Pytterns is installed in your project. Then make a folder /patterns in your project's root directory.

You can create files in this folder now, and through this you can add custom patterns to your projects.

Once you make a .py file, start with the draw() function and define the args you need for the pattern you are trying to make. Size and Center is always must to keep, rest args are based on your wish.

For Example, this is the function definition for Triangles.

def draw(size,center, char="*", filler=" ", hollow=False, direction="left", invert=False):

In this, Size (int) is the shape's size, and Center is a boolean telling if trigger has opted for centering or not.

Note: If you wish to use centering in your code, you need not to make any centering system in your template file. Just make sure its compatible with our centering and you are good to go. Similarly, you also do not need to worry about colors, those get added automatically too!

After this, you can just make your pattern function, and print the output in that function itself and the Pytterns takes care of everything!

Advanced Use

With pytterns, you can also make terminal animations/loading-graphics.

For Example, if you want fast upward moving arrows, use this:

import time
colors=["red", "green", "yellow", "blue", "magenta", "cyan"]

while True:
    for i in range(0, 6):
        pt.triangle(i, char="-", color=colors[i], hollow=False, center=True)
        time.sleep(0.05)
    

Output:

Upward Moving Arrows

*It would be animated due to loop, demo videos in /images folder

Or, For Example you can use my favorite, the Square Loading:

import time,os
colors=["red", "green", "yellow", "blue", "magenta", "cyan"]
while True:
    for i in range(0, 6):
        pt.square(i, char="-", color=colors[i], hollow=False, center=True)
        time.sleep(0.05)
        os.system("cls" if os.name == "nt" else "clear")

For this you would need to see the video at /images folder

Contribution

This project is all open for your contributions! You can make more patterns for the default installation, and fix common rendering bugs. Lets together make the best python patterns library in the world!

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get_pytterns-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

get_pytterns-0.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file get_pytterns-0.1.1.tar.gz.

File metadata

  • Download URL: get_pytterns-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for get_pytterns-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6ea1ff0507c3fcd35bf1581db6ce9287c66340ca90f2603d05aa574259fef7cb
MD5 306337d023e7588650bb9eb5db152bdb
BLAKE2b-256 9562fbb3e6b50dc2ea1552e615337e07bc59d0a83f6afe51288c3cf226c95ac7

See more details on using hashes here.

File details

Details for the file get_pytterns-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: get_pytterns-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for get_pytterns-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b8adbbe90d6891b2ca71eebdd4d140f6f5138cade06a38f3e074fa5116e2a56
MD5 6eda7df19874275d99304e4529ded9ba
BLAKE2b-256 303caf37c7305ac9e5dcd69c75266f11a0170a3574192b84c03f7626ca7bfb71

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page