Make the item list a lot better looking, and add placeholders to
inputBox.
This commit is contained in:
parent
e9cfedea55
commit
3c338f05dd
2 changed files with 24 additions and 15 deletions
|
|
@ -92,23 +92,27 @@ end
|
|||
---@param y number The Y position of the box
|
||||
---@param width number The width/length of the box
|
||||
---@param action function|string A function or `run` event to call when a key is pressed
|
||||
---@param placeholder string|nil A string that's set as the placeholder when nothing is written
|
||||
---@param fgColor color|nil The color of the text (defaults to white)
|
||||
---@param bgColor color|nil The color of the background (defaults to black)
|
||||
---@param placeholderFg color|nil The color of the placeholder text (defaults to lightGray)
|
||||
---@param replacement string|nil A character to replace typed characters with
|
||||
---@param history string[]|nil A list of previous entries to provide
|
||||
---@param completion function|nil A function to call to provide completion
|
||||
function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacement, history, completion, default)
|
||||
function PrimeUI.inputBox(win, x, y, width, action, placeholder, fgColor, bgColor, placeholderFg, replacement, history, completion, default)
|
||||
expect(1, win, "table")
|
||||
expect(2, x, "number")
|
||||
expect(3, y, "number")
|
||||
expect(4, width, "number")
|
||||
expect(5, action, "function", "string")
|
||||
fgColor = expect(6, fgColor, "number", "nil") or colors.white
|
||||
bgColor = expect(7, bgColor, "number", "nil") or colors.black
|
||||
expect(8, replacement, "string", "nil")
|
||||
expect(9, history, "table", "nil")
|
||||
expect(10, completion, "function", "nil")
|
||||
expect(11, default, "string", "nil")
|
||||
expect(6, placeholder, "string", "nil")
|
||||
fgColor = expect(7, fgColor, "number", "nil") or colors.white
|
||||
bgColor = expect(8, bgColor, "number", "nil") or colors.black
|
||||
placeholderFg = expect(9, placeholderFg, "number", "nil") or colors.lightGray
|
||||
expect(10, replacement, "string", "nil")
|
||||
expect(11, history, "table", "nil")
|
||||
expect(12, completion, "function", "nil")
|
||||
expect(13, default, "string", "nil")
|
||||
|
||||
local box = window.create(win, x, y, width, 1)
|
||||
box.setTextColor(fgColor)
|
||||
|
|
@ -134,9 +138,15 @@ function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacemen
|
|||
box.setCursorPos(1, 1)
|
||||
if replacement then
|
||||
box.write(string.rep(replacement, #text))
|
||||
else
|
||||
if #text == 0 and placeholder then
|
||||
box.setTextColor(placeholderFg)
|
||||
box.write(placeholder)
|
||||
box.setTextColor(fgColor)
|
||||
else
|
||||
box.write(text)
|
||||
end
|
||||
end
|
||||
box.setCursorPos(cursor, 1)
|
||||
|
||||
runAction()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ local PrimeUI = require("lib.primeui").PrimeUI;
|
|||
|
||||
local function runUi()
|
||||
local search = ""
|
||||
local win = term.current();
|
||||
local w , h= term.getSize()
|
||||
|
||||
local function getFiltered()
|
||||
local filtered = {}
|
||||
|
|
@ -16,16 +18,13 @@ local function runUi()
|
|||
local refiltered = {}
|
||||
|
||||
for i, filter in ipairs(filtered) do
|
||||
refiltered[i] = filter.name .. " -> " .. tostring(filter.count)
|
||||
refiltered[i] = filter.name .. string.rep(" ", w-(2+#filter.name+#tostring(filter.count))) .. tostring(filter.count)
|
||||
end
|
||||
return refiltered
|
||||
end
|
||||
|
||||
local com = getFiltered("")
|
||||
|
||||
local win = term.current();
|
||||
local w , h= term.getSize()
|
||||
|
||||
PrimeUI.clear()
|
||||
local updateEntries = PrimeUI.selectionBox(
|
||||
win, 1, 4, w, h-7,
|
||||
|
|
@ -45,10 +44,10 @@ local function runUi()
|
|||
search = data
|
||||
com = getFiltered()
|
||||
updateEntries()
|
||||
end)
|
||||
end, "Input a item to search..")
|
||||
|
||||
PrimeUI.label(win, 2, h-1, "primeui ui refucked")
|
||||
PrimeUI.label(win, 2, h-2, "rev. " .. fs.open("storage-solution/version", "r").readAll())
|
||||
PrimeUI.label(win, 2, h-1, "primeui ui refucked", colors.lightGray)
|
||||
PrimeUI.label(win, 2, h-2, "rev. " .. fs.open("storage-solution/version", "r").readAll(), colors.lightGray)
|
||||
|
||||
local timer = os.startTimer(1)
|
||||
PrimeUI.addTask(function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue