Package: cli-badges
Quirky little python library for generating badges for your cli apps.Inspired & Python Port ofcli-badges - nombrekeffGetting StartedInstallingAs usual, you need to install from PIP:$ pip install cli-badgesUsageThis is a simple example, using badges to display test results:fromcli_badgesimportbadgefailedBadge=badge("failed",'2',messagebg='red')skippedBadge=badge('skipped','1',messagebg='yellow',messagecolor='black')successBadge=badge('success','8',messagebg='green',messagecolor='black')print(failedBadge,successBadge,skippedBadge)The above would output something similar to the terminal:You could also create a donate badge with a link (if supported):fromcli_badgesimportbadgedonateBadge=badge('❤️ donate','ko-fi',messagelink='https://ko-fi.com/logginjs');print(donateBadge)You can also only show the label:fromcli_badgesimportbadgeonlyLabel=badge('❤️ donate','')print(onlyLabel)Example output is a mock, console output will vary slightly from terminal to terminal.Badge StructureA badge is conformed of a label and a message<label>:<message>. Each segment can be customized, by changing bg color, text color and style.Available OptionsOptionValueDefaultlabelString''messageString''messagebgColorbluelabelbgColordark_graymessagecolorColorwhitelabelcolorColorwhitelabelwidthIntegerlabel length + 2messagewidthIntegerlabel length + 2labelstylesArray of Styles[]messagestylesArray of Styles[]labellinkURL''messagelinkURL''swapbooleanFalsethemeThemeNoneColorscli-badgesusescoloredinternally for managing colors, you can check the list of available colors there.Stylescli-badgesusescoloredinternally for managing styles, you can check the list of available styles there.Available StylesbolddimunderlinedreversehiddenLinksYou can output badges with a link attached to it, that can be clicked in some terminals.labellinkoption will add the link to the label, whilemessagelinkoption will add the link to the message.⚠︎ cli-badges will only output link if its supported by your terminal.Seethisfor information on supported terminalsbadge('with','link',labellink='https://link.com',messagelink='https://link2.com');ThemesThemes are a way to store badge configuration for repeated use. All the options (except for the theme option, obviously) that are needed by the badge can be stored by making a theme.The library comes with a set of inbuilt themes, but you can also define your ownInbuilt Themesred: Red Message Backgroundgreen: Green Message Backgroundyellow: Black Colored Message on Yellow Backgroundcyan: Black Colored Message on Cyan Backgroundmagenta: Black Colored Message on Magenta Backgroundsuccess: 'Success' Message on Green Backgroundfailed: 'Failed' Message on Red BackgroundUsing ThemesTHEMEstores all the available themes, and has to be passed to thebadge()functionsthemeargument. Arguments present in the theme will override the passed arguments. Missing arguments will have default valuesfromcli_badgesimportbadge,THEMEred_badge=badge('Red','Badge',theme=THEME.red)print(red_badge)Adding New ThemesDirectly in CodeTo add a Theme directly,add_theme(name,config)function is used.nameis the name of the theme,configis adictcontaining the required optionsfromcli_badgesimportbadge,add_theme,THEMEadd_theme('donate',{'label':'❤️ donate'})donate_badge=badge(message='kofi',theme=THEME.donate)print(donate_badge)From a JSON FileYou can store the Theme configurations in ajsonfile and load them usingload_themes(file)function wherefileis the Themejsonfile#themes.json{"redblue":{"messagebg":"blue","labelbg":"red","messagestyles":["bold"]}}fromcli_badgesimportbadge,load_themes,THEMEload_themes(open("themes.json","r"))redblue_badge=badge('RED','BLUE',theme=THEME.redblue)print(redblue_badge)Swapping StylesTheswapoption is used to apply the message styles to the label and vice-versafromcli_badgesimportbadgenormal_badge=badge('RED','BLUE',labelbg='red',messagebg='blue')swapped_badge=badge('RED','BLUE',labelbg='red',messagebg='blue',swap=True)print(normal_badge,swapped_badge)Other Libraries?cli-badges is also available in other languages:Node@nombrekeff/cli-badgesDeno@Delta456/cli_badgesContributions are very welcomed 🥰