Package: mizue
A simple package containing various command-line utilities.Table of ContentsCautionInstallationUtilitiesGridPrinterProgressCautionThis 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.InstallationpipinstallmizueUtilities (Work in Progress)GridPrinterProgressMore utilities coming soon...GridThis class can be used to print a table/grid in the terminal.frommizue.printer.gridimportGrid,ColumnSettings,Alignmentfrommizue.fileimportFileUtilsimportoscolumn2=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(lambdaf:[f,FileUtils.get_readable_file_size(os.stat(f).st_size)],filelist))grid=Grid(columns,grid_data)grid.print()ColumnSettingsallows 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.RIGHTwidth: The width of the columnrenderer: A function that takes in an object of typeCellRendererArgsand returns a string to be displayed in the column.Gridallows 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.NONEcell_renderer: A function that takes in an object of typeCellRendererArgsand returns a string to be displayed in the cell.PrinterThis class contains various static methods for printing text in different colors.frommizue.printerimportPrinterPrinter.print('Hello World!','#ff0000')Printer.print('Hello World!',(255,0,0))Following is a list of some of the methods available in this class:print(text, text_color, background_color=None, bold=False, underline=False)error(text)warning(text)info(text)success(text)Using thecolorizemethod fromColorizerclass, you can format a text and use it later. For example:frommizue.printerimportColorizercolored_text=Colorizer.colorize('Hello World!','#ff0000')print(colored_text)ProgressThis is a simple class for displaying progress bars in the terminal.frommizue.progressimportProgressfromtimeimportsleepprogress=Progress(0,1200,0)# (start, end, current)progress.label='Progress: '# This text is displayed before the progress barprogress.info_text='(in progress)'# This text is displayed after the progress barprogress.start()foriinrange(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 spinnerAn example of rendering a custom label (appears before the progress bar):frommizue.progressimportProgressfrommizue.progressimportLabelRendererArgsfrommizue.printerimportColorizerfromtimeimportsleepdeflabel_renderer(args:LabelRendererArgs)->str:returnColorizer.colorize(args.label,'#ff0000')\ifargs.percentage<50\elseColorizer.colorize(args.label,'#00ff00')progress=Progress(0,1200,0)progress.label_renderer=label_rendererprogress.start()foriinrange(1200):progress.update_value(i)sleep(0.1)progress.stop()