Commit 68ecc41eaac7ef23853b477c574f2025b4844661

Authored by Imanol-Mikel Barba Sabariego
1 parent e2923995

git-svn-id: svn://imanolbarba.net/PAD@13 c2ee353e-ed0d-4329-bf56-03aec153487f

readline/bin/pad/prac1/Command.class
No preview for this file type
readline/bin/pad/prac1/Console.class
No preview for this file type
readline/bin/pad/prac1/Line.class
No preview for this file type
readline/src/pad/prac1/Command.java
... ... @@ -9,6 +9,7 @@ public class Command
9 9 public static final int INSERT_CHAR = 0;
10 10 public static final int DELETE_CHAR = 1;
11 11 public static final int MOVE_CURSOR = 2;
  12 + public static final int NEWLINE = 3;
12 13  
13 14 private int type;
14 15 private int value;
... ...
readline/src/pad/prac1/Console.java
... ... @@ -99,6 +99,11 @@ public class Console implements Observer
99 99 Coordinate xy = new Coordinate(cmd.getValue()%numCols,currentRow);
100 100 moveCursorTo(xy);
101 101 break;
  102 +
  103 + case Command.NEWLINE:
  104 + System.out.print((char)EditableBufferedReader.LINE_FEED);
  105 + System.out.print((char)EditableBufferedReader.RETURN_KEY);
  106 + currentRow++;
102 107 }
103 108 }
104 109 }
... ...
readline/src/pad/prac1/EditableBufferedReader.java
... ... @@ -191,13 +191,4 @@ public class EditableBufferedReader extends BufferedReader
191 191 System.out.println("");
192 192 return line.toString();
193 193 }
194   -}
195   -
196   -
197   -/* TO-DO
198   - *
199   - * up/down keys (needs text to work)
200   - * pgup pgdown keys (goesto penultima linea visible)
201   - * cursor keys skip final \n on a line
202   - * careful if overwrite mode and final character is \n
203   - */
  194 +}
204 195 \ No newline at end of file
... ...
readline/src/pad/prac1/Line.java
... ... @@ -88,25 +88,30 @@ public class Line extends Observable
88 88 {
89 89 if(c == EditableBufferedReader.LINE_FEED)
90 90 {
91   - sendCommand(Command.INSERT_CHAR,EditableBufferedReader.RETURN_KEY);
  91 + sendCommand(Command.NEWLINE);
  92 + insertCharAt(c, cursorPosition-1);
  93 + cursorPosition++;
92 94 }
93   - switch(writeMode)
  95 + else
94 96 {
95   - case EditableBufferedReader.INSERT:
96   - sendCommand(Command.INSERT_CHAR,(int)c);
97   - insertCharAt(c, cursorPosition-1);
98   - cursorPosition++;
  97 + switch(writeMode)
  98 + {
  99 + case EditableBufferedReader.INSERT:
  100 + sendCommand(Command.INSERT_CHAR,(int)c);
  101 + insertCharAt(c, cursorPosition-1);
  102 + cursorPosition++;
  103 + break;
  104 +
  105 + case EditableBufferedReader.OVERWRITE:
  106 + if(cursorPosition != line.length()+1)
  107 + {
  108 + removeCharAt(cursorPosition-1);
  109 + }
  110 + sendCommand(Command.INSERT_CHAR,(int)c);
  111 + insertCharAt(c, cursorPosition-1);
  112 + cursorPosition++;
99 113 break;
100   -
101   - case EditableBufferedReader.OVERWRITE:
102   - if(cursorPosition != line.length()+1)
103   - {
104   - removeCharAt(cursorPosition-1);
105   - }
106   - sendCommand(Command.INSERT_CHAR,(int)c);
107   - insertCharAt(c, cursorPosition-1);
108   - cursorPosition++;
109   - break;
  114 + }
110 115 }
111 116 }
112 117  
... ...
readline/src/pad/prac1/MainClass.java
... ... @@ -12,5 +12,13 @@ public class MainClass
12 12 System.out.println("\nLine read: \n" + editable.readLine());
13 13 editable.close();
14 14 }
15   -
16 15 }
  16 +
  17 +/* TO-DO
  18 + * up/down keys
  19 + * pgup pgdown keys (goesto penultima linea visible)
  20 + * implement change of terminal dimensions
  21 + *
  22 + * TO-FIX
  23 + * Cursor keys, Home and end keys when new line, reset line length
  24 + */
17 25 \ No newline at end of file
... ...