Conky可以用单词而不是数字显示时间吗?

Modified on: Sat, 09 Jun 2018 06:54:53 +0800

我想让Conky用文字显示时间而不是数字。

我想要做的或多或少是Pebble Watch的外观(红色手表)。

与图像一样,即使只显示时间而不是日期。

这可能吗?

作者:,Uri Herrera

最佳答案

Lua脚本解决方案

使用Lua脚本确实可以实现。您可以使用下面的脚本(数字转换来自rosettacode.org)。

脚本可以做一个无聊的选项,将12:45转换为“十二四十五”,以及一个很棒的选项,将其转换为“四分之一”。它还有一个Uri Herrera选项,它使小时加粗;)

当时间发生变化时,它也会自动刷新。

words = {"one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ", "nine "}
levels = {"thousand ", "million ", "billion ", "trillion ", "quadrillion ", "quintillion ", "sextillion ", "septillion ", "octillion ", [0] = ""}
iwords = {"ten ", "twenty ", "thirty ", "forty ", "fifty ", "sixty ", "seventy ", "eighty ", "ninety "}
twords = {"eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen "}

function digits(n)
  local i, ret = -1
  return function()
    i, ret = i + 1, n % 10
    if n > 0 then
      n = math.floor(n / 10)
      return i, ret
    end
  end
end

level = false
function getname(pos, dig)
  level = level or pos % 3 == 0
  if(dig == 0) then return "" end
  local name = (pos % 3 == 1 and iwords[dig] or words[dig]) .. (pos % 3 == 2 and "hundred " or "")
  if(level) then name, level = name .. levels[math.floor(pos / 3)], false end
  return name
end

function numberToWord(number)
    if(number == 0) then return "zero" end
    vword = ""
    for i, v in digits(number) do
      vword = getname(i, v) .. vword
    end

    for i, v in ipairs(words) do
      vword = vword:gsub("ty " .. v, "ty-" .. v)
      vword = vword:gsub("ten " .. v, twords[i])
    end
    return vword
end

function conky_boringTime()
    hour = os.date("%H") + 0
    minute = os.date("%M") + 0
    return numberToWord(hour) .. numberToWord(minute)
end

function conky_awesomeTime()
    hour = os.date("%H") + 0
    minute = os.date("%M") + 0
    hour = hour % 12
    if(hour == 0) then 
        hour, nextHourWord = 12, "one " 
    else
        nextHourWord = numberToWord(hour+1)
    end
    hourWord = numberToWord(hour)
    if(minute == 0 ) then 
        return hourWord .. "o'clock"
    elseif(minute == 30) then
        return "half past " .. hourWord
    elseif(minute == 15) then
        return "a quarter past " .. hourWord 
    elseif(minute == 45) then
        return "a quarter to " .. nextHourWord 
    else
        if(minute < 30) then
            return numberToWord(minute) .. "past " .. hourWord
        else
            return numberToWord(60-minute) .. "to " .. nextHourWord
        end
    end
end

function conky_getHourWord()
    return numberToWord(os.date("%H") + 0)
end

function conky_getMinuteWord()
    return numberToWord(os.date("%M") + 0)
end

现在把它保存到某个地方,为了这个问题的目的,假设我们把它保存为~/.config/conky/scripts/pretty_time.lua

现在编辑.conkyrc,然后在TEXT之前添加一行

lua_load ~/.config/conky/scripts/pretty_time.lua

这会加载脚本,以便我们可以访问这些函数。

然后,在TEXT下面的适当位置,您可以按以下方式调用这些函数(conky自动添加conky_前缀)

TEXT ... ${color grey}Boring time:$color ${lua boringTime} ${color grey}Awesome time:$color ${lua awesomeTime} ${color grey}Special Uri Herrera:$color ${font Aria:bold} ${lua getHourWord}$font ${lua getMinuteWord} ...

这将导致

如果你想要秒数,这不应该太难添加自己。


相关问答

添加新评论