Ejemplo n.º 1
0
        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()));
        }
Ejemplo n.º 2
0
		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;
		}
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public static void DrawV(Widget widget, int x, int y, int height, ColorPair color)
 {
     Curses.attron(color.Attribute);
     DrawV(widget, x, y, height);
     Curses.attron(ColorPair.From(-1, -1).Attribute);
 }
Ejemplo n.º 5
0
 public static void DrawH(Widget widget, int x, int y, int width, ColorPair color)
 {
     Curses.attron(color.Attribute);
     DrawH(widget, x, y, width);
     Curses.attron(ColorPair.From(-1, -1).Attribute);
 }
Ejemplo n.º 6
0
		public bool PairEquals(ColorPair cp)
		{
			return (Pair == cp.Pair) && ColorEquals(cp);
		}
Ejemplo n.º 7
0
		public bool ColorEquals(ColorPair cp)
		{
			return (cp.Foreground == Foreground) && (cp.Background == Background);
		}
Ejemplo n.º 8
0
 public bool PairEquals(ColorPair cp)
 {
     return((Pair == cp.Pair) && ColorEquals(cp));
 }
Ejemplo n.º 9
0
 public bool ColorEquals(ColorPair cp)
 {
     return((cp.Foreground == Foreground) && (cp.Background == Background));
 }
Ejemplo n.º 10
0
 public static void Finish()
 {
     Curses.attron(ColorPair.From(-1, -1).Attribute);
 }
Ejemplo n.º 11
0
        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);
        }