diff options
| author | Jacob McDonnell <jacob@simplelittledream.com> | 2022-01-13 18:39:09 -0500 |
|---|---|---|
| committer | Jacob McDonnell <jacob@simplelittledream.com> | 2022-01-13 18:39:09 -0500 |
| commit | 9927436cc355eb09675bcd6dd026a984c6ba9309 (patch) | |
| tree | 16321703329c3741b24946e6046443f1c721080f | |
| parent | f8961a182cb023d941e6a241ee70e316aa8b2617 (diff) | |
Added previous, next, and last line commands
| -rw-r--r-- | build/.DS_Store | bin | 6148 -> 6148 bytes | |||
| -rw-r--r-- | src/filebuffer.java | 7 | ||||
| -rw-r--r-- | src/jed.java | 18 | ||||
| -rw-r--r-- | tests/test.txt | 12 |
4 files changed, 32 insertions, 5 deletions
diff --git a/build/.DS_Store b/build/.DS_Store Binary files differindex ce4d425..45a34cb 100644 --- a/build/.DS_Store +++ b/build/.DS_Store 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 |
