announcement method
void
announcement({})
Implementation
void announcement(
{required String msg,
required String preformat,
required Color tl,
required Color tr,
required Color bl,
required Color br,
bool clip = false,
bool thick = false,
bool fringes = false}) {
List<String> message = msg.split("\n");
if (message.last.trim().isEmpty) {
message.removeLast();
}
message = message.map((String s) => s.trim()).toList();
int vpad = 1 + (thick ? 1 : 0);
int h = message.length + vpad * 2;
int w = message.fold(
0, (int prev, String element) => max(prev, element.length)) +
6;
w = w % 2 == 0 ? w + 1 : w;
double d1len = 1 / h;
double d1wid = 1 / w;
HsvColor hsvtl = tl.toHsvColor();
HsvColor hsvtr = tr.toHsvColor();
HsvColor hsvbl = bl.toHsvColor();
HsvColor hsvbr = br.toHsvColor();
String m = "";
print("");
for (int i = 0; i < h; i++) {
double ht = i * d1len;
StringBuffer sb = StringBuffer();
if (i > vpad - 1 && i < h - vpad) {
m = "${" " * ((w - message[i - vpad].length) ~/ 2)}${message[i - vpad]}";
}
for (int j = 0; j < w; j++) {
double wt = j * d1wid;
HsvColor left = HsvColor(
_lerp(hsvtl.h.toDouble(), hsvbl.h.toDouble(), ht),
_lerp(hsvtl.s.toDouble(), hsvbl.s.toDouble(), ht),
_lerp(hsvtl.v.toDouble(), hsvbl.v.toDouble(), ht),
);
HsvColor right = HsvColor(
_lerp(hsvtr.h.toDouble(), hsvbr.h.toDouble(), ht),
_lerp(hsvtr.s.toDouble(), hsvbr.s.toDouble(), ht),
_lerp(hsvtr.v.toDouble(), hsvbr.v.toDouble(), ht),
);
HexColor c = HsvColor(
_lerp(left.h.toDouble(), right.h.toDouble(), wt) % 360,
_lerp(left.s.toDouble(), right.s.toDouble(), wt),
_lerp(left.v.toDouble(), right.v.toDouble(), wt),
).toHexColor();
if (fringes && (i == 0 || i + 1 == h) && j % 2 == 0) {
c = Color.hex("#000000").toHexColor();
}
if (clip && ((i == 0 || i + 1 == h) && (j == 0 || j + 1 == w))) {
c = Color.hex("#000000").toHexColor();
}
sb.write(
"$_bgc(${c.toCssString()})${i > vpad - 1 && i < h - vpad && j < m.length ? m[j] == " " ? m[j] : "$preformat${m[j]}${j + 1 == m.length ? "&r" : ""}" : " "}");
}
print(sb.toString().chatColor);
}
print("");
}