Links: PYTHON - PROGRAMMING
Rel: python 3rd party packages
Ref: docs; github
- Markdown
- Layout
- Console
- markup link
- https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
- https://iterm2.com/ Preferences -> Profiles -> "Run coprocess: " echo nano \1
- this only works for actual path links, file:/// uri's still open to default app...
- https://github.com/willmcgugan/rich/blob/master/examples/fullscreen.py (panel system)
- BUG - Live view flickering on Windows
Tags: #public

rich text in the terminal


... no luck color in Markdown

from rich.text import Text
from rich.highlighter import Highlighter

rainbow = RainbowHighlighter()
menu_header = Text('MENU : ', style="bold magenta")
for index in range(len(menu_header)):
    menu_header.stylize(f"color({randint(16, 255)})", index, index + 1)

menu_header = rainbow(menu_header)

class RainbowHighlighter(Highlighter):
    # [https://rich.readthedocs.io/en/stable/highlighting.html](https://rich.readthedocs.io/en/stable/highlighting.html) {: id="[https://rich.readthedocs.io/en/stable/highlighting.html](https://rich.readthedocs.io/en/stable/highlighting.html)" }
    def highlight(self, text):
        for index in range(len(text)):
            ...

... no luck with Live

import time

import rich
from rich.console import Console
from rich.markdown import Markdown
from rich.layout import Layout
from rich.live import Live
from rich.prompt import Prompt
from rich.screen import Screen


@pass_nb
def _nb_console(nb=None):
    """ """

    layout = Layout()
    layout.split_row(
        Layout(name="left"),
        Layout(name="right"),
        )
    layout['left'].update(md)
    # layout['right'].visible = False {: id="layout['right'].visible-=-false" }

    # layout['upper'].visible = False {: id="layout['upper'].visible-=-false" }

    rmd = _get_rich_note(nb.get("PYTHON"), nb)

    # layout = Screen(rmd) {: id="layout-=-screen(rmd)" }

    layout['lower'].update(rmd)
    with Live(layout, screen=True) as live: # redirect_stdout=False, redirect_stderr=False, screen=True, transient=True {: id="redirect-stdout=false,-redirect-stderr=false,-screen=true,-transient=true" }

        # live.console.print(x) {: id="live.console.print(x)" }
        # layout['upper'].update() {: id="layout['upper'].update()" }

        # layout['upper'].update(live.console.input('prompt: ')) {: id="layout['upper'].update(live.console.input('prompt:-'))" }

        # name = Prompt.ask("Enter your name: ") {: id="name-=-prompt.ask("enter-your-name:-")" }
        # rich.print(name) {: id="rich.print(name)" }
        # layout.update(name) {: id="layout.update(name)" }

        while True:
            time.sleep(1)
            # live.console.print(rmd) {: id="live.console.print(rmd)" }
            x = live.console.input(rmd) # 'prompt: ' {: id="'prompt:-'" }
            # layout['lower'].update(x) {: id="layout['lower'].update(x)" }
            if ' --note=' in x:
                fn = x.split(' --note=')[1].strip('"')
                try:
                    rmd = _get_rich_note(nb.get(fn), nb)
                    live.console.print(rmd)


                    layout['lower'].update(rmd)
                except:
                    # layout['lower'].update(f'Failed to render note: {fn}') {: id="layout['lower'].update(f'failed-to-render-note:-{fn}')" }
                    break

pip install rich

>>> from rich import pretty
>>> pretty.install()
>>> ["Rich and pretty", True]
console.input("What is [i]your[/i] [bold red]name[/]? :smiley: ")

getting flickering if not using screen=True


Live

from rich.live import Live

with Live as live:
    while True:
        x = live.console.input('in: ')
        live.console.print(x)

from rich import print
from rich.console import Console
from rich.markdown import Markdown

md = (text="")
rich.inspect(md)
from rich.console import Console

console = Console()
# or {: id="or" }
console = Console(record=True)
# ->  {: id="->" }
# avail @  {: id="avail-@" }
# console.export_ ... {: id="console.export--..." }

print("Visit my [link=[https://www.willmcgugan.com](https://www.willmcgugan.com)]blog[/link]!")
console.print('google', style='blue link [https://google.com'](https://google.com'```)


https://rich.readthedocs.io/en/latest/markup.html?highlight=links