Exemplo n.º 1
0
        public async Task Loop()
        {
            while (true)
            {
                Display();
                Konsole.Write(PressNumberMessage, PromptColor);

                var k = Console.ReadKey();
                if (k.KeyChar == (char)27 || k.KeyChar.ToString().ToLower() == "q")
                {
                    break;
                }

                var itemNumber = HotcharToNumber(k.KeyChar) - 1;
                //var itemNumber = k.KeyChar.ToString().ToInt() - 1;

                if (itemNumber >= 0 && itemNumber < Items.Count)
                {
                    await Items[itemNumber].Action();
                    if (Items[itemNumber].ItemBreaksMenuLoop)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void WritePrompt()
        {
            if (string.IsNullOrEmpty(Prompt))
            {
                return;
            }
            var semicolon = false;
            var s         = Prompt;

            if (ShowRedEscapeInPrompt && EscapeBehavior == KonsoleStringEditEscapeBehavior.ReturnEmptystring)
            {
                if (s.EndsWith(":"))
                {
                    semicolon = true;
                    s         = s.Remove(s.Length - 1);
                }
            }
            Konsole.Write(s, PromptColor);
            if (ShowRedEscapeInPrompt && EscapeBehavior == KonsoleStringEditEscapeBehavior.ReturnEmptystring)
            {
                Konsole.Write(" [Esc]", ConsoleColor.Red);
            }
            if (semicolon)
            {
                Konsole.Write(":", PromptColor);
            }
            //Konsole.Write(" ");
        }
Exemplo n.º 3
0
        public static void Log(MessageLevel ml, string s, ConsoleColor kolor = ConsoleColor.Cyan, bool includeTime = true, bool silent = false)
        {
            if ((int)ml > (int)LogLevel)
            {
                return;
            }

            lock (WriteLock)
            {
                s += Environment.NewLine;
                var rightNow = "";
                if (includeTime)
                {
                    rightNow = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff") + " : ";
                }
                if (!silent)
                {
                    Konsole.Write(rightNow, ConsoleColor.White);
                    Konsole.Write(s, kolor);
                }

                if (!WriteToFile)
                {
                    return;
                }

                try
                {
                    var f  = new FileInfo(FilePath);
                    var sw = f.AppendText();
                    sw.Write(rightNow + ClearEscape(s));
                    sw.Close();
                }
                catch (Exception e)
                {
                    Konsole.WriteLine("ERROR writing to log file: " + Environment.NewLine + "Message: " + s + Environment.NewLine + "Error: " + e.Message, ConsoleColor.Red);
                }
            }
        }
Exemplo n.º 4
0
        public void Display()
        {
            Console.Clear();

            BeforeDisplay?.Invoke();

            //if (Items.Count > 9) Konsole.WriteLine("Too many menu items!!", ConsoleColor.Red);

            Konsole.WriteLine(_title, HotkeyColor);
            foreach (var unused in _title)
            {
                Konsole.Write("`", HotkeyColor);
            }
            Console.WriteLine();


            for (var i = 0; i < Items.Count; i++)
            {
                Konsole.Write(NumberToHotchar(i + 1) + " ", HotkeyColor);
                Konsole.WriteLine(Items[i].Title);
            }

            Console.WriteLine();
        }
Exemplo n.º 5
0
 private void Redraw()
 {
     Console.SetCursorPosition(_savedX, _savedY);
     Konsole.Write(Asterize(_value) + " ", ValueColor); //затираем лишнее
     Console.SetCursorPosition(_savedX + _pos, _savedY);
 }
Exemplo n.º 6
0
        public string ReadString()
        {
            _value = DefaultValue;
            _pos   = _value.Length;

            WritePrompt();



            _savedX = Console.CursorLeft;
            _savedY = Console.CursorTop;
            Konsole.Write(Asterize(_value), ValueColor);

            while (true)
            {
                var c = Console.ReadKey(true);
                switch (c.Key)
                {
                case ConsoleKey.Enter:
                {
                    if (LineFeed)
                    {
                        Console.WriteLine();
                    }
                    return(_value);
                }

                case ConsoleKey.Escape:

                    Console.Write("A");    //гасим escape последовательность, а то она норовит сожрать любой символ,выводимый после esc. Причем пробелом и знаками препинания не гасится

                    switch (EscapeBehavior)
                    {
                    case KonsoleStringEditEscapeBehavior.ReturnEmptystring:
                        if (LineFeed)
                        {
                            Console.WriteLine();
                        }
                        return("");

                    case KonsoleStringEditEscapeBehavior.ClearString:
                        Clear();
                        break;

                    case KonsoleStringEditEscapeBehavior.ReturnEsc:
                        if (LineFeed)
                        {
                            Console.WriteLine();
                        }
                        return("esc");

                    case KonsoleStringEditEscapeBehavior.Ignore:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    break;

                case ConsoleKey.LeftArrow:
                case ConsoleKey.UpArrow:
                    GoRight();
                    break;

                case ConsoleKey.RightArrow:
                case ConsoleKey.DownArrow:
                    GoLeft();
                    break;

                case ConsoleKey.Home:
                    GoHome();
                    break;

                case ConsoleKey.End:
                    GoEnd();
                    break;

                case ConsoleKey.Backspace:
                    Backspace();
                    break;

                case ConsoleKey.Delete:
                    Delete();
                    break;

                default:
                    Insert(c.KeyChar);
                    break;
                }
            }
        }