# #
###############################################################################
-from . import util
+def _add(colour, amount):
+ """
+ Adds some value to colours
+ """
+ # Parse hex array
+ bytes = bytearray.fromhex(colour.lstrip("#"))
+
+ if not len(bytes) == 3:
+ raise ValueError("Invalid colour: %s" % colour)
+
+ ret = bytearray()
+
+ for byte in bytes:
+ byte = round(byte * amount)
+
+ # Ensure the result is within range
+ byte = min(byte, 255)
+ byte = max(byte, 0)
+
+ # Update the array
+ ret.append(byte)
+
+ return "#%s" % ret.hex()
+
+def lighten(colour, scale=0.1):
+ """
+ Takes a hexadecimal colour code
+ and brightens the colour.
+ """
+ return _add(colour, scale)
+
+def darken(colour, scale=0.1):
+ """
+ Takes a hexadecimal colour code
+ and darkens the colour.
+ """
+ return _add(colour, -scale)
+
+def transparency(colour, scale=0.1):
+ """
+ Adds transparency to the given colour code
+ """
+ return "%s%02X" % (colour, 0xff * scale)
BLACK = "#000000"
WHITE = "#FFFFFF"
COLOUR_CRITICAL = LIGHT_RED
COLOUR_ERROR = COLOUR_CRITICAL
COLOUR_WARN = LIGHT_YELLOW
-COLOUR_TEXT = util.lighten(BLACK, 0.87) # 87% grey
+COLOUR_TEXT = lighten(BLACK, 0.87) # 87% grey
PRIMARY = INDIGO
ACCENT = PINK
# TCP
"CLOSE" : BLACK,
- "CLOSE_WAIT" : util.lighten(BLACK, 0.25),
+ "CLOSE_WAIT" : lighten(BLACK, 0.25),
"ESTABLISHED" : LIGHT_GREEN,
"FIN_WAIT" : ORANGE,
"LAST_ACK" : PURPLE,
"SYN_SENT2" : AMBER,
# DCCP
- "CLOSEREQ" : util.lighten(BLACK, 0.5),
- "CLOSING" : util.lighten(BLACK, 0.25),
+ "CLOSEREQ" : lighten(BLACK, 0.5),
+ "CLOSING" : lighten(BLACK, 0.25),
"IGNORE" : WHITE,
"INVALID" : RED,
"OPEN" : LIGHT_GREEN,
import collecty._collecty
from . import base
-from .. import util
from ..colours import *
from ..i18n import _
"CDEF:l099=ploss,50,99,LIMIT,UN,UNKN,INF,IF",
"LINE2:latency6_avg%s:%s" % (
- util.transparency(COLOUR_IPV6, .5),
+ transparency(COLOUR_IPV6, .5),
_("Average latency (IPv6)"),
),
"LINE2:latency4_avg%s:%s\\r" % (
- util.transparency(COLOUR_IPV4, .5),
+ transparency(COLOUR_IPV4, .5),
_("Average latency (IPv4)"),
),
"COMMENT:%s" % _("Packet Loss"),
"AREA:l005%s:%s" % (
- util.transparency(colour_bg, .2), _("0-5%"),
+ transparency(colour_bg, .2), _("0-5%"),
),
"AREA:l010%s:%s" % (
- util.transparency(colour_bg, .4), _("5-10%"),
+ transparency(colour_bg, .4), _("5-10%"),
),
"AREA:l025%s:%s" % (
- util.transparency(colour_bg, .6), _("10-25%"),
+ transparency(colour_bg, .6), _("10-25%"),
),
"AREA:l050%s:%s" % (
- util.transparency(colour_bg, .8), _("25-50%"),
+ transparency(colour_bg, .8), _("25-50%"),
),
"AREA:l099%s:%s\\r" % (colour_bg, _("50-99%")),
"COMMENT: \\n", # empty line
"AREA:spacer4",
- "AREA:stddevarea4%s:STACK" % util.lighten(COLOUR_IPV4, STDDEV_OPACITY),
+ "AREA:stddevarea4%s:STACK" % lighten(COLOUR_IPV4, STDDEV_OPACITY),
"LINE2:latency4%s:%s" % (COLOUR_IPV4, _("Latency (IPv4)")),
"GPRINT:latency4_max:%12s\:" % _("Maximum") + " %6.2lf",
"GPRINT:latency4_min:%12s\:" % _("Minimum") + " %6.2lf",
"GPRINT:latency4_avg:%12s\:" % _("Average") + " %6.2lf\\n",
"AREA:spacer6",
- "AREA:stddevarea6%s:STACK" % util.lighten(COLOUR_IPV6, STDDEV_OPACITY),
+ "AREA:stddevarea6%s:STACK" % lighten(COLOUR_IPV6, STDDEV_OPACITY),
"LINE2:latency6%s:%s" % (COLOUR_IPV6, _("Latency (IPv6)")),
"GPRINT:latency6_max:%12s\:" % _("Maximum") + " %6.2lf",
"GPRINT:latency6_min:%12s\:" % _("Minimum") + " %6.2lf",
from .constants import *
-def __add_colour(colour, amount):
- colour = colour.strip("#")
-
- colour = (
- int(colour[0:2], 16),
- int(colour[2:4], 16),
- int(colour[4:6], 16),
- )
-
- # Scale the colour
- colour = (e + amount for e in colour)
- colour = (max(e, 0) for e in colour)
- colour = (min(e, 255) for e in colour)
-
- return "#%02x%02x%02x" % tuple(colour)
-
-def lighten(colour, scale=0.1):
- """
- Takes a hexadecimal colour code
- and brightens the colour.
- """
- return __add_colour(colour, 0xff * scale)
-
-def darken(colour, scale=0.1):
- """
- Takes a hexadecimal colour code
- and darkens the colour.
- """
- return __add_colour(colour, 0xff * -scale)
-
-def transparency(colour, scale=0.1):
- """
- Adds transparency to the given colour code
- """
- return "%s%02X" % (colour, 0xff * scale)
-
def get_network_interfaces():
"""
Returns all real network interfaces