mirror of
https://github.com/SikongJueluo/cc-utils.git
synced 2025-12-20 13:37:49 +08:00
adjust input render
This commit is contained in:
@@ -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;
|
||||||
@@ -245,11 +244,11 @@ function drawNode(
|
|||||||
term.setCursorPos(x + 1, y); // Position cursor for text after padding
|
term.setCursorPos(x + 1, y); // Position cursor for text after padding
|
||||||
|
|
||||||
const renderWidth = width - 1;
|
const renderWidth = width - 1;
|
||||||
const textToRender = displayText + " ";
|
const textToRender = displayText + " ";
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user