예제 #1
0
        private bool option_parse_color(string option_name, string val, IntPtr data)
        {
            switch (val)
            {
            case "auto": colored_output = Report.Colored.AUTO; break;

            case "never": colored_output = Report.Colored.NEVER; break;

            case null:
            case "always": colored_output = Report.Colored.ALWAYS; break;

            default: throw new Exception($"Invalid --color argument '{val}'");
            }
            return(true);
        }
예제 #2
0
파일: Report.cs 프로젝트: smx-smx/ValaSharp
        /// <summary>
        /// Set all colors by string
        ///
        /// {{{
        /// "error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01"
        /// }}}
        /// </summary>
        public bool set_colors(string str, Report.Colored colored_output = Report.Colored.AUTO)
        {
            try {
                if (val_regex == null)
                {
                    val_regex = new Regex("^\\s*[0-9]+(;[0-9]*)*\\s*$");
                }
            } catch (Exception) {
                assert_not_reached();
            }

            string error_color   = null;
            string warning_color = null;
            string note_color    = null;
            string caret_color   = null;
            string locus_color   = null;
            string quote_color   = null;

            string[] fragments = str.Split(':');
            foreach (string fragment in fragments)
            {
                string[] eq = fragment.Split(new char[] { '=' }, 2);
                if (eq.Length != 2)
                {
                    return(false);
                }

                if (!val_regex.IsMatch(eq[1]))
                {
                    return(false);
                }


                string checked_value = eq[1].Trim();
                switch (eq[0].Trim())
                {
                case "error":
                    error_color = checked_value;
                    break;

                case "warning":
                    warning_color = checked_value;
                    break;

                case "note":
                    note_color = checked_value;
                    break;

                case "caret":
                    caret_color = checked_value;
                    break;

                case "locus":
                    locus_color = checked_value;
                    break;

                case "quote":
                    quote_color = checked_value;
                    break;

                default:
                    return(false);
                }
            }

            if (colored_output == Report.Colored.ALWAYS || (
                    colored_output == Report.Colored.AUTO && is_atty(stderr.fileno())
                    ))
            {
                if (error_color != null)
                {
                    this.error_color_start = "\x1b[0" + error_color + "m";
                    this.error_color_end   = ANSI_COLOR_END;
                }

                if (warning_color != null)
                {
                    this.warning_color_start = "\x1b[0" + warning_color + "m";
                    this.warning_color_end   = ANSI_COLOR_END;
                }

                if (note_color != null)
                {
                    this.note_color_start = "\x1b[0" + note_color + "m";
                    this.note_color_end   = ANSI_COLOR_END;
                }

                if (caret_color != null)
                {
                    this.caret_color_start = "\x1b[0" + caret_color + "m";
                    this.caret_color_end   = ANSI_COLOR_END;
                }

                if (locus_color != null)
                {
                    this.locus_color_start = "\x1b[0" + locus_color + "m";
                    this.locus_color_end   = ANSI_COLOR_END;
                }

                if (quote_color != null)
                {
                    this.quote_color_start = "\x1b[0" + quote_color + "m";
                    this.quote_color_end   = ANSI_COLOR_END;
                }
            }
            return(true);
        }