From: Gordon Hecker Date: Mon, 11 Jan 2010 16:51:43 +0000 (+0100) Subject: modify status output alignment for better readability X-Git-Tag: e2factory-2.3.4pre1~36 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=bb18d144fd854be365ac852d0e24778ede73b830;p=e2factory.git modify status output alignment for better readability Signed-off-by: Gordon Hecker --- diff --git a/Changelog b/Changelog index fd4edce..dfff337 100644 --- 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 diff --git a/generic/e2lib.lua b/generic/e2lib.lua index ddb4a91..8309a32 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -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 diff --git a/local/e2build.lua b/local/e2build.lua index 418784f..38b189d 100644 --- a/local/e2build.lua +++ b/local/e2build.lua @@ -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