mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Merge reline-0.3.1
This commit is contained in:
parent
ad92236d24
commit
4d1faefa10
9 changed files with 92 additions and 10 deletions
|
@ -43,7 +43,7 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
|
|||
# 20 ^T
|
||||
:ed_transpose_chars,
|
||||
# 21 ^U
|
||||
:ed_kill_line,
|
||||
:unix_line_discard,
|
||||
# 22 ^V
|
||||
:ed_quoted_insert,
|
||||
# 23 ^W
|
||||
|
|
|
@ -74,7 +74,22 @@ module Reline::Terminfo
|
|||
#extern 'char *tparm(const char *str, ...)'
|
||||
@tiparm = Fiddle::Function.new(curses_dl['tparm'], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VARIADIC], Fiddle::TYPE_VOIDP)
|
||||
end
|
||||
# TODO: add int tigetflag(char *capname) and int tigetnum(char *capname)
|
||||
begin
|
||||
#extern 'int tigetflag(char *str)'
|
||||
@tigetflag = Fiddle::Function.new(curses_dl['tigetflag'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
|
||||
rescue Fiddle::DLError
|
||||
# OpenBSD lacks tigetflag
|
||||
#extern 'int tgetflag(char *str)'
|
||||
@tigetflag = Fiddle::Function.new(curses_dl['tgetflag'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
|
||||
end
|
||||
begin
|
||||
#extern 'int tigetnum(char *str)'
|
||||
@tigetnum = Fiddle::Function.new(curses_dl['tigetnum'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
|
||||
rescue Fiddle::DLError
|
||||
# OpenBSD lacks tigetnum
|
||||
#extern 'int tgetnum(char *str)'
|
||||
@tigetnum = Fiddle::Function.new(curses_dl['tgetnum'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
|
||||
end
|
||||
|
||||
def self.setupterm(term, fildes)
|
||||
errret_int = String.new("\x00" * 8, encoding: 'ASCII-8BIT')
|
||||
|
@ -122,6 +137,28 @@ module Reline::Terminfo
|
|||
@tiparm.(str, *new_args).to_s
|
||||
end
|
||||
|
||||
def self.tigetflag(capname)
|
||||
flag = @tigetflag.(capname).to_i
|
||||
case flag
|
||||
when -1
|
||||
raise TerminfoError, "not boolean capability: #{capname}"
|
||||
when 0
|
||||
raise TerminfoError, "can't find capability: #{capname}"
|
||||
end
|
||||
flag
|
||||
end
|
||||
|
||||
def self.tigetnum(capname)
|
||||
num = @tigetnum.(capname).to_i
|
||||
case num
|
||||
when -2
|
||||
raise TerminfoError, "not numeric capability: #{capname}"
|
||||
when -1
|
||||
raise TerminfoError, "can't find capability: #{capname}"
|
||||
end
|
||||
num
|
||||
end
|
||||
|
||||
def self.enabled?
|
||||
true
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module Reline
|
||||
VERSION = '0.3.0'
|
||||
VERSION = '0.3.1'
|
||||
end
|
||||
|
|
|
@ -386,7 +386,7 @@ class Reline::Windows
|
|||
def self.scroll_down(val)
|
||||
return if val < 0
|
||||
return unless csbi = get_console_screen_buffer_info
|
||||
buffer_width, x, y, buffer_lines, attributes, window_left, window_top, window_bottom = csbi.unpack('ssssSssx2s')
|
||||
buffer_width, buffer_lines, x, y, attributes, window_left, window_top, window_bottom = csbi.unpack('ssssSssx2s')
|
||||
screen_height = window_bottom - window_top + 1
|
||||
val = screen_height if val > screen_height
|
||||
|
||||
|
|
|
@ -2329,4 +2329,26 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
|
|||
assert_cursor(1)
|
||||
assert_cursor_max(1)
|
||||
end
|
||||
|
||||
def test_unix_line_discard
|
||||
input_keys("\C-u", false)
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_line('')
|
||||
input_keys('abc')
|
||||
assert_byte_pointer_size('abc')
|
||||
assert_cursor(3)
|
||||
assert_cursor_max(3)
|
||||
input_keys("\C-b\C-u", false)
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(1)
|
||||
assert_line('c')
|
||||
input_keys("\C-f\C-u", false)
|
||||
assert_byte_pointer_size('')
|
||||
assert_cursor(0)
|
||||
assert_cursor_max(0)
|
||||
assert_line('')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -137,7 +137,7 @@ class Reline::Test < Reline::TestCase
|
|||
end
|
||||
|
||||
def test_completion_proc
|
||||
skip unless Reline.completion_proc == nil
|
||||
omit unless Reline.completion_proc == nil
|
||||
# Another test can set Reline.completion_proc
|
||||
|
||||
# assert_equal(nil, Reline.completion_proc)
|
||||
|
|
|
@ -9,24 +9,46 @@ class Reline::Terminfo::Test < Reline::TestCase
|
|||
def test_tigetstr
|
||||
assert Reline::Terminfo.tigetstr('khome')
|
||||
rescue Reline::Terminfo::TerminfoError => e
|
||||
skip e.message
|
||||
omit e.message
|
||||
end
|
||||
|
||||
def test_tiparm
|
||||
assert Reline::Terminfo.tigetstr('khome').tiparm
|
||||
rescue Reline::Terminfo::TerminfoError => e
|
||||
skip e.message
|
||||
omit e.message
|
||||
end
|
||||
|
||||
def test_tigetstr_with_param
|
||||
assert Reline::Terminfo.tigetstr('cuu').include?('%p1%d')
|
||||
rescue Reline::Terminfo::TerminfoError => e
|
||||
skip e.message
|
||||
omit e.message
|
||||
end
|
||||
|
||||
def test_tiparm_with_param
|
||||
assert Reline::Terminfo.tigetstr('cuu').tiparm(4649).include?('4649')
|
||||
rescue Reline::Terminfo::TerminfoError => e
|
||||
skip e.message
|
||||
omit e.message
|
||||
end
|
||||
|
||||
def test_tigetflag
|
||||
assert_instance_of Integer, Reline::Terminfo.tigetflag('xenl')
|
||||
rescue Reline::Terminfo::TerminfoError => e
|
||||
omit e.message
|
||||
end
|
||||
|
||||
def test_tigetflag_with_error
|
||||
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetflag('cuu') }
|
||||
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetflag('unknown') }
|
||||
end
|
||||
|
||||
def test_tigetnum
|
||||
assert_instance_of Integer, Reline::Terminfo.tigetnum('colors')
|
||||
rescue Reline::Terminfo::TerminfoError => e
|
||||
omit e.message
|
||||
end
|
||||
|
||||
def test_tigetnum_with_error
|
||||
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum('cuu') }
|
||||
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum('unknown') }
|
||||
end
|
||||
end if Reline::Terminfo.enabled?
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'irb/ruby-lex'
|
|||
class TerminationChecker < RubyLex
|
||||
def terminated?(code)
|
||||
code.gsub!(/\n*$/, '').concat("\n")
|
||||
@tokens = Ripper.lex(code)
|
||||
@tokens = self.class.ripper_lex_without_warning(code)
|
||||
continue = process_continue
|
||||
code_block_open = check_code_block(code)
|
||||
indent = process_nesting_level
|
||||
|
|
|
@ -121,6 +121,7 @@ begin
|
|||
end
|
||||
|
||||
def test_finish_autowrapped_line_in_the_middle_of_multilines
|
||||
omit if RUBY_VERSION < '2.7'
|
||||
start_terminal(30, 16, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
|
||||
write("<<~EOM\n ABCDEFG\nEOM\n")
|
||||
close
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue