"""Deterministic prompts from oh-my-posh and Starship, plus cell-offset copies of both triangle directions."""
import json, os, pathlib, subprocess, sys
root = pathlib.Path(__file__).resolve().parent
tools = pathlib.Path(os.environ.get('PROMPT_TOOLS', root))
env = {**os.environ, 'TERM':'xterm-256color', 'COLORTERM':'truecolor', 'STARSHIP_CONFIG':str(root/'starship.toml'), 'STARSHIP_SHELL':'zsh'}
def posh(config):
    return subprocess.check_output([str(tools/'oh-my-posh'),'print','primary','--config',str(root/config),'--shell','bash','--escape=false'],env=env).decode()
caps = posh('posh-caps.json')
full = posh('posh.json')
zsh = tools/'zsh-root/bin/zsh'
env['STARSHIP_BIN'] = str(tools/'starship')
star = subprocess.check_output([str(zsh),'-f','-c','PROMPT=$("$STARSHIP_BIN" prompt); print -Pn -- "$PROMPT"'],env=env).decode()
fg=lambda r,g,b:f'\033[38;2;{r};{g};{b}m'
bg=lambda r,g,b:f'\033[48;2;{r};{g};{b}m'
reset='\033[0m'
red=(243,139,168); blue=(137,180,250); lavender=(180,190,254)
rows=[
 'oh-my-posh: Ubuntu icon immediately before rounded cap',caps,
 'oh-my-posh: adjacent GitHub + branch icons; triangular joins',full,
 'Starship in zsh: Catppuccin Mocha',star,
 'Triangular joins at six cell offsets: U+E0B0 (right) and U+E0B2 (left)',
]
for offset in range(6):
    rows.append(' '*offset+bg(*red)+' '*8+bg(*blue)+fg(*red)+''+bg(*blue)+' '*8+reset+'    '+bg(*red)+fg(*blue)+''+bg(*blue)+' '*8+reset)
# Clear shell startup and command echo; hide the cursor while the static prompt is inspected.
sys.stdout.write('\033[3J\033[2J\033[H\033[?25l'+ '\r\n'.join(rows)+reset+'\r\n')
sys.stdout.flush()
try:
    input()
except (EOFError, KeyboardInterrupt):
    pass
