summaryrefslogtreecommitdiff
path: root/luaotfload-database.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2013-11-16 22:36:37 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2013-11-16 22:36:37 +0100
commit2be8db31dc0406e149a89c62bd628cfa6756ab30 (patch)
tree1084cde2f2a7af51f0e045c89912ed28a42897c6 /luaotfload-database.lua
parent4e3c25d0fa4ad115416c5004e0e544b2faf99788 (diff)
downloadluaotfload-2be8db31dc0406e149a89c62bd628cfa6756ab30.tar.gz
[db] use tput to determine the terminal size if appropriate
Diffstat (limited to 'luaotfload-database.lua')
-rw-r--r--luaotfload-database.lua40
1 files changed, 36 insertions, 4 deletions
diff --git a/luaotfload-database.lua b/luaotfload-database.lua
index bccfd7b..714c37c 100644
--- a/luaotfload-database.lua
+++ b/luaotfload-database.lua
@@ -47,7 +47,6 @@ local C, Cc, Cf, Cg, Cs, Ct
--- Luatex builtins
local load = load
local next = next
-local pcall = pcall
local require = require
local tonumber = tonumber
local unpack = table.unpack
@@ -59,6 +58,7 @@ local fontloaderopen = fontloader.open
local gzipopen = gzip.open
local iolines = io.lines
local ioopen = io.open
+local iopopen = io.popen
local kpseexpand_path = kpse.expand_path
local kpseexpand_var = kpse.expand_var
local kpsefind_file = kpse.find_file
@@ -123,6 +123,26 @@ local luaotfloadconfig = config.luaotfload --- always present
luaotfloadconfig.resolver = luaotfloadconfig.resolver or "normal"
luaotfloadconfig.formats = luaotfloadconfig.formats or "otf,ttf,ttc,dfont"
luaotfloadconfig.strip = luaotfloadconfig.strip == true
+--- The “termwidth” value is only considered when printing
+--- short status messages, e.g. when building the database
+--- online.
+if not luaotfloadconfig.termwidth then
+ local tw = 79
+ if not ( os.type == "windows" --- Assume broken terminal.
+ or os.getenv "TERM" == "dumb")
+ and iopopen
+ then
+ local p = iopopen "tput cols"
+ if p then
+ result = p:read "*all"
+ p:close ()
+ if result then
+ tw = tonumber (result) or tw
+ end
+ end
+ end
+ luaotfloadconfig.termwidth = tw
+end
--- this option allows for disabling updates
--- during a TeX run
@@ -1349,7 +1369,7 @@ local get_english_names = function (names, basename)
local english_names
if names then
- inspect(names)
+ --inspect(names)
for _, raw_namedata in next, names do
if raw_namedata.lang == "English (US)" then
english_names = raw_namedata.names
@@ -2086,6 +2106,16 @@ local find_font_files = function (root, recurse)
end
end
+--- truncate_string -- Cut the first part of a string to fit it
+--- into a given terminal width. The parameter “restrict” (int)
+--- indicates the number of characters already consumed on the
+--- line.
+local ellipsis = ".."
+local truncate_string = function (str, restrict)
+ local wd = luaotfloadconfig.termwidth - restrict - 2
+ return ellipsis .. stringsub(str, #str - wd)
+end
+
--[[doc--
scan_dir() scans a directory and populates the list of fonts
@@ -2131,10 +2161,12 @@ local scan_dir = function (dirname, currentnames, targetnames,
local new
if dry_run == true then
+ local truncated = truncate_string (fullname, 43)
report_status ("both", "db",
- "Would have been loading %q", fullname)
+ "Would have been loading %s", truncated)
else
- report_status ("both", "db", "Loading font %q", fullname)
+ local truncated = truncate_string (fullname, 32)
+ report_status ("both", "db", "Loading font %s", truncated)
local new = read_font_names (fullname, currentnames,
targetnames, texmf)
if new == true then