예제 #1
0
 private void HideCompletions()
 {
     if (_completion != null)
     {
         _completion.Remove();
         _completion = null;
     }
 }
예제 #2
0
        private void ShowCompletions(String prefix, String[] completions)
        {
            var height  = Math.Min(completions.Length, Console.WindowHeight / 5);
            var width   = CompletionMinWidth;
            var current = Console.CursorTop;

            if (current >= Console.WindowHeight - height)
            {
                Console.SetCursorPosition(0, current + 1);

                for (var i = 0; i < height; i++)
                {
                    for (var c = Console.WindowWidth; c > 0; c--)
                    {
                        Console.Write(' ');
                    }
                }

                Console.SetCursorPosition(0, current);
                Render();
            }

            foreach (var s in completions)
            {
                width = Math.Max(prefix.Length + s.Length, width);
            }

            width = Math.Min(width, CompletionMaxWidth);

            if (_completion == null)
            {
                var left = Console.CursorLeft - prefix.Length;

                if (left + width + 1 >= Console.WindowWidth)
                {
                    left = Console.WindowWidth - width - 1;
                }

                _completion = new CompletionState(left, Console.CursorTop + 1, width, height)
                {
                    Prefix      = prefix,
                    Completions = completions,
                };
            }
            else
            {
                _completion.Prefix      = prefix;
                _completion.Completions = completions;
            }

            _completion.Show();
            Console.CursorLeft = 0;
        }