From 749040cad159a4221b4dd716a2e542faf0fc241c Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 16 Mar 2025 04:03:25 +0100 Subject: [PATCH] Added replaceChar property for Input (for password input) --- src/elements/Input.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/elements/Input.lua b/src/elements/Input.lua index a0a605d..2286746 100644 --- a/src/elements/Input.lua +++ b/src/elements/Input.lua @@ -28,6 +28,8 @@ Input.defineProperty(Input, "focusedForeground", {default = colors.white, type = Input.defineProperty(Input, "pattern", {default = nil, type = "string"}) ---@property cursorColor number nil Color of the cursor Input.defineProperty(Input, "cursorColor", {default = nil, type = "number"}) +---@property replaceChar string nil Character to replace the input with (for password fields) +Input.defineProperty(Input, "replaceChar", {default = nil, type = "string"}) Input.defineEvent(Input, "mouse_click") Input.defineEvent(Input, "key") @@ -189,6 +191,7 @@ function Input:render() local focusedFg = self.get("focusedForeground") local focused = self.get("focused") local width, height = self.get("width"), self.get("height") + local replaceChar = self.get("replaceChar") self:multiBlit(1, 1, width, height, " ", tHex[focused and focusedFg or self.get("foreground")], tHex[focused and focusedBg or self.get("background")]) if #text == 0 and #placeholder ~= 0 and self.get("focused") == false then @@ -201,6 +204,9 @@ function Input:render() end local visibleText = text:sub(viewOffset + 1, viewOffset + width) + if replaceChar and #replaceChar > 0 then + visibleText = replaceChar:rep(#visibleText) + end self:textFg(1, 1, visibleText, self.get("foreground")) end