Ejemplo n.º 1
0
        public (string c, ConsoleColor cc) GetChoiceType(QueryLine choice)
        {
            var initialForegroundColor = Console.ForegroundColor;

            switch (choice.ChoiceType)
            {
            case QueryLineType.Choice:
                return("> ", ConsoleColor.Green);

            case QueryLineType.Back:
                return("< ", ConsoleColor.Red);

            case QueryLineType.Exit:
                return("< ", ConsoleColor.Red);

            case QueryLineType.Input:
                return("* ", ConsoleColor.Green);

            case QueryLineType.Title:
                return("  ", initialForegroundColor);

            case QueryLineType.PlainText:
            case QueryLineType.None:
            default:
                return("", initialForegroundColor);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write a query line, and select it, if necessary
        /// </summary>
        public void WriteQueryLine(QueryLine queryLine, bool isSelected, int?topPosition = null)
        {
            var initialForegroundColor = Console.ForegroundColor;

            Console.CursorLeft = 0;

            // if topPosition is set, we are in a "replacing" line mode
            if (topPosition.HasValue)
            {
                Console.CursorTop = topPosition.Value;
            }

            // store actual line top position
            queryLine.TopPosition = Console.CursorTop;

            // Delete current line if any characters are already there
            ConsoleExt.DeleteLine(replaceCursor: true);


            // getting line type
            var(choiceC, choiceCC) = this.GetChoiceType(queryLine);

            // for plain text let cursor visible to navigate, more easily
            // Console.CursorVisible = choice.ChoiceType == MenuChoiceType.PlainText;

            Console.ForegroundColor = choiceCC;
            Console.Write(choiceC);

            Console.ForegroundColor = isSelected ? choiceCC : initialForegroundColor;
            Console.Write(queryLine.Text);

            // color hotkey if supported and not selected
            if (queryLine.HotkeyIndex >= 0 && !isSelected)
            {
                Console.ForegroundColor = choiceCC;
                var letter = queryLine.Text.Substring(queryLine.HotkeyIndex, 1);
                Console.CursorLeft = queryLine.HotkeyIndex + 2; // +2 for first letters "> "
                Console.Write(letter);
            }

            Console.ForegroundColor = initialForegroundColor;
            Console.CursorLeft      = 0;
        }