From 68ecc41eaac7ef23853b477c574f2025b4844661 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Tue, 22 Oct 2013 09:39:58 +0000 Subject: [PATCH] git-svn-id: svn://imanolbarba.net/PAD@13 c2ee353e-ed0d-4329-bf56-03aec153487f --- readline/bin/pad/prac1/Command.class | Bin 740 -> 0 bytes readline/bin/pad/prac1/Console.class | Bin 3070 -> 0 bytes readline/bin/pad/prac1/Line.class | Bin 2950 -> 0 bytes readline/src/pad/prac1/Command.java | 1 + readline/src/pad/prac1/Console.java | 5 +++++ readline/src/pad/prac1/EditableBufferedReader.java | 11 +---------- readline/src/pad/prac1/Line.java | 37 +++++++++++++++++++++---------------- readline/src/pad/prac1/MainClass.java | 10 +++++++++- 8 files changed, 37 insertions(+), 27 deletions(-) diff --git a/readline/bin/pad/prac1/Command.class b/readline/bin/pad/prac1/Command.class index 5c8b189..5e6a22b 100644 Binary files a/readline/bin/pad/prac1/Command.class and b/readline/bin/pad/prac1/Command.class differ diff --git a/readline/bin/pad/prac1/Console.class b/readline/bin/pad/prac1/Console.class index e77f5e1..b2070fc 100644 Binary files a/readline/bin/pad/prac1/Console.class and b/readline/bin/pad/prac1/Console.class differ diff --git a/readline/bin/pad/prac1/Line.class b/readline/bin/pad/prac1/Line.class index a1ab20f..4597b83 100644 Binary files a/readline/bin/pad/prac1/Line.class and b/readline/bin/pad/prac1/Line.class differ diff --git a/readline/src/pad/prac1/Command.java b/readline/src/pad/prac1/Command.java index 14a2320..173b684 100644 --- a/readline/src/pad/prac1/Command.java +++ b/readline/src/pad/prac1/Command.java @@ -9,6 +9,7 @@ public class Command public static final int INSERT_CHAR = 0; public static final int DELETE_CHAR = 1; public static final int MOVE_CURSOR = 2; + public static final int NEWLINE = 3; private int type; private int value; diff --git a/readline/src/pad/prac1/Console.java b/readline/src/pad/prac1/Console.java index db7f01a..462ea52 100644 --- a/readline/src/pad/prac1/Console.java +++ b/readline/src/pad/prac1/Console.java @@ -99,6 +99,11 @@ public class Console implements Observer Coordinate xy = new Coordinate(cmd.getValue()%numCols,currentRow); moveCursorTo(xy); break; + + case Command.NEWLINE: + System.out.print((char)EditableBufferedReader.LINE_FEED); + System.out.print((char)EditableBufferedReader.RETURN_KEY); + currentRow++; } } } diff --git a/readline/src/pad/prac1/EditableBufferedReader.java b/readline/src/pad/prac1/EditableBufferedReader.java index de24f9e..4bfb6e3 100644 --- a/readline/src/pad/prac1/EditableBufferedReader.java +++ b/readline/src/pad/prac1/EditableBufferedReader.java @@ -191,13 +191,4 @@ public class EditableBufferedReader extends BufferedReader System.out.println(""); return line.toString(); } -} - - -/* TO-DO - * - * up/down keys (needs text to work) - * pgup pgdown keys (goesto penultima linea visible) - * cursor keys skip final \n on a line - * careful if overwrite mode and final character is \n - */ +} \ No newline at end of file diff --git a/readline/src/pad/prac1/Line.java b/readline/src/pad/prac1/Line.java index 61ef5cd..70b7f31 100644 --- a/readline/src/pad/prac1/Line.java +++ b/readline/src/pad/prac1/Line.java @@ -88,25 +88,30 @@ public class Line extends Observable { if(c == EditableBufferedReader.LINE_FEED) { - sendCommand(Command.INSERT_CHAR,EditableBufferedReader.RETURN_KEY); + sendCommand(Command.NEWLINE); + insertCharAt(c, cursorPosition-1); + cursorPosition++; } - switch(writeMode) + else { - case EditableBufferedReader.INSERT: - sendCommand(Command.INSERT_CHAR,(int)c); - insertCharAt(c, cursorPosition-1); - cursorPosition++; + switch(writeMode) + { + case EditableBufferedReader.INSERT: + sendCommand(Command.INSERT_CHAR,(int)c); + insertCharAt(c, cursorPosition-1); + cursorPosition++; + break; + + case EditableBufferedReader.OVERWRITE: + if(cursorPosition != line.length()+1) + { + removeCharAt(cursorPosition-1); + } + sendCommand(Command.INSERT_CHAR,(int)c); + insertCharAt(c, cursorPosition-1); + cursorPosition++; break; - - case EditableBufferedReader.OVERWRITE: - if(cursorPosition != line.length()+1) - { - removeCharAt(cursorPosition-1); - } - sendCommand(Command.INSERT_CHAR,(int)c); - insertCharAt(c, cursorPosition-1); - cursorPosition++; - break; + } } } diff --git a/readline/src/pad/prac1/MainClass.java b/readline/src/pad/prac1/MainClass.java index 09ec8d6..cef2bb8 100644 --- a/readline/src/pad/prac1/MainClass.java +++ b/readline/src/pad/prac1/MainClass.java @@ -12,5 +12,13 @@ public class MainClass System.out.println("\nLine read: \n" + editable.readLine()); editable.close(); } - } + +/* TO-DO + * up/down keys + * pgup pgdown keys (goesto penultima linea visible) + * implement change of terminal dimensions + * + * TO-FIX + * Cursor keys, Home and end keys when new line, reset line length + */ \ No newline at end of file -- libgit2 0.22.2