#
#
# patch "ChangeLog"
# from [c06a415882cc26be29919c373ae5cc0a6f8903c9]
# to [6ab1cb9cd7346bef4c4a1092881e4987ead37253]
#
# patch "ui.cc"
# from [4ab9ddcb20dd0800d73564d34c3d13384c99d18a]
# to [0dcd592fa535fa09f38e80661671815d6cc3edd0]
#
# patch "ui.hh"
# from [3513a0d7b22db094276be4f903876150906caa3d]
# to [cd2bcd9e2ed7fbe5e4e93c784659e951496013a7]
#
============================================================
--- ChangeLog c06a415882cc26be29919c373ae5cc0a6f8903c9
+++ ChangeLog 6ab1cb9cd7346bef4c4a1092881e4987ead37253
@@ -1,5 +1,19 @@
2006-04-12 Richard Levitte
+ * ui.hh (struct ticker): Add a member count_size to hold the size
+ of the tick count output and a method set_count_size to modify it.
+
+ * ui.cc (compose_count): New function to compose the count string
+ for a ticker. The code was moved from...
+ (write_ticks): ... here. If the tick's count_size is zero, use
+ compose_count to calculate the output string for a well chosen
+ large number and use its size as a default initial count size.
+ This is still updated dynamically if we get a count string size
+ that's still larger, but it should happen very rarely (when we get
+ a size of 1024 gibibytes or more, quite precisely).
+
+2006-04-12 Richard Levitte
+
* po/sv.po: A few more fuzzies to change.
2006-04-12 Richard Levitte
============================================================
--- ui.cc 4ab9ddcb20dd0800d73564d34c3d13384c99d18a
+++ ui.cc 0dcd592fa535fa09f38e80661671815d6cc3edd0
@@ -35,7 +35,8 @@
use_total(false),
keyname(tickname),
name(_(tickname.c_str())),
- shortname(s)
+ shortname(s),
+ count_size(0)
{
I(ui.tickers.find(keyname) == ui.tickers.end());
ui.tickers.insert(make_pair(keyname, this));
@@ -86,6 +87,69 @@
{
}
+static string compose_count(ticker *tick, size_t ticks=0)
+{
+ string count;
+
+ if (ticks == 0)
+ {
+ ticks = tick->ticks;
+ }
+
+ if (tick->kilocount && ticks)
+ {
+ // automatic unit conversion is enabled
+ float div = 1.0;
+ const char *message;
+
+ if (ticks >= 1073741824)
+ {
+ div = 1073741824;
+ // xgettext: gibibytes (2^30 bytes)
+ message = N_("%.1f G");
+ }
+ else if (ticks >= 1048576)
+ {
+ div = 1048576;
+ // xgettext: mebibytes (2^20 bytes)
+ message = N_("%.1f M");
+ }
+ else if (ticks >= 1024)
+ {
+ div = 1024;
+ // xgettext: kibibytes (2^10 bytes)
+ message = N_("%.1f k");
+ }
+ else
+ {
+ div = 1;
+ message = "%.0f";
+ }
+ // We reset the mod to the divider, to avoid spurious screen updates.
+ tick->mod = max(static_cast(div / 10.0), 1);
+ count = (F(message) % (ticks / div)).str();
+ }
+ else if (tick->use_total)
+ {
+ // We know that we're going to eventually have 'total' displayed
+ // twice on screen, plus a slash. So we should pad out this field
+ // to that eventual size to avoid spurious re-issuing of the
+ // tick titles as we expand to the goal.
+ string complete = (F("%d/%d") % tick->total % tick->total).str();
+ // xgettext: bytes
+ string current = (F("%d/%d") % ticks % tick->total).str();
+ count.append(complete.size() - current.size(),' ');
+ count.append(current);
+ }
+ else
+ {
+ // xgettext: bytes
+ count = (F("%d") % ticks).str();
+ }
+
+ return count;
+}
+
void tick_write_count::write_ticks()
{
vector tick_widths;
@@ -95,63 +159,30 @@
for (map::const_iterator i = ui.tickers.begin();
i != ui.tickers.end(); ++i)
{
- string count;
ticker * tick = i->second;
- if (tick->kilocount && tick->ticks)
- {
- // automatic unit conversion is enabled
- float div = 1.0;
- const char *message;
- if (tick->ticks >= 1073741824)
- {
- div = 1073741824;
- // xgettext: gibibytes (2^30 bytes)
- message = N_("%.1f G");
- }
- else if (tick->ticks >= 1048576)
- {
- div = 1048576;
- // xgettext: mebibytes (2^20 bytes)
- message = N_("%.1f M");
- }
- else if (tick->ticks >= 1024)
- {
- div = 1024;
- // xgettext: kibibytes (2^10 bytes)
- message = N_("%.1f k");
- }
- else
- {
- div = 1;
- message = "%.0f";
- }
- // We reset the mod to the divider, to avoid spurious screen updates.
- tick->mod = max(static_cast(div / 10.0), 1);
- count = (F(message) % (tick->ticks / div)).str();
- }
- else if (tick->use_total)
+ if (tick->count_size == 0)
{
- // We know that we're going to eventually have 'total' displayed
- // twice on screen, plus a slash. So we should pad out this field
- // to that eventual size to avoid spurious re-issuing of the
- // tick titles as we expand to the goal.
- string complete = (F("%d/%d") % tick->total % tick->total).str();
- // xgettext: bytes
- string current = (F("%d/%d") % tick->ticks % tick->total).str();
- count.append(complete.size() - current.size(),' ');
- count.append(current);
+ // To find out what the maximum size can be, choose one the the
+ // dividers from compose_count, subtract one and have compose_count
+ // create the count string for that. Use the size of the returned
+ // count string as an initial size for this tick.
+ tick->set_count_size(display_width(utf8(compose_count(tick,
+ 1048575))));
}
- else
+
+ string count(compose_count(tick));
+
+ size_t title_width = display_width(utf8(tick->name));
+ size_t count_width = display_width(utf8(count));
+
+ if (count_width > tick->count_size)
{
- // xgettext: bytes
- count = (F("%d") % tick->ticks).str();
+ tick->set_count_size(count_width);
}
-
- size_t title_width = display_width(utf8(tick->name));
- size_t count_width = display_width(utf8(count));
- size_t max_width = std::max(title_width, count_width);
+ size_t max_width = std::max(title_width, tick->count_size);
+
string name;
name.append(max_width - title_width, ' ');
name.append(tick->name);
============================================================
--- ui.hh 3513a0d7b22db094276be4f903876150906caa3d
+++ ui.hh cd2bcd9e2ed7fbe5e4e93c784659e951496013a7
@@ -29,9 +29,11 @@
std::string keyname;
std::string name; // translated name
std::string shortname;
- ticker(std::string const & n, std::string const & s, size_t mod = 64,
+ size_t count_size;
+ ticker(std::string const & n, std::string const & s, size_t mod = 64,
bool kilocount=false);
void set_total(size_t tot) { use_total = true; total = tot; }
+ void set_count_size(size_t csiz) { count_size = csiz; }
void operator++();
void operator+=(size_t t);
~ticker();