From d14d060f1c52afa0f72f15cdafcc0772474cce79 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Fri, 11 Mar 2022 05:14:12 -0400 Subject: smallclock: use new StatusView api, removed coroutine --- plugins/smallclock.lua | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'plugins/smallclock.lua') diff --git a/plugins/smallclock.lua b/plugins/smallclock.lua index da13236..201a65a 100644 --- a/plugins/smallclock.lua +++ b/plugins/smallclock.lua @@ -1,27 +1,27 @@ -- mod-version:3 --lite-xl 2.1 local core = require "core" local style = require "core.style" -local status_view = require "core.statusview" +local StatusView = require "core.statusview" local time = "" -core.add_thread(function() - while true do +local last_time = os.time() +local function update_time() + if os.time() > last_time then local t = os.date("*t") time = string.format("%02d:%02d", t.hour, t.min) - coroutine.yield(1) + last_time = os.time() end -end) - -local get_items = status_view.get_items - -function status_view:get_items() - local left, right = get_items(self) - local t = {style.dim, self.separator2, style.accent, time} - - for _, item in ipairs(t) do - table.insert(right, item) - end - - return left, right end + +core.status_view:add_item( + nil, + "status:small-clock", + StatusView.Item.RIGHT, + function() + update_time() + return {style.accent, time} + end, + nil, + -1 +).separator = core.status_view.separator2 -- cgit v1.2.3