o 2&a<@sddlZddlZddlZddlZddlmZddlmZdddZddZ dd d Z dd dZ  d ddZ ddZ GdddeZGdddeZGdddeZGdddeZGdddeZdS)!N)is_a_tty)sixTF) autoresetstripcCst|}tdd|DS)Ncss&|]}t|dvr dndVqdS)WFAN) unicodedataeast_asian_width).0charr ./usr/lib/python3/dist-packages/awscli/table.py 'sz"get_text_length..)r text_typesum)textr r rget_text_lengths rPcCstzddlm}ddlm}Wn ty|YSwztd|tj|ddd\}}W|St y9|YSw)Nr) TIOCGWINSZ)ioctlhhhhzr) termiosrfcntlr ImportErrorstructunpacksysstdout Exception) default_widthrrheightwidthr r rdetermine_terminal_width+s      r#|c Cs|durt|}g}|d|dd}||d||t|||}|t||}|d|||d|} | S)aCenter text with specified edge chars. You can pass in the length of the text as an arg, otherwise it is computed automatically for you. This can allow you to center a string not based on it's literal length (useful if you're using ANSI codes). Nrr )rappendjoin) rlength left_edge right_edge text_lengthoutput char_start length_so_farright_side_spacesfinalr r r center_text;s   r2rc Cs|durt|}||t|t|}||dkr|}nd}g}d} ||| t|7} |d|| |7} ||| |7} |d|| t|||d|S)zLeft align text.Nrr%r&)rr'lenr() rr)r*r+r, left_paddingcomputed_lengthpaddingr-r/r r r align_leftQs,      r7cCsvt|D]4\}}t|jdkr8|jr8|j}t}|j|_|j|_t||jdD] \}}|||gq(|||<qdS)Nrr) enumerater3rowsheadersSectiontitle indent_levelzipadd_row)sectionsisectionr: new_sectionheaderelementr r rconvert_to_vertical_tableks rFc@s*eZdZ  d ddZddZddZdS) IndentedStreamr$cCs||_||_||_||_dSN)_stream _indent_level_left_indent_char_right_indent_char)selfstreamr=left_indent_charright_indent_charr r r__init__s zIndentedStream.__init__cCsf|j|j|j|dr+|j|dd|j|j|j|jddS|j|dS)N )rIwriterKrJendswithrLrMrr r rrTs  zIndentedStream.writecCs t|j|SrH)getattrrI)rMattrr r r __getattr__s zIndentedStream.__getattr__N)r$r$)__name__ __module__ __qualname__rQrTrYr r r rrGs   rGc@s,eZdZddZddZddZddZd S) StylercC|SrHr rVr r r style_titlezStyler.style_titlecCr^rHr rVr r rstyle_header_columnr`zStyler.style_header_columncCr^rHr rVr r rstyle_row_elementr`zStyler.style_row_elementcCr^rHr rVr r rstyle_indentation_charr`zStyler.style_indentation_charN)rZr[r\r_rarbrcr r r rr]s  r]c@s4eZdZddZddZddZddZd d Zd S) ColorizedStylercCstjditdS)Nr )coloramainitCOLORAMA_KWARGSrMr r rrQszColorizedStyler.__init__cCr^rHr rVr r rr_zColorizedStyler.style_titlecCr^rHr rVr r rrariz#ColorizedStyler.style_header_columncCtjjtjj|tjjSrH)reStyleBRIGHTForeBLUE RESET_ALLrVr r rrb z!ColorizedStyler.style_row_elementcCrjrH)rerkDIMrmYELLOWrorVr r rrcrpz&ColorizedStyler.style_indentation_charN)rZr[r\rQr_rarbrcr r r rrds  rdc@s~eZdZ   dddZddZdd Zd d Zd d dZddZddZ ddZ ddZ ddZ ddZ ddZddZdS)! MultiTableNTr$cCsv||_|rt|_|jg|_nd|_g|_|dur&tr!t|_nt|_n||_d|_||_ |dur9t |_ dSdS)Nr) _auto_reformatr;_current_section _sectionsrrd_stylerr]_rendering_index_column_separatorr#_terminal_width)rMterminal_widthinitial_sectioncolumn_separatorterminalstyler auto_reformatr r rrQs     zMultiTable.__init__cC|j|dSrH)ru add_titlerMr<r r rrzMultiTable.add_titlecCrrH)ru add_headerrMr:r r radd_row_headerrzMultiTable.add_row_headercCrrH)rur?)rM row_elementsr r rr?rzMultiTable.add_rowrcCs.t|_|j|j|j|||j_dSrH)r;rurvr'rr=)rMr<r=r r rrCs  zMultiTable.new_sectioncCsX|}||}|rt|j|}|d|d|jD] }||||q dS)N-rR)_calculate_max_width_determine_conversion_neededrFrvrT_render_section)rMrN max_widthshould_convert_tablerBr r rrenders   zMultiTable.rendercCs||jkr|jSdSrH)rzrtrMrr r rrs z'MultiTable._determine_conversion_neededcCstdd|jD}|S)Ncss"|] }|jdd|jdVqdS)T)r6 with_border outer_paddingN) total_widthr=)r sr r rrs z2MultiTable._calculate_max_width..)maxrvrr r rrszMultiTable._calculate_max_widthcCs\t||j|jd|jd}||jd8}||||||||||||dS)Nr$r)rGr=rwrc _render_title_render_column_titles _render_rows)rMrBrrNr r rrs  zMultiTable._render_sectionc Csj|jr/|j|j}|t||ddt|jd|js1|js3|dd|dddSdSdSdS)Nr$rR+%s+rr)r<rwr_rTr2rr:r9)rMrBrrNr<r r rrs zMultiTable._render_titlec Cs|jsdS|jd|d}d}d}d}t||jD]$\}} |j| } |r)d} d}nd} |t| || dt| d7}||7}q|||||d dS Nr)r6rr&rTr$F)rr)r*r+r,rR) r:calculate_column_widthsr>rwrar2r_write_line_breakrT) rMrBrrNwidthscurrentr/firstr"rDstylized_headerr*r r rr s*   z MultiTable._render_column_titlescCsfg}d}|D]}|r|dd|dd}q|dd|dq|d|d |dS) NTrrrFz%s+rrRr&)r'rTr()rMrNrpartsrr"r r rr&s zMultiTable._write_line_breakc Cs|jsdS|jd|d}|sdS||||jD]:}d}d}d}t||D]%\} } |r1d} d}nd} |j| } |t| | | |jt| d7}|| 7}q&| |d q|||dSr) r9rrr>rwrbr7ryrrT) rMrBrrNrrowrr/rr"rEr*stylizedr r rr4s4    zMultiTable._render_rows)NTr$NNT)r)rZr[r\rQrrr?rCrrrrrrrrr r r rrss"      rsc@s`eZdZddZddZdddZdd d Zd d ZddZddZ ddZ ddZ ddZ dS)r;cCs(d|_g|_g|_d|_d|_g|_dS)Nr&r)r<r:r9r= _num_cols _max_widthsrhr r rrQSs  zSection.__init__cCsd|j|j|jt|jfS)Nz;Section(title=%s, headers=%s, indent_level=%s, num_rows=%s))r<r:r=r3r9rhr r r__repr__[szSection.__repr__rNcsfdd|jD}|dur|S|s|S|tt|fdd|D}t||}|dkritt|}|dkr=t|}|D]%}|dkrR||d8<|d8}n ||d7<|d7}|dkrdnq?|dks/|S)Ncsg|]}|qSr r r w)r6r r az3Section.calculate_column_widths..csg|] }tt|qSr )introundr) scale_factorr rrisrr)rfloatrranger3reversed)rMr6runscaled_widthsscaledoff_by iter_orderrAr )r6rrr_s.    zSection.calculate_column_widthsFcCsVd}d}|D]}|||7}q|r||7}|||7}tt|j||||S)Nrr)rrrr<)rMr6rrtotalborder_paddingrr r rr|s  zSection.total_widthcCs ||_dSrH)r<rr r rrs zSection.add_titlecCs.|||jdurt||_|||_dSrH)_update_max_widthsrr3_format_headersr:rr r rrs   zSection.add_headercCr^rHr rr r rrr`zSection._format_headerscCs\|jdur t||_t||jkrtd|jt|f||}|j|||dS)Nz.Row should have %s elements, instead it has %s)rr3 ValueError _format_rowr9r'rrMrr r rr?s     zSection.add_rowcCsdd|DS)NcSsg|]}t|qSr )rr)r rr r rrsz'Section._format_row..r rr r rrszSection._format_rowcCsJ|js dd|D|_dSt|D]\}}tt||j||j|<qdS)NcSsg|]}t|qSr )r)r elr r rrrz.Section._update_max_widths..)rr8rr)rMrrArr r rrs zSection._update_max_widths)rN)rFr) rZr[r\rQrrrrrrr?rrr r r rr;Rs    r;)r)rr$r$N)r$r$Nr)rrr re awscli.utilsr awscli.compatrrgrr#r2r7rFobjectrGr]rdrsr;r r r rs0