aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4/utils.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-08-21 23:13:05 -0400
committerRalph Amissah <ralph@amissah.com>2013-08-21 23:13:05 -0400
commit84ff66b6d438c314583983c34421d02803f5dfb4 (patch)
tree488857b8c69b0c9812abdb27f975cf303064a617 /lib/sisu/v4/utils.rb
parentv4 v5: rescued error messages (diff)
v4 v5: terminal message, code marker
Diffstat (limited to 'lib/sisu/v4/utils.rb')
-rw-r--r--lib/sisu/v4/utils.rb68
1 files changed, 56 insertions, 12 deletions
diff --git a/lib/sisu/v4/utils.rb b/lib/sisu/v4/utils.rb
index 134fbc21..b120cc01 100644
--- a/lib/sisu/v4/utils.rb
+++ b/lib/sisu/v4/utils.rb
@@ -92,15 +92,39 @@ module SiSU_Utils
#ansi_color + @line.to_s + ansi_color_off + ' ' + @file.gsub(/([^\/]+$)/,"#{ansi_color}\\1#{ansi_color_off}")
c
end
- def set(color=nil)
- c=ansi(color)
+ def var(v,x)
+ h={ c: nil, m: '' }
+ if v.class == Hash
+ h[:c] = (defined? v[:c]) ? v[:c] : ''
+ h[:m] = (defined? v[:m]) ? v[:m] : ''
+ else
+ if v.class == Symbol
+ h[:c]=v
+ elsif v.class == String
+ h[:m]=v
+ end
+ if x.class == Symbol
+ h[:c]=x
+ elsif x.class == String
+ h[:m]=x
+ end
+ h[:c] = (defined? h[:c]) ? h[:c] : ''
+ h[:m] = (defined? h[:m]) ? h[:m] : ''
+ end
+ h[:c]=ansi(h[:c])
+ h[:m]=message(h[:m])
+ h
+ end
+ def message(msg='')
+ @message=(msg.empty?) ? '' : " #{msg}"
+ end
+ def set(v=nil,x=nil)
+ v=var(v,x)
file,path=File.basename(@file),File.dirname(@file)
- c[:on] + @line + c[:off] + ' ' + path + '/' "#{c[:on]}#{file}#{c[:off]}"
+ v[:c][:on] + @line + v[:c][:off] + ' ' + path + '/' "#{v[:c][:on]}#{file}#{v[:c][:off]}" + v[:m]
end
- def set_(color=nil)
- c=ansi(color)
- c[:on] + @line + c[:off] + ' ' +
- @file.gsub(/([^\/]+$)/,"#{c[:on]}\\1#{c[:off]}")
+ def mark(v=nil,x=nil)
+ puts set(v,x)
end
end
class Path
@@ -116,9 +140,29 @@ module SiSU_Utils
end
end
__END__
-puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:red)
-puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:green)
-puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:inv_red)
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark({ m: %{
+ code: #{@@flag[:code]}, <-- close "#{t_o}"
+}})
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark({ m: %{
+ code: #{@@flag['code']}, <-- close "#{t_o}"
+}, c: :green})
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark({ m: %{
+ code: #{@@flag['code']}, open --> "#{t_o}"
+}}) if t_o=~/^```/m
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark(%{ code: #{@@flag['code']}, open --> "#{t_o}" }) \
+if t_o=~/^```/m
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark("open -->",:green)
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:green,"open -->")
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark("open -->")
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:green)
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).mark("open -->")
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark('open -->',:green)
+SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:red).mark
puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:red).set
-puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).set
-puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:inv_red).set
+puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set('',:green)
+puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set('',:fuchsia)
+puts ANSI_C[:red] + __LINE__.to_s + ANSI_C[:off] + ' ' + __FILE__
+puts "#{ANSI_C[:red]} #{__LINE__.to_s} #{ANSI_C[:off]} #{__FILE__}"
+puts ANSI_C[:fuchsia] + __LINE__.to_s + ANSI_C[:off] + ' ' + __FILE__.gsub(/([^\/]+$)/,"#{ANSI_C[:fuchsia]}\\1#{ANSI_C[:off]}")
+puts ANSI_C[:red] + __LINE__.to_s + ANSI_C[:off] + ' ' + __FILE__.gsub(/([^\/]+$)/,"#{ANSI_C[:red]}\\1#{ANSI_C[:off]}")