FrmProxyCmd: Command history.
This commit is contained in:
@@ -14,6 +14,9 @@ namespace VAR.Toolbox.UI
|
|||||||
|
|
||||||
private object _executionLock = new object();
|
private object _executionLock = new object();
|
||||||
|
|
||||||
|
private List<string> _cmdHistory = new List<string>();
|
||||||
|
private int _currentHistoryIndex = -1;
|
||||||
|
|
||||||
private void txtInput_KeyDown(object sender, KeyEventArgs e)
|
private void txtInput_KeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (Monitor.IsEntered(_executionLock))
|
if (Monitor.IsEntered(_executionLock))
|
||||||
@@ -25,12 +28,15 @@ namespace VAR.Toolbox.UI
|
|||||||
if (e.KeyCode == Keys.Return)
|
if (e.KeyCode == Keys.Return)
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
string cmd = txtInput.Text.Replace("\n", "").Replace("\r", "");
|
string cmd = txtInput.Text.TrimStart().Replace("\n", "").Replace("\r", "");
|
||||||
txtInput.Text = string.Empty;
|
if (string.IsNullOrEmpty(cmd) == false)
|
||||||
Application.DoEvents();
|
{
|
||||||
txtInput.Text = string.Empty;
|
txtInput.Text = string.Empty;
|
||||||
OutputLine(cmd);
|
Application.DoEvents();
|
||||||
new Thread(() => ExecuteCmd(cmd)).Start();
|
txtInput.Text = string.Empty;
|
||||||
|
OutputLine(cmd);
|
||||||
|
new Thread(() => ExecuteCmd(cmd)).Start();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(e.KeyCode == Keys.Enter)
|
if(e.KeyCode == Keys.Enter)
|
||||||
@@ -46,11 +52,38 @@ namespace VAR.Toolbox.UI
|
|||||||
if (e.KeyCode == Keys.Up)
|
if (e.KeyCode == Keys.Up)
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (e.KeyCode == Keys.Down)
|
if (e.KeyCode == Keys.Down)
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +99,8 @@ namespace VAR.Toolbox.UI
|
|||||||
Monitor.Enter(_executionLock);
|
Monitor.Enter(_executionLock);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_cmdHistory.Add(cmdString);
|
||||||
|
_currentHistoryIndex = -1;
|
||||||
_proxyCmdExecutor.ExecuteCmd(cmdString, this);
|
_proxyCmdExecutor.ExecuteCmd(cmdString, this);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user