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 y number The Y position of the box
|
||||||
---@param width number The width/length 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 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 fgColor color|nil The color of the text (defaults to white)
|
||||||
---@param bgColor color|nil The color of the background (defaults to black)
|
---@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 replacement string|nil A character to replace typed characters with
|
||||||
---@param history string[]|nil A list of previous entries to provide
|
---@param history string[]|nil A list of previous entries to provide
|
||||||
---@param completion function|nil A function to call to provide completion
|
---@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(1, win, "table")
|
||||||
expect(2, x, "number")
|
expect(2, x, "number")
|
||||||
expect(3, y, "number")
|
expect(3, y, "number")
|
||||||
expect(4, width, "number")
|
expect(4, width, "number")
|
||||||
expect(5, action, "function", "string")
|
expect(5, action, "function", "string")
|
||||||
fgColor = expect(6, fgColor, "number", "nil") or colors.white
|
expect(6, placeholder, "string", "nil")
|
||||||
bgColor = expect(7, bgColor, "number", "nil") or colors.black
|
fgColor = expect(7, fgColor, "number", "nil") or colors.white
|
||||||
expect(8, replacement, "string", "nil")
|
bgColor = expect(8, bgColor, "number", "nil") or colors.black
|
||||||
expect(9, history, "table", "nil")
|
placeholderFg = expect(9, placeholderFg, "number", "nil") or colors.lightGray
|
||||||
expect(10, completion, "function", "nil")
|
expect(10, replacement, "string", "nil")
|
||||||
expect(11, default, "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)
|
local box = window.create(win, x, y, width, 1)
|
||||||
box.setTextColor(fgColor)
|
box.setTextColor(fgColor)
|
||||||
|
|
@ -135,7 +139,13 @@ function PrimeUI.inputBox(win, x, y, width, action, fgColor, bgColor, replacemen
|
||||||
if replacement then
|
if replacement then
|
||||||
box.write(string.rep(replacement, #text))
|
box.write(string.rep(replacement, #text))
|
||||||
else
|
else
|
||||||
box.write(text)
|
if #text == 0 and placeholder then
|
||||||
|
box.setTextColor(placeholderFg)
|
||||||
|
box.write(placeholder)
|
||||||
|
box.setTextColor(fgColor)
|
||||||
|
else
|
||||||
|
box.write(text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
box.setCursorPos(cursor, 1)
|
box.setCursorPos(cursor, 1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ local PrimeUI = require("lib.primeui").PrimeUI;
|
||||||
|
|
||||||
local function runUi()
|
local function runUi()
|
||||||
local search = ""
|
local search = ""
|
||||||
|
local win = term.current();
|
||||||
|
local w , h= term.getSize()
|
||||||
|
|
||||||
local function getFiltered()
|
local function getFiltered()
|
||||||
local filtered = {}
|
local filtered = {}
|
||||||
|
|
@ -16,16 +18,13 @@ local function runUi()
|
||||||
local refiltered = {}
|
local refiltered = {}
|
||||||
|
|
||||||
for i, filter in ipairs(filtered) do
|
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
|
end
|
||||||
return refiltered
|
return refiltered
|
||||||
end
|
end
|
||||||
|
|
||||||
local com = getFiltered("")
|
local com = getFiltered("")
|
||||||
|
|
||||||
local win = term.current();
|
|
||||||
local w , h= term.getSize()
|
|
||||||
|
|
||||||
PrimeUI.clear()
|
PrimeUI.clear()
|
||||||
local updateEntries = PrimeUI.selectionBox(
|
local updateEntries = PrimeUI.selectionBox(
|
||||||
win, 1, 4, w, h-7,
|
win, 1, 4, w, h-7,
|
||||||
|
|
@ -45,10 +44,10 @@ local function runUi()
|
||||||
search = data
|
search = data
|
||||||
com = getFiltered()
|
com = getFiltered()
|
||||||
updateEntries()
|
updateEntries()
|
||||||
end)
|
end, "Input a item to search..")
|
||||||
|
|
||||||
PrimeUI.label(win, 2, h-1, "primeui ui refucked")
|
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())
|
PrimeUI.label(win, 2, h-2, "rev. " .. fs.open("storage-solution/version", "r").readAll(), colors.lightGray)
|
||||||
|
|
||||||
local timer = os.startTimer(1)
|
local timer = os.startTimer(1)
|
||||||
PrimeUI.addTask(function()
|
PrimeUI.addTask(function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue