Skip to content

Commit 4022734

Browse files
authored
Modifying again.
1 parent 8685450 commit 4022734

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

src/test/Line.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public void setContext(String c) {
2828

2929
public String toString(){
3030
return this.lNum+") "+ this.context;
31+
3132
}
33+
3234

3335
public void print(){
3436
System.out.println(this.toString());

src/test/Main.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package test;
22
import util.FileOps;
3+
import util.Item;
34
import util.List;
45
import 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

src/test/Session.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.io.*;
44

5-
public class Session
5+
public class Session
66
{
77
boolean raw;
88
int currentLine;
@@ -57,6 +57,13 @@ public void setF(File f) {
5757
this.f = f;
5858
}
5959

60-
60+
public void alterPrintMode()
61+
{
62+
if(raw)
63+
raw = false;
64+
else
65+
raw = true;
66+
67+
}
6168

6269
}

0 commit comments

Comments
 (0)