-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathPalette.v3
74 lines (67 loc) · 1.87 KB
/
Palette.v3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2023 Wizard Authors. All rights reserved.
// See LICENSE for details of Apache 2.0 license.
enum Color(defstr: string) {
NONE (""),
DEFAULT (TermColors.DEFAULT),
LINE (TermColors.BLUE),
FUNC (TermColors.WHITE),
ACTIVE (TermColors.WHITE),
INACTIVE (TermColors.GRAY1),
COUNT (TermColors.MAGENTA),
VERY_HIGH (TermColors.MAGENTA),
HIGH (TermColors.BRIGHTRED),
MEDIUM (TermColors.YELLOW),
LOW (TermColors.DEFAULT),
VERY_LOW (TermColors.LIGHTGRAY),
COVERED (TermColors.GREEN),
COVERED_BG (TermColors.BG_BRIGHTGREEN),
COVERED_FG (TermColors.BLACK),
UNREACHABLE (TermColors.GRAY1),
SOURCE (TermColors.BRIGHTCYAN),
TARGET (TermColors.YELLOW),
INSTR (TermColors.BRIGHTCYAN),
CONST (TermColors.GREEN),
REGISTER (TermColors.YELLOW),
DANGER (""),
WARN (""),
SUCCESS (TermColors.BRIGHTGREEN),
BINARY (TermColors.GRAY1),
TYPE (TermColors.YELLOW),
UNDERLINE (TermColors.UNDERLINE),
BOLD (TermColors.BOLD),
VALUE (TermColors.MAGENTA),
}
// Represents a color palette that maps abstract colors {Color} to escape codes.
class Palette {
def var on: bool = false;
private def colors = Array<string>.new(Color.VALUE.tag + 1);
new() { reset(false); }
def [c: Color] -> string { return colors[c.tag]; }
def [c: Color] = val: string { colors[c.tag] = val; }
def reset(on: bool) -> this {
if (on) for (c in Color) colors[c.tag] = c.defstr;
else for (i < colors.length) colors[i] = "";
this.on = on;
}
}
// Color palette for uniform coloring of Trace/Monitor outputs
component Palettes {
var on: bool = true;
private def defaultOn = Palette.new().reset(true);
private def defaultOff = Palette.new();
def spectrum = [
Color.VERY_HIGH,
Color.HIGH,
Color.MEDIUM,
Color.ACTIVE,
Color.LOW,
Color.VERY_LOW,
Color.UNREACHABLE
];
def get() -> Palette {
return if(on, defaultOn, defaultOff);
}
def reset(on: bool) {
this.on = on;
}
}