Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix Readline.get_screen_size

  • Loading branch information...
commit e05076140c126988f27f6fccf10d985b402320fb 1 parent 3d5705f
@ConradIrwin authored
Showing with 13 additions and 14 deletions.
  1. +13 −14 src/org/jruby/ext/Readline.java
View
27 src/org/jruby/ext/Readline.java
@@ -136,6 +136,14 @@ public static ConsoleHolder getHolder(Ruby runtime) {
return (ConsoleHolder) (runtime.getModule("Readline").dataGetStruct());
}
+ public static ConsoleHolder getHolderWithReadline(Ruby runtime) {
+ ConsoleHolder holder = getHolder(runtime);
+ if (holder.readline == null) {
+ initReadline(runtime, holder);
+ }
+ return holder;
+ }
+
public static void setCompletor(ConsoleHolder holder, Completer completor) {
if (holder.readline != null) {
holder.readline.removeCompleter(holder.currentCompletor);
@@ -157,10 +165,7 @@ public static IRubyObject s_readline(IRubyObject recv, IRubyObject prompt, IRuby
@JRubyMethod(name = "readline", module = true, visibility = PRIVATE)
public static IRubyObject s_readline(ThreadContext context, IRubyObject recv, IRubyObject prompt, IRubyObject add_to_hist) {
Ruby runtime = context.runtime;
- ConsoleHolder holder = getHolder(runtime);
- if (holder.readline == null) {
- initReadline(runtime, holder); // not overridden, let's go
- }
+ ConsoleHolder holder = getHolderWithReadline(runtime);
holder.readline.setExpandEvents(false);
IRubyObject line = runtime.getNil();
@@ -299,7 +304,7 @@ public static IRubyObject s_set_completion_case_fold(ThreadContext context, IRub
@JRubyMethod(name = "get_screen_size", module = true, visibility = PRIVATE, compat = RUBY1_9)
public static IRubyObject s_get_screen_size(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.runtime;
- ConsoleHolder holder = getHolder(runtime);
+ ConsoleHolder holder = getHolderWithReadline(runtime);
IRubyObject[] ary = new IRubyObject[2];
ary[0] = runtime.newFixnum(holder.readline.getTerminal().getHeight());
ary[1] = runtime.newFixnum(holder.readline.getTerminal().getWidth());
@@ -310,10 +315,7 @@ public static IRubyObject s_get_screen_size(ThreadContext context, IRubyObject r
@JRubyMethod(name = "line_buffer", module = true, visibility = PRIVATE, compat = RUBY1_9)
public static IRubyObject s_get_line_buffer(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.runtime;
- ConsoleHolder holder = getHolder(runtime);
- if (holder.readline == null) {
- initReadline(runtime, holder);
- }
+ ConsoleHolder holder = getHolderWithReadline(runtime);
CursorBuffer cb = holder.readline.getCursorBuffer();
return runtime.newString(cb.toString()).taint(context);
}
@@ -321,10 +323,7 @@ public static IRubyObject s_get_line_buffer(ThreadContext context, IRubyObject r
@JRubyMethod(name = "point", module = true, visibility = PRIVATE, compat = RUBY1_9)
public static IRubyObject s_get_point(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.runtime;
- ConsoleHolder holder = getHolder(runtime);
- if (holder.readline == null) {
- initReadline(runtime, holder);
- }
+ ConsoleHolder holder = getHolderWithReadline(runtime);
CursorBuffer cb = holder.readline.getCursorBuffer();
return runtime.newFixnum(cb.cursor);
}
@@ -332,7 +331,7 @@ public static IRubyObject s_get_point(ThreadContext context, IRubyObject recv) {
@JRubyMethod(name = "refresh_line", module = true, visibility = PRIVATE, compat = RUBY1_9)
public static IRubyObject s_refresh_line(ThreadContext context, IRubyObject recv) {
Ruby runtime = context.runtime;
- ConsoleHolder holder = getHolder(runtime);
+ ConsoleHolder holder = getHolderWithReadline(runtime);
try {
holder.readline.redrawLine(); // not quite the same as rl_refresh_line()
} catch (IOException ioe) {
Please sign in to comment.
Something went wrong with that request. Please try again.