我创建了一个名为fonts的字符串,该字符串存储系统上安装的所有字体的列表,每个字体由一个换行符分隔:
local font = io.popen("fc-list | cut -d ' ' -f 2- | cut -d : -f 1 | cut -d , -f 1 | sort | uniq")
if font == nil then return end
local fonts = font:read("*a")
print(fonts)
font:close()打印的输出看起来如下所示:
Latin Modern Mono
Latin Modern Mono Caps
Latin Modern Mono Light等等,我想把它放在桌子上。我怎么能得到这样的东西:
local fonts = {
"Latin Modern Mono",
"Latin Modern Mono Caps",
"Latin Modern Mono light"
}发布于 2022-09-29 04:16:43
感谢@timrau,这是我的最后答案。这个表叫做fonttbl。
local font = io.popen([[
fc-list | cut -d " " -f 2- | cut -d : -f 1 | cut -d , -f 1 | sort | uniq |
sed -z "$ s/\n$//"
]])
if font == nil then return end
local fontstr = font:read("*a")
local pos,fonttbl = 0,{}
for st,sp in function() return string.find(fontstr, "\n", pos, true) end do
table.insert(fonttbl, string.sub(fontstr, pos, st - 1))
pos = sp + 1
end
table.insert(fonttbl, string.sub(fontstr, pos))
font:close()https://stackoverflow.com/questions/73890064
复制相似问题