summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--ext/readline/extconf.rb2
-rw-r--r--ext/readline/readline.c60
-rw-r--r--test/readline/test_readline.rb17
4 files changed, 90 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index ff6a4bd..4d8f1bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Tue Feb 3 21:19:06 2009 TAKAO Kouji <kouji@takao7.net>
+
+ * ext/readline/extconf.rb: checked rl_set_screen_size and
+ rl_get_screen_size.
+
+ * ext/readline/readline.c (readline_s_set_screen_size): added
+ Readline.set_screen_size.
+
+ * ext/readline/readline.c (readline_s_get_screen_size): added
+ Readline.get_screen_size.
+
Tue Feb 3 21:07:19 2009 TAKAO Kouji <kouji@takao7.net>
* ext/readline/readline.c (readline_s_set_completion_proc): set
diff --git a/ext/readline/extconf.rb b/ext/readline/extconf.rb
index 1d74e29..6eb145f 100644
--- a/ext/readline/extconf.rb
+++ b/ext/readline/extconf.rb
@@ -63,6 +63,8 @@ have_readline_var("rl_editing_mode")
/mswin|bccwin|mingw/ !~ RUBY_PLATFORM && have_readline_var("rl_event_hook")
have_readline_func("rl_cleanup_after_signal")
have_readline_func("rl_clear_signals")
+have_readline_func("rl_set_screen_size")
+have_readline_func("rl_get_screen_size")
have_readline_func("rl_vi_editing_mode")
have_readline_func("rl_emacs_editing_mode")
have_readline_func("replace_history_entry")
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 9d1a9fa..a5dbe46 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -438,6 +438,62 @@ readline_attempted_completion_function(const char *text, int start, int end)
/*
* call-seq:
+ * Readline.set_screen_size(rows, columns) -> self
+ *
+ * Set terminal size to +rows+ and +columns+.
+ *
+ * See GNU Readline's rl_set_screen_size function.
+ *
+ * Raises NotImplementedError if the using readline library does not support.
+ *
+ * Raises SecurityError exception if $SAFE is 4.
+ */
+static VALUE
+readline_s_set_screen_size(VALUE self, VALUE rows, VALUE columns)
+{
+#ifdef HAVE_RL_SET_SCREEN_SIZE
+ rb_secure(4);
+ rl_set_screen_size(NUM2INT(rows), NUM2INT(columns));
+ return self;
+#else
+ rb_notimplement();
+ return Qnil; /* not reached */
+#endif /* HAVE_RL_SET_SCREEN_SIZE */
+}
+
+/*
+ * call-seq:
+ * Readline.get_screen_size -> [rows, columns]
+ *
+ * Returns the terminal's rows and columns.
+ *
+ * See GNU Readline's rl_get_screen_size function.
+ *
+ * Raises NotImplementedError if the using readline library does not support.
+ *
+ * Raises SecurityError exception if $SAFE is 4.
+ */
+static VALUE
+readline_s_get_screen_size(VALUE self)
+{
+#ifdef HAVE_RL_GET_SCREEN_SIZE
+ int rows, columns;
+ VALUE res;
+
+ rb_secure(4);
+ rl_get_screen_size(&rows, &columns);
+ res = rb_ary_new();
+ rb_ary_push(res, INT2NUM(rows));
+ rb_ary_push(res, INT2NUM(columns));
+ return res;
+#else
+ rb_notimplement();
+ return Qnil; /* not reached */
+#endif /* HAVE_RL_GET_SCREEN_SIZE */
+}
+
+/*
+ * call-seq:
* Readline.vi_editing_mode -> nil
*
* Specifies VI editing mode. See the manual of GNU Readline for
@@ -1200,6 +1256,10 @@ Init_readline()
readline_s_set_completion_case_fold, 1);
rb_define_singleton_method(mReadline, "completion_case_fold",
readline_s_get_completion_case_fold, 0);
+ rb_define_singleton_method(mReadline, "set_screen_size",
+ readline_s_set_screen_size, 2);
+ rb_define_singleton_method(mReadline, "get_screen_size",
+ readline_s_get_screen_size, 0);
rb_define_singleton_method(mReadline, "vi_editing_mode",
readline_s_vi_editing_mode, 0);
rb_define_singleton_method(mReadline, "vi_editing_mode?",
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index 2022953..846f80d 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -3,6 +3,8 @@ begin
=begin
class << Readline
[
+ "set_screen_size",
+ "get_screen_size",
"vi_editing_mode",
"emacs_editing_mode",
"completion_append_character=",
@@ -61,6 +63,8 @@ class TestReadline < Test::Unit::TestCase
["completer_quote_characters"],
["filename_quote_characters=", "\\"],
["filename_quote_characters"],
+ ["set_screen_size", 1, 1],
+ ["get_screen_size"],
]
method_args.each do |method_name, *args|
assert_raise(SecurityError, NotImplementedError,
@@ -140,6 +144,19 @@ class TestReadline < Test::Unit::TestCase
end
end
+ def test_get_screen_size
+ begin
+ res = Readline.get_screen_size
+ assert(res.is_a?(Array))
+ rows, columns = *res
+ assert(rows.is_a?(Integer))
+ assert(rows >= 0)
+ assert(columns.is_a?(Integer))
+ assert(columns >= 0)
+ rescue NotImplementedError
+ end
+ end
+
# vi_editing_mode
# emacs_editing_mode
def test_editing_mode