Slide 55
Slide 55 text
let textInput = readTextInput(validate: { !$0.isEmpty },
validationFailed: {
validationFailed = true
let currentPosition = readCursorPos()
writeAt(promptStartLine, 0, ANSIChar.warn)
updateBracketColor(fromLine: promptStartLine, toLine: bottomPos.row, withColor: 11)
writeAt(bottomPos.row, bottomPos.col + 1, validator
?.
failureString
??
"")
moveTo(currentPosition.row, currentPosition.col)
},
onNewCharacter: { char in
if validationFailed {
let currentPosition = readCursorPos()
writeAt(promptStartLine, 0, "◆".foreColor(81).bold)
updateBracketColor(fromLine: promptStartLine, toLine: bottomPos.row, withColor: 81)
moveTo(bottomPos.row, bottomPos.col + 1)
clearToEndOfLine()
moveTo(currentPosition.row, currentPosition.col)
validationFailed = false
}
write("\(isSecureEntry ? "▪" : char)")
},
onDelete: { row, col in moveTo(row, col); deleteChar() },
removePlaceholder: {
moveTo(initialCursorPosition.row, initialCursorPosition.col)
clearToEndOfLine()
},
showPlaceholder: {
write(placeholder.foreColor(244))
moveTo(initialCursorPosition.row, initialCursorPosition.col)
})