Code: Select all
-- Started: 2021-05-25
-- Published: https://forum.farmanager.com/viewtopic.php?p=166570#p166570
-- Minimal Far version: 3.0.3300
-- Options
local Opt_RemoveLeadingZero = true
local F = far.Flags
local Color = far.AdvControl("ACTL_GETCOLOR", far.Colors.COL_CLOCK)
local ClockGuid = "6F9EA66E-5210-46FF-907A-AAF32B24A948"
local tt = far[ClockGuid] or {} -- luacheck: ignore 143
far[ClockGuid] = tt -- luacheck: ignore 142
local function Clock (Event, FarDialogEvent)
if Event ~= F.DE_DLGPROCINIT then return end
if FarDialogEvent.Msg == F.DN_INITDIALOG then
if not next(tt) then
local hRaw = tostring(FarDialogEvent.hDlg)
tt[hRaw] = far.Timer(100,
function(h)
local rect = far.AdvControl("ACTL_GETFARRECT")
local tm = os.date("%H:%M")
if Opt_RemoveLeadingZero then tm = tm:gsub("^0","") end
far.Text(rect.Right - #tm + 1, 0, Color, tm)
h.Interval = 1000
end)
end
elseif FarDialogEvent.Msg == F.DN_CLOSE then
local hRaw = tostring(FarDialogEvent.hDlg)
if tt[hRaw] then tt[hRaw]:Close(); tt[hRaw]=nil; end
end
end
Event {
description="Show clock when a dialog is on the screen";
group="DialogEvent";
action=Clock;
}