From c7c5abf7c8066a6a1e1a806e227b00ce16437cb6 Mon Sep 17 00:00:00 2001 From: rr- Date: Tue, 6 Nov 2018 14:59:03 +0100 Subject: [PATCH] ui: make palette configurable --- pqcli/ui/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pqcli/ui/__init__.py b/pqcli/ui/__init__.py index 16f04b0..69b1615 100644 --- a/pqcli/ui/__init__.py +++ b/pqcli/ui/__init__.py @@ -1,7 +1,10 @@ import argparse +import json import typing as T +from pathlib import Path import urwid +import xdg from pqcli import random from pqcli.mechanic import Player @@ -25,6 +28,21 @@ PALETTE: T.List[T.Tuple[str, ...]] = [ ("progressbar-done", "black", "light red"), ("progressbar-smooth", "light red", ""), ] +PALETTE_PATH = Path(xdg.XDG_CONFIG_HOME) / "pqcli" / "palette.json" + + +def load_palette() -> bool: + global PALETTE + if PALETTE_PATH.exists(): + PALETTE = json.loads(PALETTE_PATH.read_text()) + return True + return False + + +def save_palette() -> None: + global PALETTE + PALETTE_PATH.parent.mkdir(exist_ok=True, parents=True) + PALETTE_PATH.write_text(json.dumps(PALETTE, indent=4)) class ConfirmExitDialog(ConfirmDialog): @@ -48,6 +66,8 @@ def bind_commands() -> None: class Ui: def __init__(self, roster: Roster, args: argparse.Namespace) -> None: bind_commands() + if not load_palette(): + save_palette() # create a file for the user to edit self.roster = roster self.args = args