FrmProxyCmd: Command history.

This commit is contained in:
2018-02-25 09:45:56 +01:00
parent 32e064fe10
commit 77e1c35e52

View File

@@ -14,6 +14,9 @@ namespace VAR.Toolbox.UI
private object _executionLock = new object();
private List<string> _cmdHistory = new List<string>();
private int _currentHistoryIndex = -1;
private void txtInput_KeyDown(object sender, KeyEventArgs e)
{
if (Monitor.IsEntered(_executionLock))
@@ -25,12 +28,15 @@ namespace VAR.Toolbox.UI
if (e.KeyCode == Keys.Return)
{
e.Handled = true;
string cmd = txtInput.Text.Replace("\n", "").Replace("\r", "");
string cmd = txtInput.Text.TrimStart().Replace("\n", "").Replace("\r", "");
if (string.IsNullOrEmpty(cmd) == false)
{
txtInput.Text = string.Empty;
Application.DoEvents();
txtInput.Text = string.Empty;
OutputLine(cmd);
new Thread(() => ExecuteCmd(cmd)).Start();
}
return;
}
if(e.KeyCode == Keys.Enter)
@@ -46,11 +52,38 @@ namespace VAR.Toolbox.UI
if (e.KeyCode == Keys.Up)
{
e.Handled = true;
if (_currentHistoryIndex == -1) { _currentHistoryIndex = _cmdHistory.Count; }
_currentHistoryIndex--;
if (_currentHistoryIndex < 0)
{
_currentHistoryIndex = 0;
}
if (_currentHistoryIndex>=0 && _currentHistoryIndex < _cmdHistory.Count)
{
txtInput.Text = _cmdHistory[_currentHistoryIndex];
txtInput.SelectionStart = txtInput.Text.Length;
txtInput.SelectionLength = 0;
}
return;
}
if (e.KeyCode == Keys.Down)
{
e.Handled = true;
if (_currentHistoryIndex > -1)
{
_currentHistoryIndex++;
if (_currentHistoryIndex >= _cmdHistory.Count)
{
txtInput.Text = string.Empty;
_currentHistoryIndex = -1;
}
else
{
txtInput.Text = _cmdHistory[_currentHistoryIndex];
txtInput.SelectionStart = txtInput.Text.Length;
txtInput.SelectionLength = 0;
}
}
return;
}
}
@@ -66,6 +99,8 @@ namespace VAR.Toolbox.UI
Monitor.Enter(_executionLock);
try
{
_cmdHistory.Add(cmdString);
_currentHistoryIndex = -1;
_proxyCmdExecutor.ExecuteCmd(cmdString, this);
}
catch (Exception ex)