Ejemplo n.º 1
0
        public void Paginate(params string[] options)
        {
            this.clearConsole();

            int pointer = StartIndex;

            while (true)
            {
                this.setConsoleDefaultColors();
                this.clearConsole();

                for (int i = 0; i < (this.interfaceService.GetCanvasHeight() - options.Length) / 2; i++)
                {
                    this.writer.WriteLine(default(string));
                }

                for (int i = 0; i < options.Length; i++)
                {
                    this.setConsoleDefaultColors();

                    if (pointer == Array.IndexOf(options, options[i]))
                    {
                        this.setConsoleSelectedOptionColors();
                    }

                    this.writer.Write(new string(' ', (this.interfaceService.GetCanvasWidth() - options[i].Length) / 2) + options[i] + new string(' ', (this.interfaceService.GetCanvasWidth() - options[i].Length) / 2));
                    this.selected = options[pointer];
                }

                string pressedKey = this.reader.ReadKeyboardInput();

                if (pressedKey == TerminateString)
                {
                    break;
                }

                IMenuNavigationStrategy strategy = this.menuNavigationStrategyFactory.Create(pressedKey);

                if (strategy == null)
                {
                    continue; // If another key is pressed
                }

                this.menuNavigation.SetMoveStrategy(strategy);
                pointer = this.menuNavigation.Move(pointer);

                if (pointer > options.Length - 1)
                {
                    pointer = StartIndex;
                }
                else if (pointer < StartIndex)
                {
                    pointer = options.Length - 1;
                }

                this.setConsoleDefaultColors();
            }
        }
 public void SetMoveStrategy(IMenuNavigationStrategy moveStrategy)
 {
     this.menuNavigationStrategy = moveStrategy;
 }