ruby-changes:70688
From: aycabta <ko1@a...>
Date: Sat, 1 Jan 2022 23:07:08 +0900 (JST)
Subject: [ruby-changes:70688] 6300c4dcc3 (master): [ruby/reline] Implement Reline::Terminfo.tigetflag
https://git.ruby-lang.org/ruby.git/commit/?id=6300c4dcc3 From 6300c4dcc3e040bdaf0f36e7be53e7c0e8c57ac0 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Sat, 1 Jan 2022 23:03:32 +0900 Subject: [ruby/reline] Implement Reline::Terminfo.tigetflag https://github.com/ruby/reline/commit/0451ed7a28 --- lib/reline/terminfo.rb | 21 ++++++++++++++++++++- test/reline/test_terminfo.rb | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/reline/terminfo.rb b/lib/reline/terminfo.rb index b4d1d735f84..82d3bf885f1 100644 --- a/lib/reline/terminfo.rb +++ b/lib/reline/terminfo.rb @@ -74,7 +74,15 @@ module Reline::Terminfo https://github.com/ruby/ruby/blob/trunk/lib/reline/terminfo.rb#L74 #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 'char *tigetflag(const char *str, ...)' + @tigetflag = Fiddle::Function.new(curses_dl['tigetflag'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT) + rescue Fiddle::DLError + # OpenBSD lacks tigetflag + #extern 'char *tgetflag(const char *str, ...)' + @tigetflag = Fiddle::Function.new(curses_dl['tgetflag'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT) + end + # TODO: add int tigetnum(char *capname) def self.setupterm(term, fildes) errret_int = String.new("\x00" * 8, encoding: 'ASCII-8BIT') @@ -122,6 +130,17 @@ module Reline::Terminfo https://github.com/ruby/ruby/blob/trunk/lib/reline/terminfo.rb#L130 @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.enabled? true end diff --git a/test/reline/test_terminfo.rb b/test/reline/test_terminfo.rb index 0d6cbe41f39..3a6c03cb095 100644 --- a/test/reline/test_terminfo.rb +++ b/test/reline/test_terminfo.rb @@ -29,4 +29,18 @@ class Reline::Terminfo::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_terminfo.rb#L29 rescue Reline::Terminfo::TerminfoError => e 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') } + end + + def test_tigetflag_with_error_unknwon + assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetflag('unknown') } + end end if Reline::Terminfo.enabled? -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/