@@ -20,6 +20,9 @@ public partial class TerminalWindow : Window
20
20
public delegate void KillChildrenProc ( ) ;
21
21
private KillChildrenProc KillChildren ;
22
22
23
+ private List < string > _commandHistory = new List < string > ( ) ;
24
+ private int _commandHistoryIndex = - 1 ;
25
+
23
26
bool _ctrlDown = false ;
24
27
25
28
public TerminalWindow ( SendCommandProc sendCommand , KillChildrenProc killChildren )
@@ -56,10 +59,38 @@ private void InputTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
56
59
_ctrlDown = true ;
57
60
}
58
61
62
+ if ( e . Key . Equals ( Key . Up ) )
63
+ {
64
+ if ( _commandHistoryIndex + 1 < _commandHistory . Count )
65
+ {
66
+ _commandHistoryIndex ++ ;
67
+
68
+ Input_TextBox . Text = _commandHistory [ _commandHistoryIndex ] ;
69
+ Input_TextBox . CaretIndex = Input_TextBox . Text . Length ;
70
+ }
71
+ }
72
+
73
+ if ( e . Key . Equals ( Key . Down ) )
74
+ {
75
+ if ( _commandHistoryIndex - 1 >= 0 )
76
+ {
77
+ _commandHistoryIndex -- ;
78
+
79
+ Input_TextBox . Text = _commandHistory [ _commandHistoryIndex ] ;
80
+ Input_TextBox . CaretIndex = Input_TextBox . Text . Length ;
81
+ }
82
+ }
83
+
59
84
if ( e . Key . Equals ( Key . Return ) || e . Key . Equals ( Key . Enter ) )
60
85
{
86
+ // Add to command history
87
+ _commandHistory . Insert ( 0 , Input_TextBox . Text ) ;
88
+ _commandHistoryIndex = - 1 ;
89
+
90
+ // Send command
61
91
SendCommand ( Input_TextBox . Text ) ;
62
92
93
+ // Reset textbox content
63
94
Input_TextBox . Text = "" ;
64
95
}
65
96
}
0 commit comments