A Python package for various utilities
Project description
A simple package containing various command-line utilities.
Table of Contents
Caution
This package does not have any tests. It is not recommended to use it in production. I wrote this package for my own personal use. I don't have any immediate plans to add tests and make it production-ready. Use it at your own risk.
Installation
pip install mizue
Utilities (Work in Progress)
Grid
This class can be used to print a table/grid in the terminal.
from mizue.printer.grid import Grid, ColumnSettings, Alignment
from mizue.file import FileUtils
import os
column2 = ColumnSettings(title='File', alignment=Alignment.RIGHT)
column3 = ColumnSettings(title='Size', alignment=Alignment.CENTER, width=50)
columns = [column2, column3]
filelist = FileUtils.list_files(".", recursive=True, fullpath=True)
grid_data = list(map(lambda f: [f, FileUtils.get_readable_file_size(os.stat(f).st_size)], filelist))
grid = Grid(columns, grid_data)
grid.print()
ColumnSettings allows the following attributes to be set:
title: The title of the columnalignment: The alignment of the column. Can be one of the following:Alignment.LEFTAlignment.CENTERAlignment.RIGHT
width: The width of the columnrenderer: A function that takes in an object of typeCellRendererArgsand returns a string to be displayed in the column.
Grid allows the following attributes to be set:
border_color: The color of the border in hex formatborder_style: The style of the border. Can be one of the following:BorderStyle.SINGLEBorderStyle.DOUBLEBorderStyle.BASICBorderStyle.NONE
cell_renderer: A function that takes in an object of typeCellRendererArgsand returns a string to be displayed in the cell.
Printer
This class contains various static methods for printing text in different colors.
from mizue.printer import Printer
Printer.print_hex('Hello World!', '#ff0000')
Printer.print_rgb('Hello World!', (255, 0, 0))
Following is a list of some of the methods available in this class:
format_hex(text, text_color, background_color=None, bold=False, underline=False)format_rgb(text, rgb_color, background_color=None, bold=False, underline=False)print_hex(text, text_color, background_color=None, bold=False, underline=False)print_rgb(text, rgb_color, background_color=None, bold=False, underline=False)error(text)warning(text)info(text)success(text)
Using the format_* methods, you can format text and use it later. For example:
from mizue.printer import Printer
colored_text = Printer.format_hex('Hello World!', '#ff0000')
print(colored_text)
Progress
This is a simple class for displaying progress bars in the terminal.
from mizue.progress import Progress
from time import sleep
progress = Progress(0, 1200, 0) # (start, end, current)
progress.label = 'Progress: ' # This text is displayed before the progress bar
progress.info_text = '(in progress)' # This text is displayed after the progress bar
progress.start()
for i in range(1200):
progress.update_value(i)
sleep(0.01)
progress.stop()
Progress allows the following attributes to be set:
info_separator: The character to be used to separate the info text from the progress barinfo_separaotr_renderer: A function that takes in an object of typeInfoSeparatorRendererArgsand returns a string to be used to separate the info text from the progress barinfo_text: Text to be displayed after the progress barinfo_text_renderer: A function that takes in an object of typeInfoTextRendererArgsand returns a string to be displayed after the progress barlabel: Text to be displayed before the progress barlabel_renderer: A function that takes in an object of typeLabelRendererArgsand returns a string to be displayed before the progress barprogress_bar_renderer: A function that takes in an object of typeProgressBarRendererArgsand returns a string to be displayed as the progress barpercentage_renderer: A function that takes in an object of typePercentageRendererArgsand returns a string to be displayed as the percentagespinner_renderer: A function that takes in an object of typeSpinnerRendererArgsand returns a string to be displayed as the spinner
An example of rendering a custom label (appears before the progress bar):
from mizue.progress import Progress
from mizue.progress import LabelRendererArgs
from mizue.printer import Printer
from time import sleep
def label_renderer(args: LabelRendererArgs) -> str:
return Printer.format_hex(args.label, '#ff0000') \
if args.percentage < 50 \
else Printer.format_hex(args.label, '#00ff00')
progress = Progress(0, 1200, 0)
progress.label_renderer = label_renderer
progress.start()
for i in range(1200):
progress.update_value(i)
sleep(0.1)
progress.stop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 mizue-0.5.0.tar.gz.
File metadata
- Download URL: mizue-0.5.0.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
235caf17a7ed22b5e84ca136ce36d079054d72a024b64ddbc794c26dfd1840a9
|
|
| MD5 |
5c27ff79507b151f02b7ecf22e91ae12
|
|
| BLAKE2b-256 |
a5c3766777ad982d2eb882d8a1527e5921ccc9ccabffb4ed22d0317aec924670
|
File details
Details for the file mizue-0.5.0-py3-none-any.whl.
File metadata
- Download URL: mizue-0.5.0-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e461db0ef5585acd9bf619335ea6820a548a8c97069d74aacee9e2fd572396d
|
|
| MD5 |
bf8b105e7b5586ddbbea6c16820fb494
|
|
| BLAKE2b-256 |
d88a0ef94fa845fe7b99c12241ea3f439599df0cca679ced5696666a5cda1bca
|