mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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:
parent
b4e9b0d19c
commit
a78713ce45
3 changed files with 44 additions and 1 deletions
|
@ -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>
|
Tue Aug 6 21:14:11 2013 Kouji Takao <kouji.takao@gmail.com>
|
||||||
|
|
||||||
* ext/readline/readline.c (Init_readline, readline_s_set_output)
|
* ext/readline/readline.c (Init_readline, readline_s_set_output)
|
||||||
|
|
|
@ -896,8 +896,25 @@ readline_s_get_point(VALUE self)
|
||||||
{
|
{
|
||||||
return INT2NUM(rl_point);
|
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
|
#else
|
||||||
#define readline_s_get_point rb_f_notimplement
|
#define readline_s_get_point rb_f_notimplement
|
||||||
|
#define readline_s_set_point rb_f_notimplement
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char **
|
static char **
|
||||||
|
@ -1849,6 +1866,8 @@ Init_readline()
|
||||||
readline_s_get_line_buffer, 0);
|
readline_s_get_line_buffer, 0);
|
||||||
rb_define_singleton_method(mReadline, "point",
|
rb_define_singleton_method(mReadline, "point",
|
||||||
readline_s_get_point, 0);
|
readline_s_get_point, 0);
|
||||||
|
rb_define_singleton_method(mReadline, "point=",
|
||||||
|
readline_s_set_point, 1);
|
||||||
rb_define_singleton_method(mReadline, "set_screen_size",
|
rb_define_singleton_method(mReadline, "set_screen_size",
|
||||||
readline_s_set_screen_size, 2);
|
readline_s_set_screen_size, 2);
|
||||||
rb_define_singleton_method(mReadline, "get_screen_size",
|
rb_define_singleton_method(mReadline, "get_screen_size",
|
||||||
|
|
|
@ -17,6 +17,11 @@ class TestReadline < Test::Unit::TestCase
|
||||||
def teardown
|
def teardown
|
||||||
ENV[INPUTRC] = @inputrc
|
ENV[INPUTRC] = @inputrc
|
||||||
Readline.instance_variable_set("@completion_proc", nil)
|
Readline.instance_variable_set("@completion_proc", nil)
|
||||||
|
begin
|
||||||
|
Readline.delete_text
|
||||||
|
Readline.point = 0
|
||||||
|
rescue NotImplementedError
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if !/EditLine/n.match(Readline::VERSION)
|
if !/EditLine/n.match(Readline::VERSION)
|
||||||
|
@ -311,9 +316,22 @@ class TestReadline < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
def test_insert_text
|
||||||
str = "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(0, Readline.point)
|
||||||
assert_equal(Readline, Readline.insert_text(str))
|
assert_equal(Readline, Readline.insert_text(str))
|
||||||
assert_equal(str, Readline.line_buffer)
|
assert_equal(str, Readline.line_buffer)
|
||||||
|
|
Loading…
Add table
Reference in a new issue