public void GetColorValue_CorrectOutput(AllowedColors expected, string fileContent, string preferenceName, AllowedColors defaultValue)
        {
            SetupPreferencesWithFileContent(fileContent, out UserFolderPreferences preferences);

            AllowedColors result = preferences.GetColorValue(preferenceName, defaultValue);

            Assert.Equal(expected, result);
        }
        public AllowedColors GetColorValue(string preference, AllowedColors defaultValue = AllowedColors.None)
        {
            if (!Preferences.TryGetValue(preference, out string preferenceValueString) || !Enum.TryParse(preferenceValueString, true, out AllowedColors result))
            {
                result = defaultValue;
            }

            return(result);
        }
示例#3
0
        public static AllowedColors GetColorPreference(this HttpState programState, string preference, AllowedColors defaultvalue = AllowedColors.None)
        {
            if (!programState.Preferences.TryGetValue(preference, out string preferenceValueString) || !Enum.TryParse(preferenceValueString, true, out AllowedColors result))
            {
                result = defaultvalue;
            }

            return(result);
        }
示例#4
0
        public AllowedColors GetColorValue(string preference, AllowedColors defaultValue = AllowedColors.None)
        {
            if (CurrentPreferences.TryGetValue(preference, out string value) && Enum.TryParse(value, true, out AllowedColors result))
            {
                return(result);
            }

            return(defaultValue);
        }
        public static string SetColor(this string text, AllowedColors color)
        {
            if (color.HasFlag(AllowedColors.Bold))
            {
                text  = text.Bold();
                color = color & ~AllowedColors.Bold;
            }

            switch (color)
            {
            case AllowedColors.Black:
                return(text.Black());

            case AllowedColors.Red:
                return(text.Red());

            case AllowedColors.Green:
                return(text.Green());

            case AllowedColors.Yellow:
                return(text.Yellow());

            case AllowedColors.Blue:
                return(text.Blue());

            case AllowedColors.Magenta:
                return(text.Magenta());

            case AllowedColors.Cyan:
                return(text.Cyan());

            case AllowedColors.White:
                return(text.White());

            default:
                return(text);
            }
        }
示例#6
0
        public static string SetColor(this string textToColor, AllowedColors color)
        {
            if (color.HasFlag(AllowedColors.Bold))
            {
                textToColor = textToColor.Bold();
                color       = color & ~AllowedColors.Bold;
            }

            switch (color)
            {
            case AllowedColors.Black:
            case AllowedColors.Red:
            case AllowedColors.Green:
            case AllowedColors.Yellow:
            case AllowedColors.Blue:
            case AllowedColors.Magenta:
            case AllowedColors.Cyan:
            case AllowedColors.White:
                return(SetColorInternal(textToColor, color));

            default:
                return(textToColor);
            }
        }
示例#7
0
        private static string SetColorInternal(string text, AllowedColors color)
        {
            int sgrParameter = (int)color;

            return($"{_ansiControlSequenceIntroducer}{sgrParameter}{_ansiSgrCode}{text}{_ansiSgrDefaultForegroundColor}");
        }
        public void SetColor_NoneOrInvalidColor_ReturnsText(string text, AllowedColors color, string expected)
        {
            var result = text.SetColor(color);

            Assert.Equal(expected, result);
        }
        public void SetColor_WithoutBold_ResponseIncludesJustColor(string text, AllowedColors color, string expected)
        {
            var result = text.SetColor(color);

            Assert.Equal(expected, result);
        }
示例#10
0
 public AllowedColors GetColorValue(string preference, AllowedColors defaultValue = default)
 {
     return(default);
示例#11
0
 public AllowedColors GetColorValue(string preference, AllowedColors defaultValue = AllowedColors.None)
 {
     return(defaultValue);
 }