Module mangdl.utils.style

Expand source code
import itertools
from functools import partial
from typing import List

import rich
from rich.align import Align
from rich.panel import Panel
from rich.table import Column, Table
from yachalk import chalk

from ..globals import console
from .settings import stg
from .utils import ddir, dnrp


class colour:
    pass

syml = stg(stg("colour_theme"), f"{dnrp(__file__)}/styles.yaml")
cstyle = syml['colours']

for k, v in cstyle.items():
    setattr(colour, k, v)

def stylize(st: List[str], t: str):
    op = f"[{st}]{t}[/{st}]"
    return op

SA = ddir(syml, "styles/all")
t1 = chalk.hex(cstyle.pop("t1"))
ldb = chalk.hex(cstyle.pop("fg1")).bg_hex(cstyle.pop("bg1"))
for k, v in cstyle.items():
    globals()[k] = partial(stylize, f"#{v} bold")
    globals()[f"ch_{k}"] = chalk.hex(v).bold

table = ddir(syml, "styles/table")

class ct:
    def panel(text: str):
        console.print(Align.center(Panel(text, **ddir(syml, "styles/panel"), **SA)))

    def table(cols: List[str], rows: List[List[str]]):
        stb = table
        box = getattr(rich.box, stb.pop("box"))

        new_cols = []
        for title, col in zip(cols, itertools.cycle(stb.pop("columns"))):
            attr = {i: f'#{getattr(colour, col[i])}' for i in ["header_style", "style"]}
            new_cols.append(Column(title, **attr, justify="center"))

        t = Table(*new_cols, **stb, **SA, box=box)
        for i in rows:
            t.add_row(*[str(i) for i in i])

        console.print(Align.center(t))

def pprint(t):
    console.print(Align.center(t))

Functions

def pprint(t)
Expand source code
def pprint(t):
    console.print(Align.center(t))
def stylize(st: List[str], t: str)
Expand source code
def stylize(st: List[str], t: str):
    op = f"[{st}]{t}[/{st}]"
    return op

Classes

class colour
Expand source code
class colour:
    pass

Class variables

var ac1
var bg1
var fg1
var h1
var h2
var h3
var h4
var t1
var t2
var t3
var t4
var warning
class ct
Expand source code
class ct:
    def panel(text: str):
        console.print(Align.center(Panel(text, **ddir(syml, "styles/panel"), **SA)))

    def table(cols: List[str], rows: List[List[str]]):
        stb = table
        box = getattr(rich.box, stb.pop("box"))

        new_cols = []
        for title, col in zip(cols, itertools.cycle(stb.pop("columns"))):
            attr = {i: f'#{getattr(colour, col[i])}' for i in ["header_style", "style"]}
            new_cols.append(Column(title, **attr, justify="center"))

        t = Table(*new_cols, **stb, **SA, box=box)
        for i in rows:
            t.add_row(*[str(i) for i in i])

        console.print(Align.center(t))

Methods

def panel(text: str)
Expand source code
def panel(text: str):
    console.print(Align.center(Panel(text, **ddir(syml, "styles/panel"), **SA)))
def table(cols: List[str], rows: List[List[str]])
Expand source code
def table(cols: List[str], rows: List[List[str]]):
    stb = table
    box = getattr(rich.box, stb.pop("box"))

    new_cols = []
    for title, col in zip(cols, itertools.cycle(stb.pop("columns"))):
        attr = {i: f'#{getattr(colour, col[i])}' for i in ["header_style", "style"]}
        new_cols.append(Column(title, **attr, justify="center"))

    t = Table(*new_cols, **stb, **SA, box=box)
    for i in rows:
        t.add_row(*[str(i) for i in i])

    console.print(Align.center(t))