Exemple #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()));
        }
		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;
		}
Exemple #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);
        }
Exemple #4
0
		public static void Attribute(ColorPair colorPair, Action action)
		{
			Attribute(colorPair.Attribute, action);
		}
		public bool ColorEquals(ColorPair cp)
		{
			return (cp.Foreground == Foreground) && (cp.Background == Background);
		}
Exemple #6
0
 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);
 }
Exemple #7
0
 public void Draw(Color foreground, string str, params int[] attributes)
 {
     Draw(ColorPair.From(foreground, attributes), str);
 }
Exemple #8
0
		public void Draw(ColorPair colorPair, string str)
		{
			Draw(colorPair.Attribute, str);
		}
Exemple #9
0
 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 void Attribute(ColorPair colorPair, Action action)
 {
     Attribute(colorPair.Attribute, action);
 }
 public static int AttributeOff(ColorPair colorPair)
 {
     return(AttributeOff(colorPair.Attribute));
 }
Exemple #14
0
 public static void Finish()
 {
     Curses.attron(ColorPair.From(-1, -1).Attribute);
 }
Exemple #15
0
		public void Fill(ColorPair colorPair, string str)
		{
			Fill(colorPair, str, ' ');
		}
Exemple #16
0
		public void Fill(ColorPair colorPair, string str, char ch, int x, int y)
		{
			Fill(colorPair, str, ch, x, y, Width - x, Height - y);
		}
Exemple #17
0
 public bool PairEquals(ColorPair cp)
 {
     return((Pair == cp.Pair) && ColorEquals(cp));
 }
Exemple #18
0
		public void Draw(ColorPair colorPair, string str, int x, int y, int w, int h)
		{
			Draw(colorPair.Attribute, str, x, y, w, h);
		}
Exemple #19
0
 public static int From(int foreground, int background, params int[] attributes)
 {
     return(Accumulate(ColorPair.From(foreground, background).Attribute, attributes));
 }
Exemple #20
0
 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);
 }
Exemple #21
0
 public static ColorPair From(Color foreground, Color background)
 {
     return(ColorPair.From(ConvertBasic(foreground), ConvertBasic(background)));
 }
Exemple #22
0
 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);
 }
Exemple #23
0
 public void Fill(ColorPair colorPair, string str)
 {
     Fill(colorPair, str, ' ');
 }
Exemple #24
0
 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);
 }
Exemple #25
0
 public void Fill(ColorPair colorPair, string str, char ch)
 {
     Fill(colorPair, str, ch, 0, 0);
 }
Exemple #26
0
		public bool PairEquals(ColorPair cp)
		{
			return (Pair == cp.Pair) && ColorEquals(cp);
		}
Exemple #27
0
 public void Fill(ColorPair colorPair, string str, char ch, int x, int y)
 {
     Fill(colorPair, str, ch, x, y, Width - x, Height - y);
 }
Exemple #28
0
		public static int AttributeOff(ColorPair colorPair)
		{
			return AttributeOff(colorPair.Attribute);
		}
Exemple #29
0
 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);
 }
Exemple #30
0
		public static CursesAttribute Attribute(ColorPair colorPair)
		{
			return Attribute(colorPair.Attribute);
		}
Exemple #31
0
 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);
 }
Exemple #32
0
		public void Fill(ColorPair colorPair, string str, char ch)
		{
			Fill(colorPair, str, ch, 0, 0);
		}
Exemple #33
0
 public void Draw(ColorPair colorPair, string str)
 {
     Draw(colorPair.Attribute, str);
 }
Exemple #34
0
		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);
		}
Exemple #35
0
 public void Draw(ColorPair colorPair, string str, int x, int y)
 {
     Draw(colorPair.Attribute, str, x, y);
 }
Exemple #36
0
		public void Draw(ColorPair colorPair, string str, int x, int y)
		{
			Draw(colorPair.Attribute, str, x, y);
		}
Exemple #37
0
 public void Draw(ColorPair colorPair, string str, int x, int y, int w, int h)
 {
     Draw(colorPair.Attribute, str, x, y, w, h);
 }
Exemple #38
0
		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);
		}
Exemple #39
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);
        }