From cb4135a7a74a45158294e7af15f867e8b422d86a Mon Sep 17 00:00:00 2001 From: Peter Nerlich Date: Thu, 12 Nov 2020 10:14:44 +0100 Subject: [PATCH] use text verbatim if it fits on the screen --- lcd.lua | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lcd.lua b/lcd.lua index 8cee9b7..c0cdf41 100644 --- a/lcd.lua +++ b/lcd.lua @@ -34,23 +34,27 @@ local create_lines = function(text) local line = "" local line_num = 1 local tab = {} - for word in string.gmatch(text, "%S+") do - if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then - if line ~= "" then - line = line.." "..word + if #text <= LINE_LENGTH then + line = text + else + for word in string.gmatch(text, "%S+") do + if string.len(line)+string.len(word) < LINE_LENGTH and word ~= "|" then + if line ~= "" then + line = line.." "..word + else + line = word + end else - line = word - end - else - table.insert(tab, line) - if word ~= "|" then - line = word - else - line = "" - end - line_num = line_num+1 - if line_num > NUMBER_OF_LINES then - return tab + table.insert(tab, line) + if word ~= "|" then + line = word + else + line = "" + end + line_num = line_num+1 + if line_num > NUMBER_OF_LINES then + return tab + end end end end