Skip to content

Commit 6ef822c

Browse files
committed
♻️ changed the parameter of some log func
1 parent dc8e420 commit 6ef822c

29 files changed

Lines changed: 156 additions & 663 deletions

commands.d/self-build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function extractCommandDefinitionsToVariables() {
283283

284284
if log::isTraceEnabled; then
285285
log::trace "Extracting command definition for:"
286-
log::printFileString "${content%%$'\n'*}"
286+
log::printFileString content
287287
fi
288288

289289
selfBuild_extractCommandDefinitionToVariables "${content}"
@@ -320,8 +320,9 @@ function extractCommandDefinitionsToVariables() {
320320
if log::isTraceEnabled; then
321321
# shellcheck disable=SC2086
322322
exe::captureOutput declare -p ${!TEMP_CMD_BUILD_*}
323+
local declaredVariables="${RETURNED_VALUE}"
323324
log::trace "Declared variables for this command:"
324-
log::printFileString "${RETURNED_VALUE}"
325+
log::printFileString declaredVariables
325326
fi
326327

327328
# verify that the command definition is valid

commands.d/self-document.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ function selfDocument::getAllFunctionsDocumentation() {
138138
local IFS=$'\n'
139139
if log::isDebugEnabled; then
140140
log::debug "Analyzing the following files:"
141-
log::printFileString "${filesToAnalyze[*]}"
141+
local file
142+
for file in "${filesToAnalyze[@]}"; do
143+
log::printString "- ${file}"
144+
done
142145
fi
143146

144147
unset -v RETURNED_ASSOCIATIVE_ARRAY SORTED_FUNCTION_NAMES
@@ -188,7 +191,8 @@ function selfDocument::getAllFunctionsDocumentation() {
188191
local key
189192
for key in "${!RETURNED_ASSOCIATIVE_ARRAY[@]}"; do
190193
log::trace "Function: ⌜${key}"
191-
log::printFileString "${RETURNED_ASSOCIATIVE_ARRAY[${key}]}"
194+
local documentationString="${RETURNED_ASSOCIATIVE_ARRAY[${key}]}"
195+
log::printFileString documentationString
192196
done
193197
fi
194198

commands.d/self-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function selfRelease::createRelease() {
184184
done
185185
IFS=$' '
186186
log::info "The tag message is:"
187-
log::printFileString "${tagMessage}"
187+
log::printFileString tagMessage
188188

189189
if [[ "${uploadExistingTag:-}" != "true" ]]; then
190190

libraries.d/core

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -498,30 +498,31 @@ function log::printFile() {
498498
# Display a file content with line numbers in the logs.
499499
# The file content will be aligned with the current log output and hard wrapped if necessary.
500500
#
501-
# - $1: **content** _as string_:
502-
# the file content.
501+
# - $1: **content variable name** _as string_:
502+
# The name of the variable containing the file content to print.
503503
# - $2: max lines _as int_:
504504
# (optional) Can be set using the variable `_OPTION_MAX_LINES`.
505505
# Max lines to display, can be set to 0 to display all lines.
506506
# (defaults to 0)
507507
#
508508
# ```bash
509-
# log::printFileString "myfilecontent"
509+
# log::printFileString "myvar"
510510
# ```
511511
#
512512
# > This function is not at all suited for large strings, print the content to a file instead.
513513
# shellcheck disable=SC2317
514514
function log::printFileString() {
515-
local content="${1?"The function ⌜${FUNCNAME:-?}⌝ requires more than $# arguments."}"
515+
local -n contentToPrint="${1?"The function ⌜${FUNCNAME:-?}⌝ requires more than $# arguments."}"
516516
local -i maxLines="${2:-${_OPTION_MAX_LINES:-0}}"
517517

518518
local line toPrint lineNumberPadding=" "
519519
local -i lineNumber=1 currentLineNumberLength=1
520-
while (( ${#content} > 0 )); do
521-
line="${content%%$'\n'*}"
522-
content="${content:${#line} + 1}"
520+
521+
local IFS
522+
while IFS=$'\n' read -rd $'\n' line; do
523523
log::printFileInternalLoop || break;
524-
done
524+
done <<<"${contentToPrint}"
525+
525526
# evaluated the print statement built in log::init; it uses the local var toPrint defined above
526527
eval "${GLOBAL_LOG_PRINT_STATEMENT_STANDARD}"
527528
}
@@ -629,8 +630,8 @@ function log::saveFile() {
629630
# (using `core::createNewStateFilePath`).
630631
# Useful for debugging purposes, to save the state of a string during execution.
631632
#
632-
# - $1: **content** _as string_:
633-
# The content to save.
633+
# - $1: **content variable name** _as string_:
634+
# The variable name of the content to save.
634635
# - $2: **suffix** _as string_:
635636
# The suffix to add to the file name.
636637
# - $3: log path _as bool_:
@@ -645,12 +646,12 @@ function log::saveFile() {
645646
# log::saveFileString "my content" "suffix" "important result file"
646647
# ```
647648
function log::saveFileString() {
648-
local content="${1?"The function ⌜${FUNCNAME:-?}⌝ requires more than $# arguments."}"
649+
local -n contentToSave="${1?"The function ⌜${FUNCNAME:-?}⌝ requires more than $# arguments."}"
649650
local suffix="${2?"The function ⌜${FUNCNAME:-?}⌝ requires more than $# arguments."}"
650651
local logPath="${3:-"true"}"
651652
core::createNewStateFilePath "${suffix}"
652653
local newFilePath="${RETURNED_VALUE}"
653-
printf '%s' "${content}" >"${newFilePath}"
654+
printf '%s' "${contentToSave}" >"${newFilePath}"
654655
if [[ ${logPath} == "true" ]]; then
655656
log::printString "${newFilePath}"
656657
fi
@@ -662,17 +663,17 @@ function log::saveFileString() {
662663
# Display something in the log stream.
663664
# Does not check the log level.
664665
#
665-
# - $1: **content** _as string_:
666-
# the content to print (can contain new lines)
666+
# - $1: **content variable name** _as string_:
667+
# The variable name containing the content to print (can contain new lines).
667668
#
668669
# ```bash
669670
# log::printRaw "my line"
670671
# ```
671672
# shellcheck disable=SC2317
672673
function log::printRaw() {
673-
local IFS=$'\n'
674+
local -n toPrint="${1?"The function ⌜${FUNCNAME:-?}⌝ requires more than $# arguments."}"
674675
# shellcheck disable=SC2034
675-
local toPrint="$*"
676+
676677
# evaluated the print statement built in log::init; it uses the local var toPrint defined above
677678
eval "${GLOBAL_LOG_PRINT_STATEMENT_STANDARD}"
678679
}

libraries.d/lib-curl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function curl::download() {
7676
exitCode=1
7777
if log::isDebugEnabled || [[ ${failIfFails} == "true" ]]; then
7878
log::errorTrace "Curl error output stream:"
79-
log::printFileString "${errors}"
79+
log::printFileString errors
8080
fi
8181
local message="The http return code ⌜${httpStatusCode}⌝ is not acceptable for url ⌜${url}⌝."
8282
if [[ ${failIfFails} == "true" ]]; then

libraries.d/lib-exe

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function exe::invokef5() {
7070
log::saveFile "${stdIn}" "${executable^}-stdin"
7171
else
7272
log::trace "${executable^} standard input from string:"
73-
log::saveFileString "${stdIn}" "${executable^}-stdin"
73+
log::saveFileString stdIn "${executable^}-stdin"
7474
fi
7575
else
7676
log::trace "No standard input."

libraries.d/lib-http

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ function http::request() {
173173
if (( exitCode != 0 )); then
174174
if log::isDebugEnabled || [[ ${failOnError} == "true" ]]; then
175175
log::errorTrace "HTTP response:"
176-
log::printFileString "${headers}"$'\n'"${body:-}"
176+
log::printString "${headers}"$'\n'"${body:-}"
177177
fi
178178
local message="The HTTP return code ⌜${httpCode}⌝ is not acceptable for url ⌜${url}⌝."
179179
if [[ ${failOnError} == "true" ]]; then

libraries.d/lib-multi-line-prompt

Lines changed: 0 additions & 97 deletions
This file was deleted.

libraries.d/lib-prompt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

libraries.d/lib-sfzf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ source tui
1111
source exe
1212
# shellcheck source=lib-array
1313
source array
14+
# shellcheck source=lib-list
15+
source list
1416

1517
#===============================================================
1618
# >>> Customization
@@ -361,6 +363,9 @@ function drawLeftPane() {
361363
toPrint+="${ESC__CURSOR_MOVE__}$((SFZF_LEFT_PANE_FIRST_LINE + 1));$((SFZF_LEFT_PANE_WIDTH - itemCounterLength))${__ESC__TO}${itemsCounter}"
362364
fi
363365

366+
_PROMPT_ITEMS_BOX_ITEM_WIDTH=$((SFZF_LEFT_PANE_WIDTH - 3))
367+
_PROMPT_ITEMS_BOX_FILTER_STRING="${SFZF_SEARCH_STRING}"
368+
364369
# draw the items
365370
local itemPrefix
366371
local -i index line=${SFZF_LEFT_PANE_FIRST_CONTENT_LINE}
@@ -372,7 +377,10 @@ function drawLeftPane() {
372377
else
373378
itemPrefix=" "
374379
fi
375-
toPrint+="${ESC__CURSOR_MOVE__}${line};${SFZF_LEFT_PANE_WIDTH}${__ESC__TO}${ESC__ERASE_CHARS_LEFT}"$'\r'"${itemPrefix}${SFZF_FILTERED_ITEMS[index]}${SFZF_COLOR_SELECTED_ITEM_RESET}"
380+
381+
_PROMPT_ITEMS_BOX_ITEM_DISPLAYED="${SFZF_FILTERED_ITEMS[index]}"
382+
list::getItemDisplayedString
383+
toPrint+="${ESC__CURSOR_MOVE__}${line};${SFZF_LEFT_PANE_WIDTH}${__ESC__TO}${ESC__ERASE_CHARS_LEFT}"$'\r'"${itemPrefix}${_PROMPT_ITEMS_BOX_ITEM_DISPLAYED}${SFZF_COLOR_SELECTED_ITEM_RESET}"
376384
line+=1
377385
done
378386

0 commit comments

Comments
 (0)