diff --git a/logger.lua b/logger.lua new file mode 100644 index 0000000..a232273 --- /dev/null +++ b/logger.lua @@ -0,0 +1,29 @@ +local M = {} + +local logLines = {} +local maxLines = 5 + +function M.log(msg) + local time = textutils.formatTime(os.time(), true) + local entry = string.format("[%s] %s", time, msg) + + table.insert(logLines, entry) + if #logLines > maxLines then + table.remove(logLines, 1) + end + + M.draw() +end + +function M.draw() + local w, h = term.getSize() + for i = 1, maxLines do + term.setCursorPos(1, h - maxLines + i) + term.clearLine() + if logLines[i] then + term.write(logLines[i]) + end + end +end + +return M \ No newline at end of file