]>
jfr.im git - dlqueue.git/blob - venv/lib/python3.11/site-packages/pip/_vendor/rich/__main__.py
3 from time
import process_time
5 from pip
._ vendor
. rich
import box
6 from pip
._ vendor
. rich
. color
import Color
7 from pip
._ vendor
. rich
. console
import Console
, ConsoleOptions
, Group
, RenderableType
, RenderResult
8 from pip
._ vendor
. rich
. markdown
import Markdown
9 from pip
._ vendor
. rich
. measure
import Measurement
10 from pip
._ vendor
. rich
. pretty
import Pretty
11 from pip
._ vendor
. rich
. segment
import Segment
12 from pip
._ vendor
. rich
. style
import Style
13 from pip
._ vendor
. rich
. syntax
import Syntax
14 from pip
._ vendor
. rich
. table
import Table
15 from pip
._ vendor
. rich
. text
import Text
20 self
, console
: Console
, options
: ConsoleOptions
23 for x
in range ( options
. max_width
):
24 h
= x
/ options
. max_width
25 l
= 0.1 + (( y
/ 5 ) * 0.7 )
26 r1
, g1
, b1
= colorsys
. hls_to_rgb ( h
, l
, 1.0 )
27 r2
, g2
, b2
= colorsys
. hls_to_rgb ( h
, l
+ 0.7 / 10 , 1.0 )
28 bgcolor
= Color
. from_rgb ( r1
* 255 , g1
* 255 , b1
* 255 )
29 color
= Color
. from_rgb ( r2
* 255 , g2
* 255 , b2
* 255 )
30 yield Segment ( "▄" , Style ( color
= color
, bgcolor
= bgcolor
))
34 self
, console
: "Console" , options
: ConsoleOptions
36 return Measurement ( 1 , options
. max_width
)
39 def make_test_card () -> Table
:
40 """Get a renderable that demonstrates a number of features."""
41 table
= Table
. grid ( padding
= 1 , pad_edge
= True )
42 table
. title
= "Rich features"
43 table
. add_column ( "Feature" , no_wrap
= True , justify
= "center" , style
= "bold red" )
44 table
. add_column ( "Demonstration" )
55 "✓ [bold green]4-bit color[/] \n "
56 "✓ [bold blue]8-bit color[/] \n "
57 "✓ [bold magenta]Truecolor (16.7 million)[/] \n "
58 "✓ [bold yellow]Dumb terminals[/] \n "
59 "✓ [bold cyan]Automatic color conversion"
64 table
. add_row ( "Colors" , color_table
)
68 "All ansi styles: [bold]bold[/], [dim]dim[/], [italic]italic[/italic], [underline]underline[/], [strike]strikethrough[/], [reverse]reverse[/], and even [blink]blink[/]." ,
71 lorem
= "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in metus sed sapien ultricies pretium a at justo. Maecenas luctus velit et auctor maximus."
72 lorem_table
= Table
. grid ( padding
= 1 , collapse_padding
= True )
73 lorem_table
. pad_edge
= False
75 Text ( lorem
, justify
= "left" , style
= "green" ),
76 Text ( lorem
, justify
= "center" , style
= "yellow" ),
77 Text ( lorem
, justify
= "right" , style
= "blue" ),
78 Text ( lorem
, justify
= "full" , style
= "red" ),
84 """Word wrap text. Justify [green]left[/], [yellow]center[/], [blue]right[/] or [red]full[/]. \n """
90 def comparison ( renderable1
: RenderableType
, renderable2
: RenderableType
) -> Table
:
91 table
= Table ( show_header
= False , pad_edge
= False , box
= None , expand
= True )
92 table
. add_column ( "1" , ratio
= 1 )
93 table
. add_column ( "2" , ratio
= 1 )
94 table
. add_row ( renderable1
, renderable2
)
98 "Asian \n language \n support" ,
99 ":flag_for_china: 该库支持中文,日文和韩文文本! \n :flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています \n :flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다" ,
103 "[bold magenta]Rich[/] supports a simple [i]bbcode[/i]-like [b]markup[/b] for [yellow]color[/], [underline]style[/], and emoji! "
104 ":+1: :apple: :ant: :bear: :baguette_bread: :bus: "
106 table
. add_row ( "Markup" , markup_example
)
108 example_table
= Table (
112 row_styles
=[ "none" , "dim" ],
115 example_table
. add_column ( "[green]Date" , style
= "green" , no_wrap
= True )
116 example_table
. add_column ( "[blue]Title" , style
= "blue" )
117 example_table
. add_column (
118 "[cyan]Production Budget" ,
123 example_table
. add_column (
124 "[magenta]Box Office" ,
129 example_table
. add_row (
131 "Star Wars: The Rise of Skywalker" ,
135 example_table
. add_row (
137 "[b]Solo[/]: A Star Wars Story" ,
141 example_table
. add_row (
143 "Star Wars Ep. VIII: The Last Jedi" ,
145 "[bold]$1,332,539,889[/bold]" ,
147 example_table
. add_row (
149 "Star Wars Ep. [b]I[/b]: [i]The phantom Menace" ,
154 table
. add_row ( "Tables" , example_table
)
157 def iter_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
158 """Iterate and generate a tuple with a flag for last value."""
159 iter_values = iter(values)
161 previous_value = next(iter_values)
162 except StopIteration:
164 for value in iter_values:
165 yield False, previous_value
166 previous_value = value
167 yield True, previous_value'''
174 "Vladimir Harkonnen" ,
178 "atomic" : ( False , True , None ),
181 "Syntax \n highlighting \n & \n pretty \n printing" ,
183 Syntax ( code
, "python3" , line_numbers
= True , indent_guides
= True ),
184 Pretty ( pretty_data
, indent_guides
= True ),
188 markdown_example
= """\
191 Supports much of the *markdown* __syntax__!
194 - Basic formatting: **bold**, *italic*, `code`
199 "Markdown" , comparison ( "[cyan]" + markdown_example
, Markdown ( markdown_example
))
204 """Progress bars, columns, styled logging handler, tracebacks, etc...""" ,
209 if __name__
== "__main__" : # pragma: no cover
215 test_card
= make_test_card ()
217 # Print once to warm cache
218 start
= process_time ()
219 console
. print ( test_card
)
220 pre_cache_taken
= round (( process_time () - start
) * 1000.0 , 1 )
222 console
. file = io
. StringIO ()
224 start
= process_time ()
225 console
. print ( test_card
)
226 taken
= round (( process_time () - start
) * 1000.0 , 1 )
228 c
= Console ( record
= True )
231 print ( f
"rendered in {pre_cache_taken} ms (cold cache)" )
232 print ( f
"rendered in {taken} ms (warm cache)" )
234 from pip
._ vendor
. rich
. panel
import Panel
238 sponsor_message
= Table
. grid ( padding
= 1 )
239 sponsor_message
. add_column ( style
= "green" , justify
= "right" )
240 sponsor_message
. add_column ( no_wrap
= True )
242 sponsor_message
. add_row (
244 "[u blue link=https://github.com/textualize]https://github.com/textualize" ,
246 sponsor_message
. add_row (
248 "[u blue link=https://twitter.com/willmcgugan]https://twitter.com/willmcgugan" ,
251 intro_message
= Text
. from_markup (
253 We hope you enjoy using Rich!
255 Rich is maintained with [red]:heart:[/] by [link=https://www.textualize.io]Textualize.io[/]
260 message
= Table
. grid ( padding
= 2 )
262 message
. add_column ( no_wrap
= True )
263 message
. add_row ( intro_message
, sponsor_message
)
270 title
= "[b red]Thanks for trying out Rich!" ,
271 border_style
= "bright_blue" ,