Skip to content

Commit d7de58b

Browse files
committed
[fix] another try at restoring terminal settings
since the previous attempt (on runtime tear-down) does not always work towards getting updates back: jruby/jruby#5387 actually also resolves: jruby/jruby#3181
1 parent 03475e4 commit d7de58b

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/main/java/org/jruby/ext/readline/Readline.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,12 @@ private static IRubyObject readlineImpl(ThreadContext context, String prompt, fi
221221
holder.readline.setExpandEvents(false);
222222

223223
String line;
224-
while (true) {
225-
try {
226-
holder.readline.getTerminal().setEchoEnabled(false);
227-
line = holder.readline.readLine(prompt);
228-
break;
229-
} catch (IOException ioe) {
230-
throw runtime.newIOErrorFromException(ioe);
231-
} finally {
232-
holder.readline.getTerminal().setEchoEnabled(true);
233-
}
224+
try {
225+
line = readlineLoop(holder.readline, prompt);
226+
} catch (IOException ex) {
227+
throw runtime.newIOErrorFromException(ex);
228+
} catch (Exception ex) {
229+
Helpers.throwException(ex); return null; // likely init/restore failure
234230
}
235231

236232
if (line == null) return context.nil;
@@ -248,6 +244,17 @@ private static IRubyObject readlineImpl(ThreadContext context, String prompt, fi
248244
return RubyString.newString(runtime, bytes);
249245
}
250246

247+
private static String readlineLoop(final ConsoleReader reader, final String prompt) throws Exception {
248+
while (true) {
249+
try {
250+
reader.getTerminal().init();
251+
return reader.readLine(prompt);
252+
} finally {
253+
reader.getTerminal().restore();
254+
}
255+
}
256+
}
257+
251258
@JRubyMethod(name = "input=", module = true, visibility = PRIVATE)
252259
public static IRubyObject setInput(ThreadContext context, IRubyObject recv, IRubyObject input) {
253260
// FIXME: JRUBY-3604

0 commit comments

Comments
 (0)