class TTYString::CSICode
Public Class Methods
default_arg(value = nil)
click to toggle source
# File lib/tty_string/csi_code.rb, line 8 def default_arg(value = nil) @default_arg ||= value @default_arg || 1 end
Private Class Methods
arg_re()
click to toggle source
# File lib/tty_string/csi_code.rb, line 39 def arg_re /\d*/ end
args(parser)
click to toggle source
# File lib/tty_string/csi_code.rb, line 19 def args(parser) a = parser.matched.slice(2..-2).split(';') a = a.slice(0, max_args) unless max_args == -1 a.map! { |n| n.empty? ? default_arg : n.to_i } a end
args_re()
click to toggle source
# File lib/tty_string/csi_code.rb, line 30 def args_re # rubocop:disable Metrics/MethodLength case max_args when 0 then nil when 1 then /#{arg_re}?/ when -1 then /(#{arg_re}?(;#{arg_re})*)?/ else /(#{arg_re}?(;#{arg_re}){0,#{max_args - 1}})?/ end end
match?(parser)
click to toggle source
# File lib/tty_string/csi_code.rb, line 15 def match?(parser) parser.scan(re) end
max_args()
click to toggle source
# File lib/tty_string/csi_code.rb, line 43 def max_args @max_args ||= begin params = instance_method(:action).parameters return -1 if params.assoc(:rest) params.length end end
re()
click to toggle source
# File lib/tty_string/csi_code.rb, line 26 def re @re ||= /\e\[#{args_re}#{char}/ end