Пример #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()));
        }
Пример #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;
		}
Пример #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);
        }
Пример #4
0
		public static void Attribute(ColorPair colorPair, Action action)
		{
			Attribute(colorPair.Attribute, action);
		}
Пример #5
0
		public bool ColorEquals(ColorPair cp)
		{
			return (cp.Foreground == Foreground) && (cp.Background == Background);
		}
Пример #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);
 }
Пример #7
0
 public void Draw(Color foreground, string str, params int[] attributes)
 {
     Draw(ColorPair.From(foreground, attributes), str);
 }
Пример #8
0
		public void Draw(ColorPair colorPair, string str)
		{
			Draw(colorPair.Attribute, str);
		}
Пример #9
0
 public bool ColorEquals(ColorPair cp)
 {
     return((cp.Foreground == Foreground) && (cp.Background == Background));
 }
Пример #10
0
 public static CursesAttribute Attribute(System.Drawing.Color foreground, System.Drawing.Color background, params int[] attributes)
 {
     return(Attribute(ColorPair.From(foreground, background, attributes)));
 }
Пример #11
0
 public static CursesAttribute Attribute(ColorPair colorPair)
 {
     return(Attribute(colorPair.Attribute));
 }
Пример #12
0
 public static void Attribute(ColorPair colorPair, Action action)
 {
     Attribute(colorPair.Attribute, action);
 }
Пример #13
0
 public static int AttributeOff(ColorPair colorPair)
 {
     return(AttributeOff(colorPair.Attribute));
 }
Пример #14
0
 public static void Finish()
 {
     Curses.attron(ColorPair.From(-1, -1).Attribute);
 }
Пример #15
0
		public void Fill(ColorPair colorPair, string str)
		{
			Fill(colorPair, str, ' ');
		}
Пример #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);
		}
Пример #17
0
 public bool PairEquals(ColorPair cp)
 {
     return((Pair == cp.Pair) && ColorEquals(cp));
 }
Пример #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);
		}
Пример #19
0
 public static int From(int foreground, int background, params int[] attributes)
 {
     return(Accumulate(ColorPair.From(foreground, background).Attribute, attributes));
 }
Пример #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);
 }
Пример #21
0
 public static ColorPair From(Color foreground, Color background)
 {
     return(ColorPair.From(ConvertBasic(foreground), ConvertBasic(background)));
 }
Пример #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);
 }
Пример #23
0
 public void Fill(ColorPair colorPair, string str)
 {
     Fill(colorPair, str, ' ');
 }
Пример #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);
 }
Пример #25
0
 public void Fill(ColorPair colorPair, string str, char ch)
 {
     Fill(colorPair, str, ch, 0, 0);
 }
Пример #26
0
		public bool PairEquals(ColorPair cp)
		{
			return (Pair == cp.Pair) && ColorEquals(cp);
		}
Пример #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);
 }
Пример #28
0
		public static int AttributeOff(ColorPair colorPair)
		{
			return AttributeOff(colorPair.Attribute);
		}
Пример #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);
 }
Пример #30
0
		public static CursesAttribute Attribute(ColorPair colorPair)
		{
			return Attribute(colorPair.Attribute);
		}
Пример #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);
 }
Пример #32
0
		public void Fill(ColorPair colorPair, string str, char ch)
		{
			Fill(colorPair, str, ch, 0, 0);
		}
Пример #33
0
 public void Draw(ColorPair colorPair, string str)
 {
     Draw(colorPair.Attribute, str);
 }
Пример #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);
		}
Пример #35
0
 public void Draw(ColorPair colorPair, string str, int x, int y)
 {
     Draw(colorPair.Attribute, str, x, y);
 }
Пример #36
0
		public void Draw(ColorPair colorPair, string str, int x, int y)
		{
			Draw(colorPair.Attribute, str, x, y);
		}
Пример #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);
 }
Пример #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);
		}
Пример #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);
        }