public static ColorString Escape(string str, Func <char, ColorPair> exchange) { if (str == null) { return(null); } else if (str.Length == 0) { return(null); } char ch = str[0]; ColorPair current = exchange(ch); StringBuilder sb = new StringBuilder(current.ToString()); sb.Append(current); sb.Append(ch); for (int i = 1; i < str.Length; i++) { ch = str[i]; ColorPair next = exchange(ch); if (current != next) { sb.Append(next.ToString()); current = next; } sb.Append(ch); } return(new ColorString(sb.ToString())); }
public static ColorPair From(ushort foreground, ushort background) { short fg = (short)(foreground + 1); short bg = (short)(background + 1); var col = colors[fg, bg]; if (col == null) { col = new ColorPair(foreground, background); colors[fg, bg] = col; } return col; }
public static ColorPair From(ushort foreground, ushort background) { short fg = (short)(foreground + 1); short bg = (short)(background + 1); var col = colors[fg, bg]; if (col == null) { col = new ColorPair(foreground, background); colors[fg, bg] = col; } return(col); }
public static void Attribute(ColorPair colorPair, Action action) { Attribute(colorPair.Attribute, action); }
public bool ColorEquals(ColorPair cp) { return (cp.Foreground == Foreground) && (cp.Background == Background); }
public void Draw(Color foreground, Color background, string str, int x, int y, params int[] attributes) { Draw(ColorPair.From(foreground, background, attributes), str, x, y); }
public void Draw(Color foreground, string str, params int[] attributes) { Draw(ColorPair.From(foreground, attributes), str); }
public void Draw(ColorPair colorPair, string str) { Draw(colorPair.Attribute, str); }
public bool ColorEquals(ColorPair cp) { return((cp.Foreground == Foreground) && (cp.Background == Background)); }
public static CursesAttribute Attribute(System.Drawing.Color foreground, System.Drawing.Color background, params int[] attributes) { return(Attribute(ColorPair.From(foreground, background, attributes))); }
public static CursesAttribute Attribute(ColorPair colorPair) { return(Attribute(colorPair.Attribute)); }
public static int AttributeOff(ColorPair colorPair) { return(AttributeOff(colorPair.Attribute)); }
public static void Finish() { Curses.attron(ColorPair.From(-1, -1).Attribute); }
public void Fill(ColorPair colorPair, string str) { Fill(colorPair, str, ' '); }
public void Fill(ColorPair colorPair, string str, char ch, int x, int y) { Fill(colorPair, str, ch, x, y, Width - x, Height - y); }
public bool PairEquals(ColorPair cp) { return((Pair == cp.Pair) && ColorEquals(cp)); }
public void Draw(ColorPair colorPair, string str, int x, int y, int w, int h) { Draw(colorPair.Attribute, str, x, y, w, h); }
public static int From(int foreground, int background, params int[] attributes) { return(Accumulate(ColorPair.From(foreground, background).Attribute, attributes)); }
public void Draw(ColorPair colorPair, string str, int x, int y, int w, int h, out int endx, out int endy) { Draw(colorPair.Attribute, str, x, y, w, h, out endx, out endy); }
public static ColorPair From(Color foreground, Color background) { return(ColorPair.From(ConvertBasic(foreground), ConvertBasic(background))); }
public void Draw(Color foreground, string str, int x, int y, int w, int h, params int[] attributes) { Draw(ColorPair.From(foreground, attributes), str, x, y, w, h); }
public void Draw(Color foreground, Color background, string str, int x, int y, int w, int h, out int endx, out int endy, params int[] attributes) { Draw(ColorPair.From(foreground, background, attributes), str, x, y, w, h, out endx, out endy); }
public void Fill(ColorPair colorPair, string str, char ch) { Fill(colorPair, str, ch, 0, 0); }
public bool PairEquals(ColorPair cp) { return (Pair == cp.Pair) && ColorEquals(cp); }
public static int AttributeOff(ColorPair colorPair) { return AttributeOff(colorPair.Attribute); }
public void Fill(ColorPair colorPair, string str, char ch, int x, int y, int w, int h) { Fill(colorPair.Attribute, str, ch, x, y, w, h); }
public static CursesAttribute Attribute(ColorPair colorPair) { return Attribute(colorPair.Attribute); }
public void Fill(Color foreground, Color background, string str, char ch, int x, int y, int w, int h, params int[] attributes) { Fill(ColorPair.From(foreground, background, attributes), str, ch, x, y, w, h); }
public void Draw(ColorPair colorPair, string str, int x, int y) { Draw(colorPair.Attribute, str, x, y); }
public static int Each(string str, Func <char, bool> callback) { int n = 0; DrawStringMode mode = DrawStringMode.Normal; string fg = string.Empty; string bg = string.Empty; foreach (char c in str) { switch (mode) { case DrawStringMode.Normal: if (c == '\x0000') { mode = DrawStringMode.ForegroundColor; } else { if (!callback(c)) { return(n); } n++; } break; case DrawStringMode.ForegroundColor: if (char.IsNumber(c)) { fg += c; } else if (c == ',') { mode = DrawStringMode.Background; } else if (c == ' ') { ushort foreground = ushort.MaxValue; if (fg != string.Empty) { foreground = ushort.Parse(fg); } Curses.attron(ColorPair.From(foreground, ushort.MaxValue).Attribute); fg = string.Empty; mode = DrawStringMode.Normal; } else { throw new Exception("Malformed color string"); } break; case DrawStringMode.Background: if (char.IsNumber(c)) { bg += c; } else if (c == ' ') { Curses.attron(ColorPair.From(ushort.Parse(fg), ushort.Parse(bg)).Attribute); fg = string.Empty; bg = string.Empty; mode = DrawStringMode.Normal; } else { throw new Exception("Malformed color string"); } break; } } return(n); }