Skip to content

Commit

Permalink
update 20211112
Browse files Browse the repository at this point in the history
  • Loading branch information
honnza committed Nov 12, 2021
1 parent bbac8b9 commit 22b2083
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions gzView.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ident_subseq_dyn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 22b2083

Please sign in to comment.