Skip to main content

A to create a better ui with your terminal.

Project description

Better Terminal

A simple pip library to make your terminal simpler

Documentation

Installation

pip install better_terminal

Creating a template

A template is just a simple string where you can add variables as placeholders.

from better_terminal import Terminal

terminal = Terminal.New("@RED@Launching Rocket in @BRIGHT_YELLOW@#countdown#.")

If you run the script now, the place holder will stay as it is. To change that we need to create variable for those place holder.
[NOTE: Notice the @ colors @, we will talk about that later]

Creating variables

.create_variable() requires two arguments, the name of the placeholder and a default value for the variable.

countdown = terminal.create_variable("countdown", 5)

As soon as we create the variable the placeholders will automatically update.

Using the variable

You can get the current value of the variable with .value method

print(variable.value)

To update the variable use .update() which requires one argument, that is the new value of the variable
Lets see an example with a simple countdown

while True:
    sleep(2)
    countdown.update(countdown.value - 1)
    if(countdown.value == 0):    
        terminal.update_template("@GREEN@ROCKET LAUNCHED!") 
        sleep(10)
        break

Yay!

Changing template

You don't need to be stuck with a sinple template. You can change your template with .update_template() function which accepts one arguemnt that is the new template.

Colors

Ever thought that terminals were boring, well lets decorate them with colors.

You can use the .COLOR["COLOR_NAME"] property of Terminal class to get or color string.

Terminal.New(Terminal.COLOR["GREEN"] + "Hello World")

This will change the text after color to green.\

[NOTE: There color value ever works with the variable value]\

Or you can just use the color name with "@"on both sides.

Terminal.New("@GREEN@Hello World")

To switch to the default color, use @CLEAR@ or Terminal.COLOR["CLEAR"].

Example Code

from better_terminal import Terminal
from time import sleep

terminal = Terminal.New("@RED@Launching Rocket in @BRIGHT_YELLOW@#countdown#.")

countdown = terminal.create_variable("countdown", 5)

while True:
    sleep(2)
    countdown.update(countdown.value - 1)
    if(countdown.value == 0):    
        terminal.update_template("@GREEN@ROCKET LAUNCHED!") 
        sleep(10)
        break

License

We use the MIT License for this project

FAQ

When will be the next update?

Quite Soon

When will the new update bring?

The new update will bring integration of terminal input with the whole system.

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

better_terminal-0.0.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

better_terminal-0.0.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

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