Exemplo n.º 1
0
 public void GetHintsR()
 {
     Hints = GetTabbyThingy.GetHints(LeftInput).ToArray();
     if (Hints.Length == 1)
     {
         IncrHint();
     }
     UpdateVisibleHints();
 }
Exemplo n.º 2
0
        private void DoKeyStuff()
        {
            switch (_key.Key)
            {
            case ConsoleKey.End:
                GuiApp.Log(new FancyText($"UwU{new Random().Next()}", FancyColor.Aqua));
                break;

            case ConsoleKey.Tab:
                int rem;
                if (_hinting)
                {
                    _hintIndex++;
                    if (_hintIndex >= _hints.Count)
                    {
                        _hintIndex = 0;
                    }
                    rem = GetSkipAmount(-1, true);
                }
                else
                {
                    _hinting = true;
                    var hints = GetTabbyThingy.GetHints(_line);
                    _hints     = hints.Where(s => s.StartsWith(_currentArg)).ToList();
                    _hintIndex = 0;
                    rem        = _currentArg.Length;
                }

                if (_hints.Count == 0)
                {
                    return;
                }

                if (rem > 0)
                {
                    _line = _line.Remove(_cursor - rem, rem);
                }

                AddCursorPos(-rem);

                var hint = _hints[_hintIndex];
                _line = _line.Insert(_cursor, hint);
                AddCursorPos(hint.Length);

                SetCursorPos();
                return;

            case ConsoleKey.Enter:
                Console.Write("\n");
                _history.Insert(0, _line);
                GuiApp.LineRed(_line);
                Reset();
                break;

            case ConsoleKey.LeftArrow:
                AddCursorPos(_key.Modifiers.HasFlag(ConsoleModifiers.Control) ? -GetSkipAmount(-1, true) : -1);
                break;

            case ConsoleKey.RightArrow:
                AddCursorPos(_key.Modifiers.HasFlag(ConsoleModifiers.Control) ? GetSkipAmount(1, false) : 1);
                break;

            case ConsoleKey.UpArrow:
                History(1);
                break;

            case ConsoleKey.DownArrow:
                History(-1);
                break;

            case ConsoleKey.Backspace:
                if (_key.Modifiers.HasFlag(ConsoleModifiers.Control))
                {
                    var amount = GetSkipAmount(-1, true);
                    if (amount > 0)
                    {
                        _line = _line.Remove(_cursor - amount, amount);
                    }
                    AddCursorPos(-amount);
                }
                else
                {
                    if (_cursor > 0)
                    {
                        _line = _line.Remove(_cursor - 1, 1);
                    }
                    AddCursorPos(-1);
                }

                break;

            case ConsoleKey.Delete:
                if (_key.Modifiers.HasFlag(ConsoleModifiers.Control))
                {
                    var amount = GetSkipAmount(1, false);
                    if (amount > 0 && _cursor < _line.Length)
                    {
                        _line = _line.Remove(_cursor, amount);
                    }
                }
                else
                {
                    if (_cursor < _line.Length)
                    {
                        _line = _line.Remove(_cursor, 1);
                    }
                }

                break;

            default:
                HandleKey();
                break;
            }

            _hinting = false;
            SetCurrentArg();
            SetCursorPos();
        }