Skip to content
Snippets Groups Projects
Commit cffe0710 authored by Florian Angerer's avatar Florian Angerer
Browse files

Fix: Method readLines of StdConnection always included a newline character.

parent ea6c99b0
No related branches found
No related tags found
No related merge requests found
......@@ -77,11 +77,7 @@ class JLineConsoleHandler implements ConsoleHandler {
public String readLine() {
try {
console.getTerminal().init();
String line = console.readLine();
if (line != null) {
line += "\n";
}
return line;
return console.readLine();
} catch (UserInterruptException e) {
throw e;
} catch (Exception ex) {
......
......@@ -243,6 +243,7 @@ public class RCommand {
if (additionalInput == null) {
throw new EOFException();
}
sb.append('\n');
sb.append(additionalInput);
source = RSource.fromTextInternal(sb.toString(), RSource.Internal.SHELL_INPUT);
// The only continuation in the while loop
......
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -64,7 +64,7 @@ class StringConsoleHandler implements ConsoleHandler {
output.print(prompt);
output.println(lines.get(currentLine));
}
return lines.get(currentLine++) + "\n";
return lines.get(currentLine++);
} else {
return null;
}
......
......@@ -51,9 +51,6 @@ public abstract class Readline extends RBuiltinNode {
String savedPrompt = consoleHandler.getPrompt();
consoleHandler.setPrompt(prompt.getDataAt(0));
String input = consoleHandler.readLine();
// The readLine method always appends the newline character, as opposed to the readline
// builtin. Therefore, the trailing newline must be cut off.
input = input.substring(0, input.length() - 1);
consoleHandler.setPrompt(savedPrompt);
return input;
}
......
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -154,6 +154,7 @@ public abstract class BrowserInteractNode extends RNode {
} catch (IncompleteSourceException e) {
// read another line of input
ch.setPrompt("+ ");
sb.append('\n');
sb.append(ch.readLine());
// The only continuation in the while loop
continue;
......
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -67,10 +67,8 @@ public interface ConsoleHandler {
void printError(String s);
/**
* Read a line of input, newline included in result. Returns null if {@link #isInteractive() ==
* false}. The rationale for including the readline is to ensure that the accumulated input,
* whether it be from a file or the console accurately reflects the the source. TODO worry about
* "\r\n"?
* Read a line of input, newline is <b>NOT</b> included in result. Returns null if
* {@link #isInteractive() == false}. TODO worry about "\r\n"?
*/
@TruffleBoundary
String readLine();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment