Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge reline-0.3.1 #6648

Merged
merged 1 commit into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reline/key_actor/emacs.rb
Expand Up @@ -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
Expand Down
39 changes: 38 additions & 1 deletion lib/reline/terminfo.rb
Expand Up @@ -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')
Expand Down Expand Up @@ -122,6 +137,28 @@ def self.tiparm(str, *args)
@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
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/version.rb
@@ -1,3 +1,3 @@
module Reline
VERSION = '0.3.0'
VERSION = '0.3.1'
end
2 changes: 1 addition & 1 deletion lib/reline/windows.rb
Expand Up @@ -386,7 +386,7 @@ def self.erase_after_cursor
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

Expand Down
22 changes: 22 additions & 0 deletions test/reline/test_key_actor_emacs.rb
Expand Up @@ -2329,4 +2329,26 @@ def test_input_unknown_char
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
2 changes: 1 addition & 1 deletion test/reline/test_reline.rb
Expand Up @@ -137,7 +137,7 @@ def test_completion_case_fold
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)
Expand Down
30 changes: 26 additions & 4 deletions test/reline/test_terminfo.rb
Expand Up @@ -9,24 +9,46 @@ def setup
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?
2 changes: 1 addition & 1 deletion test/reline/yamatanooroti/termination_checker.rb
Expand Up @@ -4,7 +4,7 @@
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
Expand Down
1 change: 1 addition & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Expand Up @@ -121,6 +121,7 @@ def test_finish_autowrapped_line_in_the_middle_of_lines
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
Expand Down