]> git.e2factory.org Git - e2factory.git/commitdiff
modify status output alignment for better readability
authorGordon Hecker <gh@emlix.com>
Mon, 11 Jan 2010 16:51:43 +0000 (17:51 +0100)
committerGordon Hecker <gh@emlix.com>
Fri, 12 Feb 2010 09:51:59 +0000 (10:51 +0100)
Signed-off-by: Gordon Hecker <gh@emlix.com>
Changelog
generic/e2lib.lua
local/e2build.lua

index fd4edce7e42fd08b3f24059ff09c493731673722..dfff3370a811dc5165353b3574ff8a89423dc64d 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -20,6 +20,7 @@ NEXT:
  * a few minor bugs were fixed
  * code related to external tools was moved into the new tools module
  * transport, url and hash were turned into proper Lua modules
+ * fix alignment of status messages for better readability
 
 e2factory-2.3.3
  * use sha1 module instead of calling the sha1sum tool
index ddb4a91f45747873e430cbce0d7b7381b05f0d1f..8309a32f04ca553d5771e6cc1d60052eb58dcd63 100644 (file)
@@ -1889,6 +1889,33 @@ function e2lib.chdir(path)
   return true, nil
 end
 
+--- align strings
+-- @param columns screen width
+-- @param align1 column to align string1to
+-- @param string1 first string
+-- @param align2 column to align string2 to
+-- @param string2 second string
+function e2lib.align(columns, align1, string1, align2, string2)
+       local lines = 1
+       if align2 + #string2 > columns then
+               -- try to move string2 to the left first
+               align2 = columns - #string2
+       end
+       if align1 + #string1 + #string2 > columns then
+               -- split into two lines
+               lines = 2
+       end
+       local s
+       if lines == 1 then
+               s = string.rep(" ", align1) .. string1 ..
+                       string.rep(" ", align2 - #string1 - align1) .. string2
+       else
+               s = string.rep(" ", align1) .. string1 .. "\n" ..
+                       string.rep(" ", align2) .. string2
+       end
+       return s
+end
+
 --------------------------------------------------------------------------------
 
 -- "seal" modules e2util and e2lib
index 418784f814e81d3589b2b2ea1c96bf6f9b08af95..38b189d9aba41d7cf52e089cd6fc2ef708ed4334 100644 (file)
@@ -56,15 +56,19 @@ function e2build.result_available(info, r, return_flags)
   local sbid = e2tool.bid_display(buildid)
   local rc, re
   local e = new_error("error while checking if result is available: %s", r)
+  local columns = tonumber(e2lib.osenv["COLUMNS"])
   if res.playground then
-    return_flags.message = string.format("building %-20s [%s] [playground]",
-                                                               r, sbid)
+    return_flags.message = e2lib.align(columns,
+               0, string.format("building %-20s", r),
+               columns, string.format("[%s] [playground]", sbid))
     return_flags.stop = false
     return true, nil
   end
   if res.build_mode.source_set() == "working-copy" or
      res.force_rebuild == true then
-    return_flags.message = string.format("building %-20s [%s]", r, sbid)
+    return_flags.message = e2lib.align(columns,
+                               0, string.format("building %-20s", r),
+                               columns, string.format("[%s]", sbid))
     return_flags.stop = false
     return true, nil
   end
@@ -84,7 +88,9 @@ function e2build.result_available(info, r, return_flags)
   rc = e2lib.isfile(path)
   if not rc then
     -- result is not available. Build.
-    return_flags.message = string.format("building %-20s [%s]", r, sbid)
+    return_flags.message = e2lib.align(columns,
+                               0, string.format("building %-20s", r),
+                               columns, string.format("[%s]", sbid))
     return_flags.stop = false
     return true, nil
   end
@@ -102,7 +108,9 @@ function e2build.result_available(info, r, return_flags)
     return false, e:cat(re)
   end
   -- return true
-  return_flags.message = string.format("skipping %-20s [%s]", r, sbid)
+  return_flags.message = e2lib.align(columns,
+                               0, string.format("skipping %-20s", r),
+                               columns, string.format("[%s]", sbid))
   return_flags.stop = true
   return true, nil
 end