Lightweight terminal utilities
Project description
tooly
Lightweight terminal utilities for Python developers.
Installation
pip install tooly-dev
Usage
import tooly
import time
from datetime import datetime
colors = tooly.ColorSystem() #? recommended
wait_time = 2
skip_userinput = False
print(colors.info("Welcome to Tooly!")) #* Color example
tooly.typewrite(colors.info("Example text"), delay=0.05) #* Typewrite example
with tooly.measure("Example measure"):
#? Do something
time.sleep(wait_time)
with tooly.spinner("Example spinner", done_msg="Exaple spinner done"):
#? Do something
time.sleep(wait_time)
#* Highlight example
text = "Some interesting text with keywords"
print(colors.highlight(text, ["keywords", "text"], "yellow")) #? text, keywords, color
#* Indent example
#? You can use indent for file tree for example
print(colors.indent("Example folder/", 0))
print(colors.indent("Example python file", 1))
print(colors.indent("Example readme file", 1))
print(colors.indent("Example subfolder/", 1))
print(colors.indent("howtodoerrors.txt", 2))
print(colors.indent("Example file", 0))
#* Diff feature examples
# word mode sql example
sql_before = "SELECT id, name FROM users WHERE active = 1"
sql_after = "SELECT id, email FROM users WHERE active = 1 LIMIT 100"
print(tooly.diff_highlight(sql_before, sql_after, tooly.DiffMode.WORD))
# char mode url example
url_before = "https://api.example.com/v1/users/42"
url_after = "https://api.example.com/v2/users/42/profile"
print(tooly.diff_highlight(url_before, url_after, tooly.DiffMode.CHAR))
# line mode config example
cfg_before = """
host = localhost
port = 5432
debug = true
workers = 2
"""
cfg_after = """
host = example.com
port = 5432
debug = false
workers = 8
timeout = 30
"""
print(tooly.diff_highlight(cfg_before, cfg_after, tooly.DiffMode.LINE, context_lines=1))
#* Validator example
"""
Methods:
str.isalpha() - only letters
str.isdigit() - only dights
str.isnumeric() - only dights (including unicode)
str.isalnum() - digits and letters
str.islower() - only lower case
str.isupper() - only upper case
str.istitle() - every word starts with a capital
str.startswith(prefix) - starts with a prefix
str.endswith(suffix) - ends with a suffix
str.isprintable() - only printable characters
str.isascii() - only ASCII characters
"""
if not skip_userinput:
tooly.userinput("Enter your name: ", validator=lambda name: name.isalpha(), error_msg="Invalid name. Try again.")
tooly.userinput("Enter your age: ", validator=lambda name: name.isdigit(), error_msg="Invalid age. Try again.")
#* Recorder example
with tooly.recorder("example_session.log"):
print("Recorder example...")
name = tooly.userinput("Enter your name: ", validator=lambda name: name.isalpha(), error_msg="Invalid name. Try again.")
print(f"Hello, {name}!")
#* Clear console example
print("Console will be cleared")
input("Press Enter to continue...")
tooly.cls()
#* On platform example
result = tooly.on_platform(
windows=lambda: "Windows",
linux=lambda: "Linux",
macos=lambda: "macOS",
android=lambda: "Android",
ios=lambda: "iOS",
default=lambda: "Unknown"
)
print(f"Current platform: {result}")
input("Press Enter to continue...")
#* Menu example
choice = tooly.menu(
["Start server", "Stop server", "Exit"],
title="Example menu"
)
print(f"You chose: {choice}")
#* Confirm example
if tooly.confirm("Are you sure?"):
print("Confirmed")
else:
print("Canceled")
input("Press Enter to continue...")
#* Watch example
def show_time():
return f"Текущее время: {datetime.now().strftime("%H:%M:%S")}"
tooly.watch(show_time, interval=1)
#* Notify example
tooly.notify("Example", "Example text")
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
tooly_dev-1.3.0.tar.gz
(11.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tooly_dev-1.3.0.tar.gz.
File metadata
- Download URL: tooly_dev-1.3.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96c4388325ac72a2a86da0f4f13182ab0b39d23131eccd7ef139d8a6f2317edd
|
|
| MD5 |
a61485b8360fb682c70d7598e40be860
|
|
| BLAKE2b-256 |
de8e23e7c8970cb3539e37ceddb5de26e70a09f3ccd915c751aec14734de428f
|
File details
Details for the file tooly_dev-1.3.0-py3-none-any.whl.
File metadata
- Download URL: tooly_dev-1.3.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4655b6d6b49cfb2f3a3b76c881d0606f8c1fb14b1a27afa78e6344d719ee03a7
|
|
| MD5 |
852e77492876e091c59cd5790f0e8005
|
|
| BLAKE2b-256 |
66f179ec86cb5bbe4d6b7a3a5ea0ea77506e063c1196f1a884c5826170c67905
|