2019-12-28 12:16:32 +01:00
|
|
|
local core = require "core"
|
|
|
|
local style = require "core.style"
|
|
|
|
local View = require "core.view"
|
|
|
|
|
|
|
|
|
|
|
|
local LogView = View:extend()
|
|
|
|
|
2021-08-27 23:55:17 +02:00
|
|
|
LogView.context = "session"
|
2019-12-28 12:16:32 +01:00
|
|
|
|
|
|
|
function LogView:new()
|
|
|
|
LogView.super.new(self)
|
2020-04-30 15:44:52 +02:00
|
|
|
self.last_item = core.log_items[#core.log_items]
|
2019-12-28 12:16:32 +01:00
|
|
|
self.scrollable = true
|
|
|
|
self.yoffset = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function LogView:get_name()
|
|
|
|
return "Log"
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function LogView:update()
|
|
|
|
local item = core.log_items[#core.log_items]
|
|
|
|
if self.last_item ~= item then
|
|
|
|
self.last_item = item
|
|
|
|
self.scroll.to.y = 0
|
|
|
|
self.yoffset = -(style.font:get_height() + style.padding.y)
|
|
|
|
end
|
|
|
|
|
|
|
|
self:move_towards("yoffset", 0)
|
|
|
|
|
|
|
|
LogView.super.update(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-05-06 01:06:27 +02:00
|
|
|
local function draw_text_multiline(font, text, x, y, color)
|
|
|
|
local th = font:get_height()
|
|
|
|
local resx, resy = x, y
|
|
|
|
for line in text:gmatch("[^\n]+") do
|
|
|
|
resy = y
|
|
|
|
resx = renderer.draw_text(style.font, line, x, y, color)
|
|
|
|
y = y + th
|
|
|
|
end
|
|
|
|
return resx, resy
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-12-28 12:16:32 +01:00
|
|
|
function LogView:draw()
|
|
|
|
self:draw_background(style.background)
|
|
|
|
|
|
|
|
local ox, oy = self:get_content_offset()
|
|
|
|
local th = style.font:get_height()
|
|
|
|
local y = oy + style.padding.y + self.yoffset
|
|
|
|
|
|
|
|
for i = #core.log_items, 1, -1 do
|
|
|
|
local x = ox + style.padding.x
|
|
|
|
local item = core.log_items[i]
|
|
|
|
local time = os.date(nil, item.time)
|
|
|
|
x = renderer.draw_text(style.font, time, x, y, style.dim)
|
|
|
|
x = x + style.padding.x
|
|
|
|
local subx = x
|
2020-05-06 01:06:27 +02:00
|
|
|
x, y = draw_text_multiline(style.font, item.text, x, y, style.text)
|
|
|
|
renderer.draw_text(style.font, " at " .. item.at, x, y, style.dim)
|
2019-12-28 12:16:32 +01:00
|
|
|
y = y + th
|
|
|
|
if item.info then
|
2020-05-06 01:06:27 +02:00
|
|
|
subx, y = draw_text_multiline(style.font, item.info, subx, y, style.dim)
|
|
|
|
y = y + th
|
2019-12-28 12:16:32 +01:00
|
|
|
end
|
|
|
|
y = y + style.padding.y
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return LogView
|