summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/filebuffer.java7
-rw-r--r--src/jed.java18
2 files changed, 23 insertions, 2 deletions
diff --git a/src/filebuffer.java b/src/filebuffer.java
index 7ee27c2..ff6b225 100644
--- a/src/filebuffer.java
+++ b/src/filebuffer.java
@@ -19,7 +19,6 @@ public class filebuffer {
readFile();
}
}
-
/* getFileSize: gets the size of the buffer arraylist */
public int getFileSize() {
return buffer.size();
@@ -33,6 +32,12 @@ public class filebuffer {
/* changeCurrentLine: changes the current line value */
public void changeCurrentLine(int n) {
currentLine = n;
+ printLine(currentLine);
+ }
+
+ /* printLine: prints the line */
+ private void printLine(int n) {
+ System.out.printf("%d %s\n", n + 1, getLine(n));
}
/* getLine: returns the selected line as a string */
diff --git a/src/jed.java b/src/jed.java
index 3aae502..3f2056c 100644
--- a/src/jed.java
+++ b/src/jed.java
@@ -18,7 +18,9 @@ public class jed {
file = new filebuffer(fileName, hasName);
+ /* Main command prompt */
while (true) {
+ System.out.print("> ");
String line = kbIn.nextLine();
int err = parser(line);
if (err == 1)
@@ -32,7 +34,6 @@ public class jed {
int err = 0;
if (isNum(cmd)) {
file.changeCurrentLine(Integer.parseInt(cmd) - 1);
- System.out.printf("%d %s\n", file.getCurrentLine() + 1, file.getLine(file.getCurrentLine()));
} else {
char c = cmd.charAt(0);
switch (c) {
@@ -89,6 +90,21 @@ public class jed {
case 'h': // help command
help();
break;
+ case '^': case '-': // previous line command
+ if ((file.getCurrentLine() - 1) > -1)
+ file.changeCurrentLine((file.getCurrentLine() - 1));
+ else
+ System.out.println("?");
+ break;
+ case '+': // Next line command
+ if ((file.getCurrentLine() + 1) <= file.getFileSize())
+ file.changeCurrentLine((file.getCurrentLine() + 1));
+ else
+ System.out.println("?");
+ break;
+ case '$': // Last line command
+ file.changeCurrentLine(file.getFileSize() - 1);
+ break;
default:
System.out.println("?");
break;