@@ -1239,3 +1239,96 @@ function prompt_getDisplayedPromptString() {
12391239 RETURNED_VALUE2=${screenIndex}
12401240}
12411241
1242+
1243+ # Clear the multi-line prompt
1244+ function prompt_clearMultiLinePrompt() {
1245+ tui::clearBox " ${_PROMPT_START_LINE} " " ${_PROMPT_START_COLUMN} " " ${_PROMPT_WIDTH} " " ${_PROMPT_NB_PROMPT_LINES} "
1246+ }
1247+
1248+ function prompt_drawMultiLinePrompt() {
1249+ # we need to draw the prompt on multiple lines
1250+ local promptLines=()
1251+ local promptLinesStartIndex=()
1252+ prompt_drawMultiLinePromptRefreshLines _PROMPT_STRING
1253+
1254+ prompt_getMultiLinePrompt
1255+ printf ' %s' " ${ESC__CURSOR_HIDE}${ESC__CURSOR_MOVE__}${_PROMPT_START_LINE} ;${_PROMPT_START_COLUMN}${__ESC__TO}${RETURNED_VALUE}${ESC__CURSOR_MOVE__}${GLOBAL_CURSOR_LINE} ;${GLOBAL_CURSOR_COLUMN}${__ESC__TO}${ESC__CURSOR_SHOW} "
1256+ }
1257+
1258+ function prompt_drawMultiLinePromptRefreshLines() {
1259+ local -n textToWrapAtWords=" ${1} "
1260+
1261+ local -i linesIndex=0
1262+
1263+ # short cut in case the text is already shorter than the width
1264+ if [[ ${# textToWrapAtWords} -le ${_PROMPT_STRING_SCREEN_WIDTH} && ${textToWrapAtWords} != * $' \n ' * ]]; then
1265+ RETURNED_VALUE=" ${textToWrapAtWords} "
1266+ return 0
1267+ fi
1268+
1269+ local text=" ${textToWrapAtWords} "
1270+ local IFS=$' \t ' line word realWord RETURNED_VALUE2
1271+ local -i realWordLength=0 firstWord=1
1272+ local -i lineLength=0
1273+
1274+ while (( ${# text} > 0 )) ; do
1275+ line=" ${text%% $' \n ' * } "
1276+ text=" ${text: ${# line} +1} "
1277+
1278+ output+=$' \n ' " "
1279+
1280+ # short cut in case the text is already shorter than the width
1281+ if (( lineLength + ${# line} <= _PROMPT_STRING_SCREEN_WIDTH)) ; then
1282+ output+=" ${line} "
1283+ continue
1284+ fi
1285+
1286+ firstWord=1
1287+
1288+ for word in ${line} ; do
1289+ if [[ ${word} == * $' \e ' * ]]; then
1290+ realWord=" ${word// $' \e [' [0-9][0-9]m/ } "
1291+ realWord=" ${realWord// $' \e [' [0-9]m/ } "
1292+ realWordLength=" ${# realWord} "
1293+ else
1294+ realWordLength=" ${# word} "
1295+ fi
1296+
1297+ if (( lineLength < _PROMPT_STRING_SCREEN_WIDTH && firstWord == 0 )) ; then
1298+ output+=" "
1299+ lineLength+=1
1300+ else
1301+ firstWord=0
1302+ fi
1303+
1304+ if (( lineLength + realWordLength <= _PROMPT_STRING_SCREEN_WIDTH)) ; then
1305+ # add the word to the current line
1306+ output+=" ${word} "
1307+ lineLength+=realWordLength
1308+ else
1309+ # not enough space left, check if the word fits on the next line
1310+ if (( realWordLength <= _PROMPT_STRING_SCREEN_WIDTH)) ; then
1311+ output+=$' \n ' " ${word} "
1312+ lineLength=realWordLength
1313+ else
1314+ # the word is too long to fit on a line, split it in multiple lines
1315+ string::wrapCharacters word " ${_PROMPT_STRING_SCREEN_WIDTH} " " " " $(( _PROMPT_STRING_SCREEN_WIDTH - lineLength)) "
1316+ output+=" ${RETURNED_VALUE} "
1317+ lineLength=${RETURNED_VALUE2}
1318+ fi
1319+ fi
1320+
1321+ done
1322+
1323+ lineLength=0
1324+ done
1325+
1326+ RETURNED_VALUE=" ${output# $' \n ' " " } "
1327+
1328+
1329+
1330+ string::wrapWords _PROMPT_STRING " ${_PROMPT_STRING_SCREEN_WIDTH} " " " " $(( _PROMPT_STRING_SCREEN_WIDTH - _PROMPT_SYMBOL_LENGTH)) "
1331+
1332+ prompt_getMultiLinePrompt
1333+ printf ' %s' " ${ESC__CURSOR_HIDE}${ESC__CURSOR_MOVE__}${_PROMPT_START_LINE} ;${_PROMPT_START_COLUMN}${__ESC__TO}${RETURNED_VALUE}${ESC__CURSOR_MOVE__}${GLOBAL_CURSOR_LINE} ;${GLOBAL_CURSOR_COLUMN}${__ESC__TO}${ESC__CURSOR_SHOW} "
1334+ }
0 commit comments