Beispiel #1
0
 public CommandBlock(LumenCommand command, String highlight) : base(command.Command, highlight, RowType.Command)
 {
     this.Command = command;
     if (_part != null)
     {
         _part.Style = Styles.CommandHighlight;
     }
 }
Beispiel #2
0
        private void ProcessCommand()
        {
            var          distances  = new List <LumenCommandDistance>();
            LumenCommand topCommand = null;

            if (_buffer.Length > 0)
            {
                foreach (var command in _registeredCommands)
                {
                    if (!command.Command.Contains(_buffer))
                    {
                        continue;
                    }
                    int distance = LevenshteinDistance(_buffer, command.Command);
                    distances.Add(new LumenCommandDistance()
                    {
                        Distance = distance, Command = command
                    });
                }
                distances = distances.OrderBy(o => o.Distance).ToList();
            }

            if (distances.Count > 0)
            {
                topCommand = distances.Take(1).SingleOrDefault().Command;
            }

            FormatPrompt(topCommand);

            List <LumenCommand> commands = distances.Select(o => o.Command).Take(10).ToList();

            _GridCommands.ClearRows();

            foreach (var command in commands)
            {
                var block = new CommandBlock(command, _buffer.ToString())
                {
                    Width = _BorderMain.Width
                };
                _GridCommands.AddRow(block);
                UpdateVirtualRows <CommandBlock>(_GridCommands);
            }
        }
Beispiel #3
0
        private void FormatPrompt(LumenCommand command)
        {
            var buffer = _buffer.ToString();
            var text   = String.Empty;
            var hint   = String.Empty;

            if (command != null)
            {
                text = command.Command;
                hint = command.ParameterHint;
            }

            _Command.Text = String.Empty;

            if (!text.StartsWith(buffer))
            {
                return;
            }

            _Command.Inlines.Add(new TextBlock()
            {
                Foreground = Brushes.Transparent,
                Text       = buffer
            });

            _Command.Inlines.Add(new TextBlock()
            {
                Style = (Style)FindResource("CommandPreview"),
                Text  = text.Substring(buffer.Length)
            });

            if (command != null && buffer.Length < command.Command.Length + 1)               // don't want to display the hin
            {
                _Command.Inlines.Add(new TextBlock()
                {
                    Style = (Style)FindResource("CommandHint"),
                    Text  = " " + hint
                });
            }
        }