From 22b20835abe6d8f7acd236f332b67332e921d049 Mon Sep 17 00:00:00 2001 From: honnza Date: Fri, 12 Nov 2021 16:12:48 +0100 Subject: [PATCH] update 20211112 --- gzView.rb | 25 +++++++++++-------------- ident_subseq_dyn.rb | 4 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/gzView.rb b/gzView.rb index 054f868..da16cf9 100644 --- a/gzView.rb +++ b/gzView.rb @@ -529,30 +529,27 @@ def initialize(col_styles, width = IO.console.winsize[1] - 1) @col_styles.each{_1[:opt_width] = 1; _1[:fixed] = true if _1[:width]} @width = width @data = [] - recalc_widths end def recalc_widths #todo: minimize total height instead of dividing widths equally #todo: redistribute rounding errors in the meantime? - fixed_total = @col_styles.filter{_1[:fixed]}.map{_1[:width]}.sum - auto_cols = @col_styles.filter{!_1[:fixed]} + @col_styles.filter{_1[:nowrap]}.each{_1[:width] = _1[:opt_width]} + fixed_total = @col_styles.filter{_1[:fixed] || _1[:nowrap]}.map{_1[:width]}.sum + auto_cols = @col_styles.reject{_1[:fixed] || _1[:nowrap]} auto_opt_total = auto_cols.map{_1[:opt_width]}.sum auto_total = @width - fixed_total - @col_styles.count - if auto_total < auto_opt_total - @col_styles.filter{!_1[:fixed] && _1[:nowrap]}.each do - _1[:width] = _1[:opt_width] - fixed_total += _1[:width] - auto_total -= _1[:width] - auto_opt_total -= _1[:width] - end - auto_cols.reject!{_1[:nowrap]} + if auto_total >= auto_opt_total + auto_cols.each {_1[:width] = _1[:opt_width]} + return end - auto_cols.each do - _1[:width] = (_1[:opt_width] * auto_total / auto_opt_total).clamp(1..) - end + auto_cols[0][:width] = auto_total if auto_cols.count == 1 + return if auto_cols.count <= 1 + + p auto_cols + raise "TODO" end def to_s; render_all; end diff --git a/ident_subseq_dyn.rb b/ident_subseq_dyn.rb index 62b2366..a8c40a9 100644 --- a/ident_subseq_dyn.rb +++ b/ident_subseq_dyn.rb @@ -439,9 +439,9 @@ def highlight_diff in_str, new_str, old_str, fold_case end results = calc.results if tiebreak == :all - calc.strs.zip(results).sort.each{|full| puts full.map(&:inspect).join(" => ")} + calc.orig_strs.zip(results).sort.each{|full| puts full.map(&:inspect).join(" => ")} else offset = results.map(&:length).max - calc.strs.zip(results).sort.each{|in_str, out_str| puts "%#{offset}s %s" % [out_str, in_str]} + calc.orig_strs.zip(results).sort.each{|in_str, out_str| puts "%#{offset}s %s" % [out_str, in_str]} end end