Commit f77c94da20190b8fce0e8f6db468058d8c8d9155
0 parents
initial commit
git-svn-id: svn://imanolbarba.net/PAD@1 c2ee353e-ed0d-4329-bf56-03aec153487f
Showing
7 changed files
with
131 additions
and
0 deletions
readline/.classpath
0 → 100644
1 | +++ a/readline/.classpath | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<classpath> | ||
3 | + <classpathentry kind="src" path="src"/> | ||
4 | + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
5 | + <classpathentry kind="output" path="bin"/> | ||
6 | +</classpath> |
readline/.project
0 → 100644
1 | +++ a/readline/.project | ||
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<projectDescription> | ||
3 | + <name>readline</name> | ||
4 | + <comment></comment> | ||
5 | + <projects> | ||
6 | + </projects> | ||
7 | + <buildSpec> | ||
8 | + <buildCommand> | ||
9 | + <name>org.eclipse.jdt.core.javabuilder</name> | ||
10 | + <arguments> | ||
11 | + </arguments> | ||
12 | + </buildCommand> | ||
13 | + </buildSpec> | ||
14 | + <natures> | ||
15 | + <nature>org.eclipse.jdt.core.javanature</nature> | ||
16 | + </natures> | ||
17 | +</projectDescription> |
readline/.settings/org.eclipse.jdt.core.prefs
0 → 100644
1 | +++ a/readline/.settings/org.eclipse.jdt.core.prefs | ||
1 | +eclipse.preferences.version=1 | ||
2 | +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
3 | +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
4 | +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
5 | +org.eclipse.jdt.core.compiler.compliance=1.6 | ||
6 | +org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
7 | +org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
8 | +org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
9 | +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
10 | +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
11 | +org.eclipse.jdt.core.compiler.source=1.6 |
readline/bin/pad/prac1/EditableBufferedReader.class
0 → 100644
No preview for this file type
readline/bin/pad/prac1/MainClass.class
0 → 100644
No preview for this file type
readline/src/pad/prac1/EditableBufferedReader.java
0 → 100644
1 | +++ a/readline/src/pad/prac1/EditableBufferedReader.java | ||
1 | +package pad.prac1; | ||
2 | +import java.io.*; | ||
3 | + | ||
4 | + | ||
5 | +public class EditableBufferedReader extends BufferedReader | ||
6 | +{ | ||
7 | + private String line = ""; | ||
8 | + private boolean returnKey = false; | ||
9 | + | ||
10 | + public EditableBufferedReader(Reader in) | ||
11 | + { | ||
12 | + super(in); | ||
13 | + } | ||
14 | + | ||
15 | + public EditableBufferedReader(Reader in, int sz) | ||
16 | + { | ||
17 | + super(in,sz); | ||
18 | + } | ||
19 | + | ||
20 | + private void setRaw() throws IOException, InterruptedException | ||
21 | + { | ||
22 | + String[] cmd = {"/bin/sh", "-c", "stty raw -echo </dev/tty"}; | ||
23 | + Runtime.getRuntime().exec(cmd).waitFor(); | ||
24 | + } | ||
25 | + | ||
26 | + private void unsetRaw() throws IOException, InterruptedException | ||
27 | + { | ||
28 | + String[] cmd = {"/bin/sh", "-c", "stty -raw echo </dev/tty"}; | ||
29 | + Runtime.getRuntime().exec(cmd).waitFor(); | ||
30 | + } | ||
31 | + | ||
32 | + public int read() throws IOException | ||
33 | + { | ||
34 | + return super.read(); | ||
35 | + } | ||
36 | + | ||
37 | + public String readLine() | ||
38 | + { | ||
39 | + try | ||
40 | + { | ||
41 | + setRaw(); | ||
42 | + } | ||
43 | + catch (Exception e) | ||
44 | + { | ||
45 | + System.out.println("Couldn't set terminal in raw mode"); | ||
46 | + return ""; | ||
47 | + } | ||
48 | + while(!returnKey) | ||
49 | + { | ||
50 | + try | ||
51 | + { | ||
52 | + int character = read(); | ||
53 | + switch(character) | ||
54 | + { | ||
55 | + case 0x0D: | ||
56 | + returnKey = true; | ||
57 | + break; | ||
58 | + default: | ||
59 | + line += (char)character; | ||
60 | + System.out.print((char)character); | ||
61 | + break; | ||
62 | + } | ||
63 | + } | ||
64 | + catch (IOException e) | ||
65 | + { | ||
66 | + System.out.println("Couldn't unset raw mode"); | ||
67 | + break; | ||
68 | + } | ||
69 | + } | ||
70 | + try | ||
71 | + { | ||
72 | + unsetRaw(); | ||
73 | + } | ||
74 | + catch (Exception e) | ||
75 | + { | ||
76 | + System.out.println("Couldn't unset raw mode"); | ||
77 | + return ""; | ||
78 | + } | ||
79 | + return line; | ||
80 | + } | ||
81 | +} |
readline/src/pad/prac1/MainClass.java
0 → 100644
1 | +++ a/readline/src/pad/prac1/MainClass.java | ||
1 | +package pad.prac1; | ||
2 | + | ||
3 | +import java.io.IOException; | ||
4 | +import java.io.InputStreamReader; | ||
5 | + | ||
6 | +public class MainClass | ||
7 | +{ | ||
8 | + public static void main(String[] argv) throws IOException | ||
9 | + { | ||
10 | + InputStreamReader input = new InputStreamReader(System.in); | ||
11 | + EditableBufferedReader editable = new EditableBufferedReader(input); | ||
12 | + System.out.println("\nLine read: " + editable.readLine()); | ||
13 | + editable.close(); | ||
14 | + } | ||
15 | + | ||
16 | +} |