コード例 #1
0
ファイル: Program.cs プロジェクト: TheDireMaster/fCraft
        static MenuState ShowKey()
        {
            ShowSeparator();
            var meta = currentKey.GetMetadata();

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Key {0} in section {1}", currentKey, currentSection);

            Console.Write("  Description: ");
            Console.ResetColor();
            string[] newlineSeparator = new[] { "\r\n" };
            string[] descriptionLines = meta.Description.Split(newlineSeparator, StringSplitOptions.RemoveEmptyEntries);
            Console.WriteLine(descriptionLines[0]);
            for (int i = 1; i < descriptionLines.Length; i++)
            {
                Console.WriteLine("    " + descriptionLines[i]);
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("  Type: ");
            Console.ResetColor();
            Console.WriteLine(meta.ValueType.Name);

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("  Default value: ");
            Console.ResetColor();
            Console.WriteLine(meta.DefaultValue);

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("  Current value: ");
            Console.ResetColor();
            Console.WriteLine(currentKey.GetString());

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("  New value: ");
            Console.ResetColor();

            while (true)
            {
                try {
                    currentKey.SetValue(Console.ReadLine());
                    break;
                } catch (FormatException ex) {
                    Console.WriteLine(ex.Message);
                }
            }

            return(MenuState.KeyList);
        }
コード例 #2
0
ファイル: ConfigCLI.cs プロジェクト: TheDireMaster/fCraft
        static MenuState ShowKey()
        {
            Refresh("Section {0} > Key {1}", currentSection, currentKey);
            Type valueType = currentKey.GetValueType();

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.Write("    Value Type: ");
            if (UseColor)
            {
                Console.ResetColor();
            }
            if (valueType.IsEnum)
            {
                Console.WriteLine("{0} (enumeration)", valueType.Name);
            }
            else if (valueType == typeof(int))
            {
                Console.WriteLine("Integer");
            }
            else if (valueType == typeof(bool))
            {
                Console.WriteLine("{0} (true/false)", valueType.Name);
            }
            else
            {
                Console.WriteLine(valueType.Name);
            }

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.WriteLine("   Description:");
            if (UseColor)
            {
                Console.ResetColor();
            }
            string[] newlineSeparator = new[] { "\r\n" };
            string[] descriptionLines = currentKey.GetDescription().Split(newlineSeparator,
                                                                          StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in descriptionLines)
            {
                Console.WriteLine("    " + line);
            }

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.Write(" Default value: ");
            PrintKeyValue(currentKey.GetDefault().ToString());

            if (UseColor)
            {
                Console.ForegroundColor = ConsoleColor.White;
            }
            Console.Write(" Current value: ");
            PrintKeyValue(currentKey.GetRawString());

            if (valueType.IsEnum)
            {
                if (UseColor)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                }
                Console.Write("       Choices: ");
                if (UseColor)
                {
                    Console.ResetColor();
                }
                Console.WriteLine(Enum.GetNames(valueType).JoinToString());
            }
            else if (currentKey.IsColor())
            {
                PrintColorList();
            }

            Console.WriteLine();
            TextMenu   menu           = new TextMenu();
            TextOption optionBack     = menu.AddOption("B", "Back to " + currentSection);
            TextOption optionChange   = menu.AddOption("C", "Change value");
            TextOption optionDefaults = menu.AddOption("D", "Use default");

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.KeyList);
            }
            else if (choice == optionChange)
            {
                while (true)
                {
                    try {
                        Console.Write("Enter new value for {0}: ", currentKey);
                        currentKey.SetValue(Console.ReadLine());
                        break;
                    } catch (FormatException ex) {
                        WriteWarning(ex.Message);
                    }
                }
            }
            else if (choice == optionDefaults)
            {
                currentKey.SetValue(currentKey.GetDefault());
            }
            return(MenuState.Key);
        }