|
8 | 8 | */
|
9 | 9 | package org.jline.terminal.impl;
|
10 | 10 |
|
| 11 | +import java.io.BufferedReader; |
11 | 12 | import java.io.ByteArrayInputStream;
|
12 | 13 | import java.io.ByteArrayOutputStream;
|
13 | 14 | import java.io.FilterInputStream;
|
14 | 15 | import java.io.IOException;
|
15 | 16 | import java.io.InputStream;
|
| 17 | +import java.io.InputStreamReader; |
16 | 18 | import java.io.PipedInputStream;
|
17 | 19 | import java.io.PipedOutputStream;
|
18 | 20 | import java.nio.charset.StandardCharsets;
|
@@ -51,6 +53,43 @@ public void tearDown() {
|
51 | 53 | System.clearProperty(TerminalBuilder.PROP_PROVIDERS);
|
52 | 54 | }
|
53 | 55 |
|
| 56 | + @Test |
| 57 | + void testEOL() throws IOException { |
| 58 | + { |
| 59 | + PipedInputStream in = new PipedInputStream(); |
| 60 | + PipedOutputStream outIn = new PipedOutputStream(in); |
| 61 | + BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); |
| 62 | + outIn.write("abc\rdef\nghi\r\njkl\r".getBytes()); |
| 63 | + |
| 64 | + assertEquals("abc", reader.readLine()); |
| 65 | + assertEquals("def", reader.readLine()); |
| 66 | + assertEquals("ghi", reader.readLine()); |
| 67 | + assertEquals("jkl", reader.readLine()); |
| 68 | + } |
| 69 | + { |
| 70 | + PipedInputStream in = new PipedInputStream(); |
| 71 | + PipedOutputStream outIn = new PipedOutputStream(in); |
| 72 | + ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 73 | + outIn.write("abc\rdef\nghi\r\njkl\n".getBytes()); |
| 74 | + |
| 75 | + Terminal terminal = TerminalBuilder.builder() |
| 76 | + .type("ansi") |
| 77 | + .streams(in, out) |
| 78 | + .paused(true) |
| 79 | + .build(); |
| 80 | + LineReader reader = LineReaderBuilder.builder().terminal(terminal).build(); |
| 81 | + Attributes attributes = terminal.getAttributes(); |
| 82 | + attributes.setInputFlag(InputFlag.INORMEOL, true); |
| 83 | + terminal.setAttributes(attributes); |
| 84 | + terminal.resume(); |
| 85 | + |
| 86 | + assertEquals("abc", reader.readLine()); |
| 87 | + assertEquals("def", reader.readLine()); |
| 88 | + assertEquals("ghi", reader.readLine()); |
| 89 | + assertEquals("jkl", reader.readLine()); |
| 90 | + } |
| 91 | + } |
| 92 | + |
54 | 93 | @Test
|
55 | 94 | public void testInput() throws IOException, InterruptedException {
|
56 | 95 | PipedInputStream in = new PipedInputStream();
|
|
0 commit comments