
    AHj                        d dl mZ d dlZd dlmZ 	 d dlZdZd dlm	Z	 d dl
mZ d dlmZmZmZ d d	lmZ d d
lmZ d dlmZmZmZmZmZ dZdZdZdZdZ G d de      Z G d ded      Z  G d de      Z!y# e$ r dZY gw xY w)    )annotationsN)versionTF)work)ComposeResult)
HorizontalVerticalVerticalScroll)
PageScreen)reactive)CollapsibleDigitsFooterLabelMarkdownu   # What is Textual?

Snappy, keyboard-centric, applications that run in the terminal and [the web](https://github.com/Textualize/textual-web).

🐍 All you need is Python!

uP  ## Welcome keyboard warriors!

This is a Textual app. Here's what you need to know:

* **enter** `toggle this collapsible widget`
* **tab** `focus the next widget`
* **shift+tab** `focus the previous widget`
* **ctrl+p** `summon the command palette`


👇 Also see the footer below.

`Or… click away with the mouse (no judgement).`

u  The retro look is not just an aesthetic choice! Textual apps have some unique properties that make them preferable for many tasks.

## Textual interfaces are *snappy*
Even the most modern of web apps can leave the user waiting hundreds of milliseconds or more for a response.
Given their low graphical requirements, Textual interfaces can be far more responsive — no waiting required.

## Reward repeated use
Use the mouse to explore, but Textual apps are keyboard-centric and reward repeated use.
An experienced user can operate a Textual app far faster than their web / GUI counterparts.

## Command palette
A builtin command palette with fuzzy searching puts powerful commands at your fingertips.

**Try it:** Press **ctrl+p** now.

a  A modern Python API from the developer of [Rich](https://github.com/Textualize/rich).

```python
# Start building!
from textual.app import App, ComposeResult
from textual.widgets import Label

class MyApp(App):
    def compose(self) -> ComposeResult:
        yield Label("Hello, World!")

MyApp().run()
```

* Intuitive, batteries-included, API.
* Well documented: See the [tutorial](https://textual.textualize.io/tutorial/), [guide](https://textual.textualize.io/guide/app/), and [reference](https://textual.textualize.io/reference/). 
* Fully typed, with modern type annotations.
* Accessible to Python developers of all skill levels.

**Hint:** press **C** to view the code for this page.

## Built on Rich

With over 3.1 *billion* downloads, Rich is the most popular terminal library out there.
Textual builds on Rich to add interactivity, and is fully-compatible with Rich renderables.

## Re-usable widgets

Textual's widgets are self-contained and re-usable across projects.
Virtually all aspects of a widget's look and feel can be customized to your requirements.

## Builtin widgets

A large [library of builtin widgets](https://textual.textualize.io/widget_gallery/), and a growing ecosystem of third party widgets on PyPI
(this content is generated by the builtin [Markdown](https://textual.textualize.io/widget_gallery/#markdown) widget).
    
## Reactive variables

[Reactivity](https://textual.textualize.io/guide/reactivity/) using Python idioms, keeps your logic separate from display code.

## Async support

Built on asyncio, you can easily integrate async libraries while keeping your UI responsive.

## Concurrency

Textual's [Workers](https://textual.textualize.io/guide/workers/) provide a far-less error prone interface to
concurrency: both async and threads.

## Testing

With a comprehensive [testing framework](https://textual.textualize.io/guide/testing/), you can release reliable software, that can be maintained indefinitely.

## Docs

Textual has [amazing docs](https://textual.textualize.io/)!

a  Textual apps have extremely low system requirements, and will run on virtually any OS and hardware; locally or remotely via SSH.

There are a number of ways to deploy and share Textual apps.

## As a Python library

Textual apps may be pip installed, via tools such as `pipx` or `uvx`, and other package managers.

## As a web application

It takes two lines of code to [serve your Textual app](https://github.com/Textualize/textual-serve) as a web application.

## Managed web application

With [Textual web](https://github.com/Textualize/textual-web) you can serve multiple Textual apps on the web,
with zero configuration. Even behind a firewall.
c                  d    e Zd ZdZdZ edd      Z edd      Zed        Z	ddZ
dd	Zdd
Zy)	StarCountz,Widget to get and display GitHub star count.aX  
    StarCount {
        dock: top;
        height: 6;
        border-bottom: hkey $background;
        border-top: hkey $background;
        layout: horizontal;
        background: $boost;
        padding: 0 1;
        color: $text-warning;
        #stars { align: center top; }
        #forks { align: right top; }
        Label { text-style: bold; color: $foreground; }
        LoadingIndicator { background: transparent !important; }
        Digits { width: auto; margin-right: 1; }
        Label { margin-right: 1; }
        align: center top;
        &>Horizontal { max-width: 100;} 
    }
    ib  T)	recomposei  c                  K   t         s| j                  dd       yd| _        	 t        j                  d       d{    t        j                         4 d{   }|j                  d       d{   j                         }ddd      d{    d   | _	        |d	   | _
        d| _        y7 t7 Y7 B7 &# 1 d{  7  sw Y   6xY w# t        $ r | j                  d
dd       Y d| _        yw xY ww)z$Worker to get stars from GitHub API.zNInstall httpx to update stars from the GitHub API.

$ [b]pip install httpx[/b]zGitHub StarstitleNT   z/https://api.github.com/repos/textualize/textualstargazers_countforksz0Unable to update star count (maybe rate-limited)zGitHub starserror)r   severityF)HTTPX_AVAILABLEnotifyloadingasynciosleephttpxAsyncClientgetjsonstarsr   	Exception)selfclientrepository_jsons      I/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/demo/home.py	get_starszStarCount.get_stars   s      KKb$   	--"""((*  f **%VWW$&    ));<DJ(1DJ  #W     	KKB$   
 	s   "C9C B2C B4C B:3B64B:C B8C *C92C 4C 6B:8C :C CCC C6,	C95C66C9c              #  z  K   t               5  t        d      5  t        d       t        t	        d             d d d        t        d      5  t        d       | j
                  dz  dd	}t        |      j                  | j
                   d
       d d d        t        d      5  t        d       t        t        | j                              j                  | j                   d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   |xY w# 1 sw Y   *xY w# 1 sw Y   y xY ww)Nr   )idVersiontextualr%   u
   GitHub ★i  z.1fKz GitHub starsr   Forksz Forks)	r   r   r   r   r   r%   with_tooltipstrr   )r'   r%   s     r*   composezStarCount.compose   s    \ 
	RY' 1I&&WY/001 W% OL))::,S13Um00DJJ<}1MNNO W% RGn$S_-::djj\;PQQR
	R 
	R1 1O OR R
	R 
	Rsd   D;D/$DD/A
DD/0A
D#:D/	D;D	D/D 	D/#D,	(D//D84D;c                2    d| _         | j                          y )NzClick to refresh)tooltipr+   r'   s    r*   on_mountzStarCount.on_mount   s    )    c                $    | j                          y )N)r+   r7   s    r*   on_clickzStarCount.on_click   s    r9   Nreturnr   )r=   None)__name__
__module____qualname____doc__DEFAULT_CSSr   r%   r   r   r+   r4   r8   r;    r9   r*   r   r      sH    6K( Ud+ESD)E	 
2Rr9   r   c                      e Zd ZdZy)ContentzNon focusable vertical scroll.N)r?   r@   rA   rB   rD   r9   r*   rF   rF      s    (r9   rF   )	can_focusc                      e Zd ZdZddZy)
HomeScreena  
    HomeScreen {
        
        Content {
            align-horizontal: center;
            & > * {
                max-width: 100;
            }      
            margin: 0 1;          
            overflow-y: auto;
            height: 1fr;
            scrollbar-gutter: stable;
            MarkdownFence {
                height: auto;
                max-height: initial;
            }
            Collapsible {
                padding-right: 0;               
                &.-collapsed { padding-bottom: 1; }
            }
            Markdown {
                margin-right: 1;
                padding-right: 1;
                background: transparent;
            }
        }
    }
    c              #  .  K   t                t               5  t        t               t	        dd      5  t        t
               d d d        t	        d      5  t        t               d d d        t	        d      5  t        t               d d d        t	        d      5  t        t               d d d        d d d        t                y # 1 sw Y   xY w# 1 sw Y   vxY w# 1 sw Y   \xY w# 1 sw Y   BxY w# 1 sw Y   FxY ww)NWelcomeF)r   	collapsedzTextual Interfacesr   zTextual APIzDeploying Textual apps)
r   rF   r   WHAT_IS_TEXTUAL_MDr   
WELCOME_MDABOUT_MDAPI_MD	DEPLOY_MDr   r7   s    r*   r4   zHomeScreen.compose   s     kY 		*-..9> +z**+#78 )x(()=1 'v&&'#;< *y))*		* h+ +) )' '* *		* 		*s{   DD	C
D	C%0D	C1D	*C=<D	DC"	D	%C.	*D	1C:	6D	=D	D		DDNr<   )r?   r@   rA   rC   r4   rD   r9   r*   rI   rI      s    K:r9   rI   )"
__future__r   r   importlib.metadatar   r!   r   ImportErrorr/   r   textual.appr   textual.containersr   r   r	   textual.demo.pager
   textual.reactiver   textual.widgetsr   r   r   r   r   rM   rN   rO   rP   rQ   r   rF   rI   rD   r9   r*   <module>rZ      s    "  &O  % C C ( % H H 
"$:
x	(F FR)n )* *g  Os   A6 6B ?B 