U C^Y!@sddlmZmZddlZddlmZddlmZddlm Z ddl Z ddl Z ddl Z ddl Z ddlmZmZddlmZmZmZmZdd lmZmZmZdd lmZGd d d eZdS) )unicode_literalsprint_functionN)Counter)contextmanager)Process)tablerow)wrap supports_ansi can_render locale_escape)MESSAGESCOLORSICONS)colorc @seZdZd%dd Zed d Zd&d dZd'ddZd(ddZd)ddZ d*ddZ d+ddZ ddZ ddZ ed,dd Zd-d!d"Zd.d#d$ZdS)/PrinterTFNP⠙⠹⠸⠼⠴⠦⠧⠇⠏|/-\WASABIc Cstd| d} td| d} t|_|o4| |_||_toH| |_|pR| |_ | |_ ||_ t t |_t t|_| |_|r|j||r|j|t|r|n||_dS)aInitialize the command-line printer. pretty (bool): Pretty-print output (colors, icons). no_print (bool): Don't actually print, just return. colors (dict): Add or overwrite color values, name mapped to value. icons (dict): Add or overwrite icons. Name mapped to unicode icon. line_max (int): Maximum line length (for divider). animation (unicode): Steps of loading animation for loading() method. animation_ascii (unicode): Alternative animation for ASCII terminals. hide_animation (bool): Don't display animation, e.g. for logs. ignore_warnings (bool): Do not output messages of type MESSAGE.WARN. env_prefix (unicode): Prefix for environment variables, e.g. WASABI_LOG_FRIENDLY. timestamp (bool): Print a timestamp (default False). RETURNS (Printer): The initialized printer. z{}_LOG_FRIENDLYFz {}_NO_PRETTYN)osgetenvformatr_countsprettyno_printr show_colorhide_animationignore_warningsline_maxdictrcolorsricons timestampupdater anim)selfrrr"r#r Z animationZanimation_asciirrZ env_prefixr$Zenv_log_friendlyZ env_no_prettyr(2/tmp/pip-install-6_kvzl1k/wasabi/wasabi/printer.py__init__s"      zPrinter.__init__cCs|jS)zGet the counts of how often the special printers were fired, e.g. MESSAGES.GOOD. Can be used to print an overview like "X warnings". )r)r'r(r(r)countsDszPrinter.countscCs|j||tj|||dS)zPrint a success message.styleshowspacedexits)_get_msgrZGOODr'titletextr/r0r1r(r(r)goodKsz Printer.goodcCs|j||tj|||dS)zPrint an error message.r-)r2rZFAILr3r(r(r)failQsz Printer.failcCs|j||tj|||dS)zPrint a warning message.r-)r2rWARNr3r(r(r)warnWsz Printer.warncCs|j||tj|||dS)zPrint an informational message.r-)r2rINFOr3r(r(r)info]sz Printer.infoc Cs|sdS|jr\|j|}|j|}|r>td||}|jrPt||d}t |dd}|rtd|t |dd}|j rt j d} d| |}|dk s|rd |}|js|st||dk rtjtjt||js|r|SdS) a'Print a message. title (unicode): The main text to print. text (unicode): Optional additional text to print. color (unicode / int): Foreground color. icon (unicode): Name of icon to add. spaced (unicode): Whether to add newlines around the output. show (bool): Whether to print or not. Can be used to only output messages under certain condition, e.g. if --verbose flag is set. no_print (bool): Don't actually print, just return. exits (int): Perform a system exit. N{} {})Zfgr)indentz{} {}z%Y-%m-%d %H:%M:%Sz{} {}z {} )rr"getr#r rstripr_colorr r$datetimenowstrftimerprintsysstdoutflushstderrexit) r'r4r5riconr0r/rr1rBr(r(r)r5cs2            z Printer.text=cCst|dkrtd||jr|j|}|rDtd||}|tt |j t|dd}|rtd|nd}t dj||dd d }t||j kr|||j t|}|j r|St |d S) aiPrint a divider with a headline: ============================ Headline here =========================== text (unicode): Headline text. If empty, only the line is printed. char (unicode): Line character to repeat, e.g. =. show (bool): Whether to print or not. icon (unicode): Optional icon to display with title. rz9Divider chars need to be one character long. Received: {}r<z {} r,z {deco}{text}{deco})decor5T)ZboldN)len ValueErrorrrr#r>r r?introundr r@rrD)r'r5charr/rJrMr(r(r)dividers*  " zPrinter.dividercKs<|dd}t|f|}|r&|||jr0|St|dS)zPrint data as a table. data (iterable / dict): The data to render. Either a list of lists (one per row) or a dict for two-column tables. kwargs: Table settings. See tables.table for details. r4N)poprrSrrD)r'datakwargsr4r5r(r(r)rs   z Printer.tablecKs"t|f|}|jr|St|dS)zPrint a table row. data (iterable): The individual columns to format. kwargs: Row settings. See tables.row for details. N)r rrD)r'rUrVr5r(r(r)r s z Printer.row Loading...c cs|jrdVn|jr$t|dVntjt|j|fd}|z dVWn:t k r}z| tj d|W5d}~XYnX| tj dtjdS)N)targetargs z ) rrrDrErFrGr_spinnerstart Exception terminatewrite)r'r5ter(r(r)loadings"    zPrinter.loadingcCs>t|jD],}tjd||tjt dq dS)Nz {} {}g?) itertoolscycler&rErFr_rrGtimesleep)r'r5rRr(r(r)r[s zPrinter._spinnerc Cs>|jr|tjkrd}|j|d7<|j|||||||dS)NFr)rrJr/r0r1)rrr8rr5)r'r4r5r.r/r0r1r(r(r)r2szPrinter._get_msg) TFNNrrrFFrF)r,r,TFN)r,r,TFN)r,r,TFN)r,r,TFN)r,r,NNFTFN)r,rKTN)rW)rW)NNFN)__name__ __module__ __qualname__r*propertyr+r6r7r9r;r5rSrr rrbr[r2r(r(r(r)rsD 0      1    r) __future__rrrA collectionsr contextlibrmultiprocessingrrcrErertablesrr utilr r r r rrrrr@objectrr(r(r(r)s