11package test ;
22import util .FileOps ;
3+ import util .Item ;
34import util .List ;
45import util .Node ;
56
@@ -17,7 +18,7 @@ public static void main(String[] args) throws IOException,FileNotFoundException
1718
1819 List list = new List ();
1920 Scanner in = new Scanner (System .in );
20- Session u = new User ();
21+ Session u = new Session ();
2122
2223
2324 //arguments check
@@ -48,7 +49,7 @@ public static void main(String[] args) throws IOException,FileNotFoundException
4849
4950 if (inputCheck (u .getCmd ()) != null )
5051 {
51- execCommand (u ,list );
52+ execCommand (u ,list , in );
5253 }
5354
5455
@@ -70,15 +71,22 @@ public static void main(String[] args) throws IOException,FileNotFoundException
7071
7172}
7273
73- private static void execCommand (User u , List lines )
74+ private static void execCommand (Session u , List lines , Scanner input )
7475 {
7576
7677
7778 Node curr ;
79+ Item n ;
7880 switch (u .cmd )
7981 {
8082
8183 case "a" :
84+ //add newline of text after the current line, new node after the current node
85+ System .out .println ("Type text for new line: " +u .getCurrentLine ());
86+ n = FileOps .formatInput (input .nextLine ().trim (),u .getCurrentLine ()+1 );
87+ lines .append (u .getCurrentLine ()+1 , n );
88+
89+
8290 break ;
8391 case "t" :
8492 break ;
@@ -89,6 +97,7 @@ private static void execCommand(User u, List lines)
8997 lines .print ();
9098 break ;
9199 case "n" :
100+ u .alterPrintMode ();
92101 break ;
93102 case "p" :
94103 //print current line of text, current node of the list.
@@ -106,26 +115,28 @@ private static void execCommand(User u, List lines)
106115
107116 break ;
108117 case "q" :
118+ //quit without saving modifications. Nothing to be done here.
109119 break ;
110120 case "w" :
111121 break ;
112122 case "x" :
113123 break ;
114124 case "^" :
115- //u.currentLine is already 0, nothing to do here.
125+ //go to the first line of text, first node of the list.
126+ u .setCurrentLine (0 );
116127 break ;
117128 case "+" :
118129 //go to next line of text, next node of the list.
119130 if (u .getCurrentLine () == lines .getLength ()-1 )
120131 {
121- System .out .println ("There is no further line, command will be ignored." );
132+ System .out .println ("There is no next line, command will be ignored." );
122133 break ;
123134 }
124135 u .setCurrentLine (u .getCurrentLine ()+1 );
125136 break ;
126137 case "=" :
127138 //print current line index, current node index.
128- System .out .println ("Line: " +(u .currentLine +1 ));
139+ System .out .println ("Line: " +(u .getCurrentLine () +1 ));
129140 break ;
130141 case "#" :
131142 //print lines and characters
0 commit comments