Esempio n. 1
0
        protected virtual void DrawProperties(params PropertySelectionItem[] propItems)
        {
            foreach (var propItem in propItems)
            {
                Console.SetCursorPosition(0, StartTopPosition + propItem.LinePosition - 1);
                int longestPropName = PropertyItems.Max(x => x.Name.Length);

                int propNameLength = propItem.Name.Length;
                int residue = longestPropName - propNameLength;
                InteractiveHelper.ClearCurrentConsoleLine();
                if (propItem.Selected)
                {
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.Green;
                    string text = propItem.Name + new string(' ', residue) + " > ";
                    propItem.NameWithPaddingLength = text.Length;
                    Console.Write(text);
                    Console.ResetColor();
                    Console.Write(propItem.Value + "\n");
                }
                else
                {
                    Console.ResetColor();
                    Console.Write(propItem.Name + new string(' ', residue) + " > " + propItem.Value + "\n");
                }
                Console.SetCursorPosition(propItem.NameWithPaddingLength + CurrentPositionInProperty, StartTopPosition + propItem.LinePosition - 1);
            }
        }
Esempio n. 2
0
        public virtual T GetUserSelection()
        {
            DrawSelections();

            bool selected = false;

            while (!selected)
            {
                ConsoleKeyInfo pressedKey       = InteractiveHelper.ReadKeyWithoutMoving();
                bool           selectionChanged = false;
                if (pressedKey.Key == ConsoleKey.Enter)
                {
                    selected = true;
                }
                if (pressedKey.Key == PrevItemKey)
                {
                    for (int i = 0; i < selectionItems.Length; i++)
                    {
                        if (i != 0)
                        {
                            if (selectionItems[i].Selected)
                            {
                                selectionItems[i].Selected     = false; // unselect right item
                                selectionItems[i - 1].Selected = true;  // select left item
                                selectionChanged = true;
                                break;
                            }
                        }
                    }
                }
                else if (pressedKey.Key == NextItemKey)
                {
                    for (int i = 0; i < selectionItems.Length; i++)
                    {
                        if (i != selectionItems.Length - 1)
                        {
                            if (selectionItems[i].Selected)
                            {
                                selectionItems[i].Selected     = false; // unselect left item
                                selectionItems[i + 1].Selected = true;  // select right item
                                selectionChanged = true;
                                break;
                            }
                        }
                    }
                }
                if (selectionChanged)
                {
                    DrawSelections();
                }
            }
            return(selectionItems.Where(x => x.Selected).FirstOrDefault());
        }
Esempio n. 3
0
        public T Change(T settings)
        {
            PropertyItems = GetPropertySelectionItems(settings);
            DrawProperties(PropertyItems);

            bool changingFinished = false;
            while (!changingFinished)
            {
                ConsoleKeyInfo pressedKey = InteractiveHelper.ReadKeyWithoutMoving();
                bool altPressed = (pressedKey.Modifiers & ConsoleModifiers.Alt) != 0;
                bool controlPressed = (pressedKey.Modifiers & ConsoleModifiers.Control) != 0;
                bool shiftPressed = (pressedKey.Modifiers & ConsoleModifiers.Shift) != 0;

                if (pressedKey.Key == ConsoleKey.Enter)
                {
                    changingFinished = true;
                }
                else if (pressedKey.Key == ConsoleKey.UpArrow)
                {
                    MoveUp();
                }
                else if (pressedKey.Key == ConsoleKey.DownArrow)
                {
                    MoveDown();
                }
                else if (pressedKey.Key == ConsoleKey.LeftArrow)
                {
                    MoveLeft(controlPressed);
                }
                else if (pressedKey.Key == ConsoleKey.RightArrow)
                {
                    MoveRight(controlPressed);
                }
                else if (pressedKey.Key == ConsoleKey.Z && controlPressed)
                {

                }
                else if (pressedKey.Key == ConsoleKey.Backspace)
                {
                    EraseChar();
                }
                else
                {
                    WriteChar(pressedKey.KeyChar);
                }
            }

            return Map(PropertyItems);
        }