@@ -20,6 +20,9 @@ public partial class TerminalWindow : Window
2020 public delegate void KillChildrenProc ( ) ;
2121 private KillChildrenProc KillChildren ;
2222
23+ private List < string > _commandHistory = new List < string > ( ) ;
24+ private int _commandHistoryIndex = - 1 ;
25+
2326 bool _ctrlDown = false ;
2427
2528 public TerminalWindow ( SendCommandProc sendCommand , KillChildrenProc killChildren )
@@ -56,10 +59,38 @@ private void InputTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
5659 _ctrlDown = true ;
5760 }
5861
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+
5984 if ( e . Key . Equals ( Key . Return ) || e . Key . Equals ( Key . Enter ) )
6085 {
86+ // Add to command history
87+ _commandHistory . Insert ( 0 , Input_TextBox . Text ) ;
88+ _commandHistoryIndex = - 1 ;
89+
90+ // Send command
6191 SendCommand ( Input_TextBox . Text ) ;
6292
93+ // Reset textbox content
6394 Input_TextBox . Text = "" ;
6495 }
6596 }
0 commit comments