From 9927436cc355eb09675bcd6dd026a984c6ba9309 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Thu, 13 Jan 2022 18:39:09 -0500 Subject: Added previous, next, and last line commands --- build/.DS_Store | Bin 6148 -> 6148 bytes src/filebuffer.java | 7 ++++++- src/jed.java | 18 +++++++++++++++++- tests/test.txt | 12 +++++++++--- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/build/.DS_Store b/build/.DS_Store index ce4d425..45a34cb 100644 Binary files a/build/.DS_Store and b/build/.DS_Store differ 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; diff --git a/tests/test.txt b/tests/test.txt index 58b1c66..57a9698 100644 --- a/tests/test.txt +++ b/tests/test.txt @@ -6,13 +6,19 @@ test no test more test motestre -test testpenistest test test petestpe +test testPENIStest test test petestpe ;al;skjfjfjfjjfjfjfjjfjfjfjfjf -penis +PENIS +PENIS +dick +balls +PENIS ;alsdkjf;sa -penis +PENIS sdfasdlfkjas;ldf asdfals;dfjas;ldkfj;a laskdfj;lasdfkj l;askdjf;alsdfja;sldfja;sldf al;skfdjdas +dick +balls -- cgit v1.2.3