From 20e844488abb986aabf36f5d8b5ede97b28ec4cb Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Sun, 2 Jun 2024 16:58:30 +0200 Subject: [PATCH] Fix aligning in orders, rename function --- orders.lua | 12 +++++++----- requests.lua | 4 ++-- winhlp.lua | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/orders.lua b/orders.lua index b3c2a79..86e98c7 100644 --- a/orders.lua +++ b/orders.lua @@ -49,13 +49,14 @@ local function drawEntry(win, obj) win.write(obj.pos.x .. "," .. obj.pos.y .. "," .. obj.pos.z) win.write(" ") end + local padding if obj.res_status then - winhlp.alignRight(win, #obj.res_status + 4) + padding = winhlp.alignRightPadding(win, #obj.res_status + 4) win.write(" " .. obj.res_status) else - winhlp.alignRight(win, 3) + padding = winhlp.alignRightPadding(win, 3) end - win.write(" ") + win.write(string.format("%" .. padding+1 .. "s", " ")) if obj.claimed then win.setTextColor(colors.green) win.write("C") @@ -66,8 +67,9 @@ local function drawEntry(win, obj) win.setTextColor(colors.gray) win.setCursorPos(1, 2) if obj.target then - winhlp.alignRight(win, #obj.target + 1) - win.write(" " .. obj.target) + padding = winhlp.alignRightPadding(win, #obj.target + 1) + win.write(string.format("%" .. padding+1 .. "s", " ")) + win.write(obj.target) end win.setTextColor(colors.white) win.setCursorPos(1, 2) diff --git a/requests.lua b/requests.lua index a147f61..480b451 100644 --- a/requests.lua +++ b/requests.lua @@ -64,7 +64,7 @@ local function drawLine(termlike, obj) termlike.write(" ") if obj.answer == nil then termlike.setTextColor(colors.orange) - local padding = winhlp.alignRight(termlike, 5) + local padding = winhlp.alignRightPadding(termlike, 5) termlike.write(string.format("%" .. padding+5 .. "s", " N/A ")) else if permset.has(allowed_items, obj.answer.name) then @@ -74,7 +74,7 @@ local function drawLine(termlike, obj) end termlike.write(obj.answer.name) termlike.setTextColor(colors.white) - local padding = winhlp.alignRight(termlike, 5) + local padding = winhlp.alignRightPadding(termlike, 5) termlike.write(string.format("%" .. padding+2 .. "s", " [")) if permset.has(allowed_items, obj.answer.name) then termlike.setTextColor(colors.green) diff --git a/winhlp.lua b/winhlp.lua index d1e19e7..fb4fd38 100644 --- a/winhlp.lua +++ b/winhlp.lua @@ -15,7 +15,7 @@ local function setHeight(win, height) win.reposition(winX, winY, sizeX, height) end -local function alignRight(termlike, length) +local function alignRightPadding(termlike, length) local tw, th = termlike.getSize() local x, y = termlike.getCursorPos() termlike.setCursorPos(math.min(x, tw-length+1), y) @@ -27,5 +27,5 @@ return { translate=translate, contains=contains, setHeight=setHeight, - alignRight=alignRight, + alignRightPadding=alignRightPadding, }