* ext/readline/readline.c (readline_s_set_point, Init_readline):

add Readline.point=(pos). Patched by naruse.  [ruby-dev:47535]
  [Feature #8675]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kouji 2013-08-06 12:52:22 +00:00
Родитель b4e9b0d19c
Коммит a78713ce45
3 изменённых файлов: 44 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Tue Aug 6 21:48:31 2013 Kouji Takao <kouji.takao@gmail.com>
* ext/readline/readline.c (readline_s_set_point, Init_readline):
add Readline.point=(pos). Patched by naruse. [ruby-dev:47535]
[Feature #8675]
Tue Aug 6 21:14:11 2013 Kouji Takao <kouji.takao@gmail.com>
* ext/readline/readline.c (Init_readline, readline_s_set_output)

Просмотреть файл

@ -896,8 +896,25 @@ readline_s_get_point(VALUE self)
{
return INT2NUM(rl_point);
}
/*
* call-seq:
* Readline.point = int
*
* Set the index of the current cursor position in
* +Readline.line_buffer+.
*
* See +Readline.point+.
*/
static VALUE
readline_s_set_point(VALUE self, VALUE pos)
{
rl_point = NUM2INT(pos);
return pos;
}
#else
#define readline_s_get_point rb_f_notimplement
#define readline_s_set_point rb_f_notimplement
#endif
static char **
@ -1849,6 +1866,8 @@ Init_readline()
readline_s_get_line_buffer, 0);
rb_define_singleton_method(mReadline, "point",
readline_s_get_point, 0);
rb_define_singleton_method(mReadline, "point=",
readline_s_set_point, 1);
rb_define_singleton_method(mReadline, "set_screen_size",
readline_s_set_screen_size, 2);
rb_define_singleton_method(mReadline, "get_screen_size",

Просмотреть файл

@ -17,6 +17,11 @@ class TestReadline < Test::Unit::TestCase
def teardown
ENV[INPUTRC] = @inputrc
Readline.instance_variable_set("@completion_proc", nil)
begin
Readline.delete_text
Readline.point = 0
rescue NotImplementedError
end
end
if !/EditLine/n.match(Readline::VERSION)
@ -311,9 +316,22 @@ class TestReadline < Test::Unit::TestCase
end
end
def test_point
assert_equal(0, Readline.point)
Readline.insert_text('12345')
assert_equal(5, Readline.point)
assert_equal(4, Readline.point=(4))
Readline.insert_text('abc')
assert_equal(7, Readline.point)
assert_equal('1234abc5', Readline.line_buffer)
rescue NotImplementedError
end if !/EditLine/n.match(Readline::VERSION)
def test_insert_text
str = "test_insert_text"
with_pipe {|r, w| w.write("\C-a\n")} # reset rl_point
assert_equal(0, Readline.point)
assert_equal(Readline, Readline.insert_text(str))
assert_equal(str, Readline.line_buffer)