diff --git a/readline/bin/pad/prac1/Command.class b/readline/bin/pad/prac1/Command.class index 5c8b189..5e6a22b 100644 --- a/readline/bin/pad/prac1/Command.class +++ b/readline/bin/pad/prac1/Command.class diff --git a/readline/bin/pad/prac1/Console.class b/readline/bin/pad/prac1/Console.class index e77f5e1..b2070fc 100644 --- a/readline/bin/pad/prac1/Console.class +++ b/readline/bin/pad/prac1/Console.class diff --git a/readline/bin/pad/prac1/Line.class b/readline/bin/pad/prac1/Line.class index a1ab20f..4597b83 100644 --- a/readline/bin/pad/prac1/Line.class +++ b/readline/bin/pad/prac1/Line.class 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