-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colour.py
33 lines (28 loc) · 1.04 KB
/
Colour.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# coding: utf-8
from bearlibterminal import terminal as blt
from abc import ABCMeta, abstractmethod
from typing import NamedTuple
class Colour(metaclass=ABCMeta):
@abstractmethod
def blt_colour(self) -> int : pass
class ColourRGBA(Colour, NamedTuple('RGBA', [('r',int),('g',int),('b',int),('a',int)])):
def blt_colour(self) -> int:
return blt.color_from_argb(self.a, self.r, self.g, self.b)
ColourRGBA.__new__.__defaults__ = (255,) # mypy hates this
# When Python 3.6.1 arrives:
# * Remove __defaults__ assignment
# * Use class _ColourRGBA(NamedTuple)
# * Assign defaults in instance variable type hints
# * Use class ColourRGBA(NamedTuple, Colour), to avoid metaclass conflict
class ColourName(Colour):
name : str
def __init__(self, name : str) -> None:
self.name = name
def blt_colour(self) -> int:
return blt.color_from_name(self.name)
class ColourBLT(Colour):
code : int
def __init__(self, code : int) -> None:
self.code = code
def blt_colour(self) -> int:
return self.code