@@ -6,6 +6,8 @@ package term
6
6
7
7
import (
8
8
"bytes"
9
+ "errors"
10
+ "fmt"
9
11
"io"
10
12
"os"
11
13
"runtime"
@@ -208,12 +210,24 @@ var keyPressTests = []struct {
208
210
line : "efgh" ,
209
211
throwAwayLines : 1 ,
210
212
},
213
+ {
214
+ // Newline in bracketed paste mode should still work.
215
+ in : "abc\x1b [200~d\n efg\x1b [201~h\r " ,
216
+ line : "efgh" ,
217
+ throwAwayLines : 1 ,
218
+ },
211
219
{
212
220
// Lines consisting entirely of pasted data should be indicated as such.
213
221
in : "\x1b [200~a\r " ,
214
222
line : "a" ,
215
223
err : ErrPasteIndicator ,
216
224
},
225
+ {
226
+ // Lines consisting entirely of pasted data should be indicated as such (\n paste).
227
+ in : "\x1b [200~a\n " ,
228
+ line : "a" ,
229
+ err : ErrPasteIndicator ,
230
+ },
217
231
{
218
232
// Ctrl-C terminates readline
219
233
in : "\003 " ,
@@ -296,6 +310,32 @@ func TestRender(t *testing.T) {
296
310
}
297
311
}
298
312
313
+ func TestCRLF (t * testing.T ) {
314
+ c := & MockTerminal {
315
+ toSend : []byte ("line1\r line2\r \n line3\n " ),
316
+ // bytesPerRead 0 means read all at once - CR+LF need to be in same read which is what terminals would do.
317
+ }
318
+
319
+ ss := NewTerminal (c , "> " )
320
+ for i := range 3 {
321
+ line , err := ss .ReadLine ()
322
+ if err != nil {
323
+ t .Fatalf ("failed to read line %d: %v" , i + 1 , err )
324
+ }
325
+ expected := fmt .Sprintf ("line%d" , i + 1 )
326
+ if line != expected {
327
+ t .Fatalf ("expected '%s', got '%s'" , expected , line )
328
+ }
329
+ }
330
+ line , err := ss .ReadLine ()
331
+ if ! errors .Is (err , io .EOF ) {
332
+ t .Fatalf ("expected EOF after 3 lines, got '%s' with error %v" , line , err )
333
+ }
334
+ if line != "" {
335
+ t .Fatalf ("expected empty line after EOF, got '%s'" , line )
336
+ }
337
+ }
338
+
299
339
func TestPasswordNotSaved (t * testing.T ) {
300
340
c := & MockTerminal {
301
341
toSend : []byte ("password\r \x1b [A\r " ),
0 commit comments