@@ -48,12 +48,25 @@ public MainController()
4848 InitConsole ( ) ;
4949 }
5050
51- public string InputPrefix ( )
51+ public string GetInputPrefix ( )
5252 {
5353 string text = string . Concat ( Environment . UserName , "@" , currentDir , " ~ " ) ;
5454 return text ;
5555 }
5656
57+ public void SetInputPrefix ( )
58+ {
59+ inputBox . Text = GetInputPrefix ( ) ;
60+ LockInputPrefix ( ) ;
61+ }
62+
63+ public void LockInputPrefix ( )
64+ {
65+ inputBox . Select ( 0 , GetInputPrefix ( ) . Length ) ;
66+ inputBox . SelectionProtected = true ;
67+ inputBox . SelectionStart = inputBox . Text . Length ;
68+ }
69+
5770 public string GetFullPathFromName ( string path )
5871 {
5972 if ( ! currentDir . EndsWith ( "\\ " ) )
@@ -75,8 +88,7 @@ public string GetPathType(string path)
7588
7689 public void InitConsole ( )
7790 {
78- inputBox . Text = string . Concat ( Environment . UserName , "@" , currentDir , " ~ " ) ;
79- inputBox . SelectionStart = inputBox . Text . Length ;
91+ SetInputPrefix ( ) ;
8092 this . ActiveControl = inputBox ;
8193 }
8294
@@ -91,8 +103,7 @@ public void AddCommandToConsole(string[] tokens)
91103 outputBox . SelectionStart = outputBox . TextLength ;
92104 outputBox . ScrollToCaret ( ) ;
93105 UpdateHistoryFile ( command ) ; //Update history file
94- inputBox . Text = InputPrefix ( ) ; //Clear input area
95- inputBox . SelectionStart = inputBox . Text . Length ; //Set cursor to right position
106+ SetInputPrefix ( ) ;
96107 }
97108
98109 public void UpdateHistoryFile ( string command )
@@ -146,17 +157,22 @@ public string FormatBytes(long bytes)
146157 #region Commands
147158 public void ChangeDirectory ( string [ ] tokens )
148159 {
149-
150- string path = GetPathType ( tokens [ 1 ] ) ;
160+ string path = string . Empty ;
151161
152- if ( tokens . Length == 1 ) //Go to root
162+ if ( tokens . Length > 1 )
163+ path = GetPathType ( tokens [ 1 ] ) ;
164+ else if ( tokens . Length == 1 && tokens [ 0 ] == "cd" )
153165 {
154166 if ( Environment . OSVersion . Platform == PlatformID . Win32NT )
155167 currentDir = @"C:\" ;
156168 else if ( Environment . OSVersion . Platform == PlatformID . Unix )
157169 currentDir = @"~" ;
170+
171+ SetInputPrefix ( ) ;
172+ return ;
158173 }
159- else if ( tokens [ 1 ] == ".." ) //Go back one folder
174+
175+ if ( tokens [ 1 ] == ".." ) //Go back one folder
160176 {
161177 string dir = currentDir ;
162178 int index = dir . LastIndexOf ( @"\" ) ;
@@ -238,7 +254,7 @@ public void Rename(string[] tokens)
238254
239255 AddCommandToConsole ( tokens ) ;
240256 }
241- catch ( Exception e )
257+ catch ( Exception )
242258 {
243259 AddTextToConsole ( "Cannot find file path, did you enter the right name?" ) ;
244260 }
@@ -261,10 +277,7 @@ public void MakeFile(string[] tokens)
261277 {
262278 string path = string . Empty ;
263279 if ( tokens . Length == 2 )
264- {
265280 path = GetPathType ( tokens [ 1 ] ) ;
266-
267- }
268281 else
269282 {
270283 AddTextToConsole ( "Wrong ammount of arguments..." ) ;
@@ -336,7 +349,6 @@ public void RemoveFolder(string[] tokens)
336349 return ; //Hopefully never gets to this so don't display anything
337350 }
338351 }
339-
340352 }
341353 else
342354 AddTextToConsole ( "Folder doesn't exists" ) ;
@@ -365,7 +377,7 @@ public void CopyFile(string[] tokens)
365377 {
366378 if ( ! Directory . Exists ( output ) )
367379 {
368- //UNFINISHED, TO BE ADDED
380+ //TODO: COPY FOLDERS
369381 }
370382 else
371383 AddTextToConsole ( "Output directory already exists" ) ;
@@ -468,8 +480,7 @@ public void DisplayHelp()
468480
469481 AddTextToConsole ( sb . ToString ( ) ) ;
470482 AddCommandToConsole ( com ) ;
471- inputBox . Text = InputPrefix ( ) ;
472- inputBox . SelectionStart = inputBox . Text . Length ;
483+ SetInputPrefix ( ) ;
473484 }
474485
475486 public void Execute ( string [ ] tokens )
@@ -521,13 +532,13 @@ public void OpenFile(string[] tokens)
521532 public void ClearConsole ( )
522533 {
523534 outputBox . Text = string . Empty ;
524- inputBox . Text = InputPrefix ( ) ;
525- inputBox . SelectionStart = inputBox . Text . Length ;
535+ SetInputPrefix ( ) ;
526536 }
527537
528538 public void ClearHistory ( )
529539 {
530540 File . WriteAllText ( historyFilePath , string . Empty ) ;
541+ LoadHistoryFile ( ) ;
531542 }
532543
533544 public void DirectorySize ( string [ ] tokens )
@@ -792,16 +803,14 @@ public void RunCommand(string command, bool fromScript)
792803 coloring = new Coloring ( ) ;
793804 coloring . ColorForeground ( fcolor ) ;
794805
795- inputBox . Text = InputPrefix ( ) ;
796- inputBox . SelectionStart = inputBox . Text . Length ;
806+ SetInputPrefix ( ) ;
797807 break ;
798808 case true when cmds [ i ] . StartsWith ( "bcolor" ) :
799809 string bcolor = tokens [ 1 ] . ToUpper ( ) ;
800810 coloring = new Coloring ( ) ;
801- coloring . ColorForeground ( bcolor ) ;
811+ coloring . ColorBackground ( bcolor ) ;
802812
803- inputBox . Text = InputPrefix ( ) ;
804- inputBox . SelectionStart = inputBox . Text . Length ;
813+ SetInputPrefix ( ) ;
805814 break ;
806815 case true when cmds [ i ] . StartsWith ( "ssh" ) :
807816 AddCommandToConsole ( tokens ) ;
@@ -874,15 +883,15 @@ go out of bounds or change index by 2
874883 {
875884 if ( firstClick == false )
876885 -- historyIndex ;
877- inputBox . Text = string . Concat ( InputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
886+ inputBox . Text = string . Concat ( GetInputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
878887 inputBox . SelectionStart = inputBox . Text . Length ; //Set cursor to right position
879888
880889 if ( firstClick == true )
881890 firstClick = false ;
882891 }
883892 else if ( historyIndex == 0 ) //This else if must be here so that you can press down to clear the history if you are at the end
884893 {
885- inputBox . Text = string . Concat ( InputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
894+ inputBox . Text = string . Concat ( GetInputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
886895 inputBox . SelectionStart = inputBox . Text . Length ;
887896 }
888897 }
@@ -896,22 +905,21 @@ go out of bounds or change index by 2
896905 {
897906 if ( firstClick == false )
898907 ++ historyIndex ;
899- inputBox . Text = string . Concat ( InputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
908+ inputBox . Text = string . Concat ( GetInputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
900909 inputBox . SelectionStart = inputBox . Text . Length ; //Set cursor to right position
901910 if ( firstClick == true )
902911 firstClick = false ;
903912 }
904913 else if ( historyIndex == 0 && firstClick == false ) //This else if must be here so that you can press down to clear the history if you are at the end
905914 {
906915 ++ historyIndex ;
907- inputBox . Text = string . Concat ( InputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
916+ inputBox . Text = string . Concat ( GetInputPrefix ( ) , " " , cmdHistory [ historyIndex ] ) ;
908917 inputBox . SelectionStart = inputBox . Text . Length ;
909918 }
910919 else if ( historyIndex == cmdHistory . Length - 1 )
911920 {
912921 ++ historyIndex ;
913- inputBox . Text = InputPrefix ( ) ;
914- inputBox . SelectionStart = inputBox . Text . Length ; //Set cursor to right position
922+ SetInputPrefix ( ) ;
915923 }
916924 }
917925 #endregion
0 commit comments