Module: TarkaMatchers::Commands

Includes:
Formatters::Styles
Defined in:
lib/tarka_matchers/commands/install.rb,
lib/tarka_matchers/commands/calibrate.rb

Constant Summary collapse

FILE_NAME =
/(?:[^\/])+(?=\.txt$)/

Constants included from Formatters::Styles

Formatters::Styles::BLACK_ON_GREEN, Formatters::Styles::GREEN_F, Formatters::Styles::L_GREEN_F, Formatters::Styles::RED_BLOCK, Formatters::Styles::RED_F, Formatters::Styles::RESET, Formatters::Styles::WHITE_BLOCK, Formatters::Styles::WHITE_F, Formatters::Styles::WHITE_ON_RED, Formatters::Styles::YELLOW_F

Class Method Summary collapse

Class Method Details

.calibrateObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tarka_matchers/commands/calibrate.rb', line 3

def self.calibrate
	lib = File.expand_path('../../../..', __FILE__)
	$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
	require 'tarka_matchers.config.rb'
	require 'io/console'
	require 'terminfo'
	include TarkaMatchers::Config
	puts "Beginning SGR calibration test..."
	all_sgr =  [['aaa',0],['aab',0]]  #SGR_CODES.map{ |v| [v,0] }
	SGR_CODES.each_with_index do |v,i|
		pangram = "The quick brown fox jumps over the lazy dog"
		spaces = '' 
		(i.to_s.length - 1).times{ spaces << ' ' }
		puts "Currently testing SGR code: #{i}\n          Escaped sequence: \\e[#{i}m\n\nDefault Text, reset with \\e[0m#{spaces}: #{pangram}\nStyled Text, styled with \\e[#{i}m: \e[#{i}m#{pangram}\e[0m\n\nThe styled text should look #{v}."
	array = ['2222','333221','3322']
	inputs = []
	closest = [-1, 0]
	puts 100
	while input = STDIN.raw(&:getch)
		if input == "\r"
			break
		else
			if input == "\u007F"
				inputs.pop
			else
				inputs << input
			end
#					puts inputs.inspect	
#					all_sgr.map! do |v|
#						[v[0], (v[0].split('') & inputs).length]
#					end
#					all_sgr.sort_by!{ |v| !v[1] }		
			print "\r                                                                                                                                                                                       \r"
			STDOUT.flush
			print "\r#{inputs.join}\r\n\rHello\r"
			i -= 1
		end
	end
	break
	SGR_CODES

=begin
require 'time'

loop do
time = Time.now.to_s + "\r"
print time
$stdout.flush
sleep 1
end
=end
	end
end

.install(flags) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tarka_matchers/commands/install.rb', line 7

def self.install flags
	puts 'Installing tarka_matchers...'
	path = 'lib/tarka_matchers/helpers/string/sgr/sgr_sequences'
	detected_terminal = ENV['TERM']
	specified_terminal = flags.index('-i')
	specified_terminal ? terminal = flags[specified_terminal+1] : terminal = detected_terminal
	
	begin
		sequence = ''
		sequence_array = IO.read("#{path}/#{terminal}.txt").split("\n")
		sequence_array_length = sequence_array.length
		sequence_array.each_with_index do |v,i| 
			string = "\n\t\t\t'#{v}', #\\e[#{i}m"
			case i
			when 0
				sequence << "[#{string}"
			when sequence_array_length - 1
				sequence << "#{string}\n\t\t]"
			else
				sequence << string
			end
		end
	rescue Errno::ENOENT
		puts "#{RED_F}TarkaMatchers doesn't currently contain a configuration file for a #{YELLOW_F}#{terminal}#{RED_F} interface. Here are the currently available interface configurations:#{YELLOW_F}"
		Dir["#{path}/*.txt"].each_with_index{ |v,i| puts FILE_NAME.match(v).to_s.prepend("#{i+1}) ") }
		puts "#{RED_F}This should only be a concern if you plan on using our SGR matchers, (e.g. 'be_red' or 'be_bold'), and even then, most modern interfaces are configured very similarly to #{YELLOW_F}xterm#{RED_F}. Consider adding a confguration file for your terminal, #{YELLOW_F}#{terminal}#{RED_F}, to the TarkaMatchers github repository.#{RESET}"
		terminal = 'xterm'					
	end
	puts sequence	
	config = File.new 'tarka_matchers.config.rb', 'w'
	config.write "module TarkaMatchers\n\tmodule Config\n\t\tSGR_CODES = #{sequence}\n\t\tend\n\tend"
	config.close
		puts "Created config file in gem root: #{GREEN_F}#{Dir.pwd}/#{L_GREEN_F}tarka_matchers_config.rb#{RESET} with #{YELLOW_F}#{terminal}#{RESET} SGR settings applied.\nIf when using our SGR matchers, (e.g. 'be_red' or 'be_bold'), you find your SGR expectations are behaving strangely, edit the #{YELLOW_F}TarkaMatchers::Config::SGR_CODES#{RESET} array, found in #{L_GREEN_F}tarka_matchers_config.rb#{RESET}. For more information into SGR codes visit: 'https://en.wikipedia.org/wiki/ANSI_escape_code'."
end