Software /
code /
prosody
Comparison
util/human/io.lua @ 13031:1023c3faffac
util.human.io: Fix pattern to support fractional proportions
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 06 Apr 2023 15:03:45 +0100 |
parent | 13030:1f89a2a9f532 |
child | 13038:83b93ad08b23 |
comparison
equal
deleted
inserted
replaced
13030:1f89a2a9f532 | 13031:1023c3faffac |
---|---|
137 | 137 |
138 -- Calculate width of proportional columns | 138 -- Calculate width of proportional columns |
139 local total_proportional_width = 0; | 139 local total_proportional_width = 0; |
140 for i = 1, #col_specs do | 140 for i = 1, #col_specs do |
141 if not widths[i] then | 141 if not widths[i] then |
142 local width_spec = col_specs[i].width:match("(%d+)[p%%]"); | 142 local width_spec = col_specs[i].width:match("([%d%.]+)[p%%]"); |
143 total_proportional_width = total_proportional_width + tonumber(width_spec); | 143 total_proportional_width = total_proportional_width + tonumber(width_spec); |
144 end | 144 end |
145 end | 145 end |
146 | 146 |
147 for i = 1, #col_specs do | 147 for i = 1, #col_specs do |
148 if not widths[i] then | 148 if not widths[i] then |
149 local width_spec = col_specs[i].width:match("(%d+)[p%%]"); | 149 local width_spec = col_specs[i].width:match("([%d%.]+)[p%%]"); |
150 local rel_width = tonumber(width_spec); | 150 local rel_width = tonumber(width_spec); |
151 widths[i] = math.floor(free_width*(rel_width/total_proportional_width)); | 151 widths[i] = math.floor(free_width*(rel_width/total_proportional_width)); |
152 end | 152 end |
153 end | 153 end |
154 | 154 |