Class: TYUtil::TYPuts

Inherits:
Object
  • Object
show all
Defined in:
lib/tycli/util/puts_util.rb

Constant Summary collapse

ERROR_KEYS =
[
	"fatal",
	"error",
	"ERROR",
	"can not",
	"not found",
	"Couldn"#Couldn't find
]

Class Method Summary collapse

Class Method Details

.filter(target, keys) ⇒ Object



82
83
84
85
# File 'lib/tycli/util/puts_util.rb', line 82

def self.filter(target, keys)
	# filter_color(target, keys, 'yellow', '[!tuya-cli suggested]')
	filter_content(target, keys, '「tuya-cli」 Maybe the reason for the error is :')
end

.filter_color(target, keys, color, pre) ⇒ Object



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
# File 'lib/tycli/util/puts_util.rb', line 18

def self.filter_color(target, keys, color, pre)
	target.each_line do |s|

		# p 111
		# p s
		eval_command = ""
		keys.each do |key|
			temp = ""
			if eval_command.length > 0
				temp = " || "
			end
			eval_command = "#{eval_command}#{temp}s.include?('#{key}')"
		end
		# p eval_command
		if eval_command.length > 0 && (eval eval_command)
			# p 11111
			# p pre
			# p 222

			out = "#{pre} #{s}"
			if out.include?("''")
				out.gsub!("'","")
			end

			# p "#{pre} #{s}"
			# p 33
			# p out

			# puts "puts '#{out}'.#{color}"

			# eval "puts '#{out}'.#{color}"
		end
	end

end

.filter_content(target, keys, pre) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tycli/util/puts_util.rb', line 54

def self.filter_content(target, keys, pre)

	regular_temp = ""
	is_put_pre = false
	keys.each do |key|
		temp = ""
		if regular_temp.length > 0
			temp = "|"
		end
		regular_temp = "#{regular_temp}#{temp}(.*)#{key}(.*)"
	end

	regular = "^(#{regular_temp})$"
	target.gsub(/#{regular}/) do |matched|

		if !is_put_pre
			is_put_pre = true
			puts pre.yellow
			puts "\n"
		end

		if matched.length < 2000
			puts matched.magenta
			puts "\n"
		end
	end
end