From 84ff66b6d438c314583983c34421d02803f5dfb4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 21 Aug 2013 23:13:05 -0400 Subject: v4 v5: terminal message, code marker --- lib/sisu/v4/constants.rb | 8 +----- lib/sisu/v4/hub.rb | 10 +++---- lib/sisu/v4/sysenv.rb | 3 +-- lib/sisu/v4/texpdf.rb | 6 ++--- lib/sisu/v4/utils.rb | 68 +++++++++++++++++++++++++++++++++++++++--------- lib/sisu/v5/constants.rb | 8 +----- lib/sisu/v5/hub.rb | 10 +++---- lib/sisu/v5/sysenv.rb | 3 +-- lib/sisu/v5/texpdf.rb | 6 ++--- lib/sisu/v5/utils.rb | 68 +++++++++++++++++++++++++++++++++++++++--------- 10 files changed, 130 insertions(+), 60 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v4/constants.rb b/lib/sisu/v4/constants.rb index fab3890f..28bb2f49 100644 --- a/lib/sisu/v4/constants.rb +++ b/lib/sisu/v4/constants.rb @@ -310,13 +310,7 @@ DEVELOPER={ maintenance: :false, } __END__ -puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,: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]}") +utils.rb consider: 〔comment〕 〔links?????〕 diff --git a/lib/sisu/v4/hub.rb b/lib/sisu/v4/hub.rb index 84c10dd2..5f80e795 100644 --- a/lib/sisu/v4/hub.rb +++ b/lib/sisu/v4/hub.rb @@ -186,22 +186,22 @@ module SiSU @@n_do=0 end def remote_put_base_site_rsync # -CR - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).rsync_base end def remote_put_base_site_rsync_match # -CCRZ - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).rsync_base_sync end def remote_put_base_site # -Cr - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).scp_base end def remote_put_base_site_all # -CCr - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).scp_base_all end @@ -691,7 +691,7 @@ module SiSU elsif action_on_file_ == :true \ and @opt.files.length == 0 STDERR.puts %{requested action requires valid sisu markup file [filename (.sst .ssm)] or wildcard (that includes a valid filename)} - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) if @opt.cmd =~/[MV]/ + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:fuchsia) if @opt.cmd =~/[MV]/ end elsif @opt.mod.inspect =~/--query/ require_relative 'sst_identify_markup' # sst_identify_markup.rb diff --git a/lib/sisu/v4/sysenv.rb b/lib/sisu/v4/sysenv.rb index bcc2adce..cfbbc0c1 100644 --- a/lib/sisu/v4/sysenv.rb +++ b/lib/sisu/v4/sysenv.rb @@ -1097,8 +1097,7 @@ module SiSU_Env elsif output_dir_structure.by_filename? '' else - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - puts 'set output type, by: language, filetype or filename' + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('set output type, by: language, filetype or filename') end @stub_set_manifest=stub + '/manifest' end diff --git a/lib/sisu/v4/texpdf.rb b/lib/sisu/v4/texpdf.rb index 82b47218..3d226533 100644 --- a/lib/sisu/v4/texpdf.rb +++ b/lib/sisu/v4/texpdf.rb @@ -246,8 +246,7 @@ module SiSU_TeX and File.size(texfile) > 0 #@tex_f_no+=1 else - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - puts "\tzero file size #{@env.processing_path.tex}/#{texfile}" + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark("\tzero file size #{@env.processing_path.tex}/#{texfile}") end end end @@ -342,8 +341,7 @@ module SiSU_TeX elsif @md.opt.act[:pdf_p][:set]==:on 'pdfTex portrait' else - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - 'error: neither landscape nor portrait' + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('error: neither landscape nor portrait') end SiSU_Screen::Ansi.new(@md.opt.cmd,txt_gen).txt_grey if @md.opt.cmd=~/[MVvz]/ if defined? @md.rights.all \ 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]}") diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index 6f9d4580..bc98ca99 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -310,13 +310,7 @@ DEVELOPER={ maintenance: :false, } __END__ -puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,: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]}") +utils.rb consider: 〔comment〕 〔links?????〕 diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 052d983c..08ad7b58 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -186,22 +186,22 @@ module SiSU @@n_do=0 end def remote_put_base_site_rsync # -CR - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).rsync_base end def remote_put_base_site_rsync_match # -CCRZ - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).rsync_base_sync end def remote_put_base_site # -Cr - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).scp_base end def remote_put_base_site_all # -CCr - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:cyan) if @opt.act[:maintenance][:set] ==:on + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) if @opt.act[:maintenance][:set] ==:on require_relative 'remote' # remote.rb SiSU_Remote::Put.new(@opt).scp_base_all end @@ -691,7 +691,7 @@ module SiSU elsif action_on_file_ == :true \ and @opt.files.length == 0 STDERR.puts %{requested action requires valid sisu markup file [filename (.sst .ssm)] or wildcard (that includes a valid filename)} - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) if @opt.cmd =~/[MV]/ + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:fuchsia) if @opt.cmd =~/[MV]/ end elsif @opt.mod.inspect =~/--query/ require_relative 'sst_identify_markup' # sst_identify_markup.rb diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 1c75f4d4..3092532b 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1097,8 +1097,7 @@ module SiSU_Env elsif output_dir_structure.by_filename? '' else - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - puts 'set output type, by: language, filetype or filename' + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('set output type, by: language, filetype or filename') end @stub_set_manifest=stub + '/manifest' end diff --git a/lib/sisu/v5/texpdf.rb b/lib/sisu/v5/texpdf.rb index 18d2d2a0..0d259cf1 100644 --- a/lib/sisu/v5/texpdf.rb +++ b/lib/sisu/v5/texpdf.rb @@ -246,8 +246,7 @@ module SiSU_TeX and File.size(texfile) > 0 #@tex_f_no+=1 else - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - puts "\tzero file size #{@env.processing_path.tex}/#{texfile}" + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark("\tzero file size #{@env.processing_path.tex}/#{texfile}") end end end @@ -342,8 +341,7 @@ module SiSU_TeX elsif @md.opt.act[:pdf_p][:set]==:on 'pdfTex portrait' else - puts SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).set(:fuchsia) - 'error: neither landscape nor portrait' + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('error: neither landscape nor portrait') end SiSU_Screen::Ansi.new(@md.opt.cmd,txt_gen).txt_grey if @md.opt.cmd=~/[MVvz]/ if defined? @md.rights.all \ diff --git a/lib/sisu/v5/utils.rb b/lib/sisu/v5/utils.rb index eb707ee9..8ebc3647 100644 --- a/lib/sisu/v5/utils.rb +++ b/lib/sisu/v5/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]}") -- cgit v1.2.3