adjust input render

This commit is contained in:
2025-10-14 19:41:56 +08:00
parent 5a3a404bff
commit d41117cecc

View File

@@ -211,22 +211,21 @@ function drawNode(
term.write(isChecked ? "[X]" : "[ ]"); term.write(isChecked ? "[X]" : "[ ]");
} else { } else {
// Draw text input // Draw text input
let value = ""; let displayText = "";
const valueProp = node.props.value; const valueProp = node.props.value;
if (typeof valueProp === "function") { if (typeof valueProp === "function") {
value = (valueProp as Accessor<string>)(); displayText = (valueProp as Accessor<string>)();
} }
const placeholder = node.props.placeholder as string | undefined; const placeholder = node.props.placeholder as string | undefined;
let cursorPos = node.cursorPos ?? 0; const cursorPos = node.cursorPos ?? 0;
let displayText = value;
let currentTextColor = textColor; let currentTextColor = textColor;
let showPlaceholder = false; let showPlaceholder = false;
const focusedBgColor = bgColor ?? colors.white; const focusedBgColor = bgColor ?? colors.white;
const unfocusedBgColor = bgColor ?? colors.black; const unfocusedBgColor = bgColor ?? colors.black;
if (value === "" && placeholder !== undefined && !focused) { if (displayText === "" && placeholder !== undefined && !focused) {
displayText = placeholder; displayText = placeholder;
showPlaceholder = true; showPlaceholder = true;
currentTextColor = currentTextColor ?? colors.gray; currentTextColor = currentTextColor ?? colors.gray;
@@ -249,7 +248,7 @@ function drawNode(
// Move text if it's too long for the padded area // Move text if it's too long for the padded area
const startDisPos = const startDisPos =
cursorPos >= renderWidth ? textToRender.length - renderWidth : 0; cursorPos >= renderWidth ? cursorPos - renderWidth + 1 : 0;
const stopDisPos = startDisPos + renderWidth; const stopDisPos = startDisPos + renderWidth;
if (focused && !showPlaceholder && cursorBlinkState) { if (focused && !showPlaceholder && cursorBlinkState) {