Skip to content

Commit

Permalink
✨ awesome prompt!
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Feb 4, 2025
1 parent 584ab00 commit 589e4a7
Show file tree
Hide file tree
Showing 16 changed files with 512 additions and 262 deletions.
1 change: 0 additions & 1 deletion docs/content/docs/800.roadmap/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This page lists the features that I would like to implement in Valet. They come
- prompt:
- Finish prompt and interactive functions: prompt user for multiline text (doable with by just implementing a good _PROMPT_CALLBACK_FUNCTION_ON_ITEM_DISPLAY)
- Prompt user for multi select.
- prompt: add the possibility to position the autocompletion box (top/left/width/height)
- Add a full screen view with the keyboard shortcuts in edit mode (new interactive::showFullScreenHelp ?).
- fzf:
- draw in a given rectangle, we handle full screen or not before calling sfzf
Expand Down
3 changes: 2 additions & 1 deletion libraries.d/lib-ansi-codes
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ __AC__SCROLL_DOWN=$'T'
# Reports the cursor position to the application as (as ESC[n;mR), where n is the line and m is the column.
AC__REQUEST_CURSOR_POSITION=$'\e[6n'

# About AC__ERASE*: try not to use them to clear characters that you will immediately rewrite
# because it will cause flickering, use it to actually get empty space.
# erase in display or line
# clear from cursor to end of screen
AC__ERASE_LINES_BELOW=$'\e[0J'
Expand All @@ -155,7 +157,6 @@ AC__ERASE_CHARS_RIGHT=$'\e[0K'
AC__ERASE_CHARS_LEFT=$'\e[1K'
# clear entire line
AC__ERASE_LINE=$'\e[2K'

# Erase a set number of characters "${AC__ERASE__}2${__AC_CHARS}"
AC__ERASE__=$'\e['
__AC_CHARS=$'X'
Expand Down
46 changes: 0 additions & 46 deletions libraries.d/lib-fs
Original file line number Diff line number Diff line change
Expand Up @@ -555,43 +555,6 @@ function fs::createLink() {
log::debug "Created ${linkType} link: ⌜${linkedPath}⌝ ← ⌜${linkPath}⌝."
}

# ## fs::getFileMaxLineLength
#
# Get the maximum line length of a file.
#
# - $1: **path** _as string_:
# the file path to read
#
# Returns:
#
# - ${RETURNED_VALUE}: The maximum line length of the file.
#
# ```bash
# fs::getFileMaxLineLength "/path/to/file"
# local maxLineLength="${RETURNED_VALUE}"
# ```
function fs::getFileMaxLineLength() {
local filePath="${1}"

if [[ ${VALET_CONFIG_STRICT_PURE_BASH:-false} != "true" ]] && command -v awk &>/dev/null; then
# shellcheck source=lib-exe
source exe
exe::captureOutput awk 'BEGIN { maxLength = 0 } { if (length > maxLength) maxLength = length } END { print maxLength }' "${filePath}"
RETURNED_VALUE=${RETURNED_VALUE%%[[:space:]]}
return 0
fi

local -i maxLineLength=0 currentLineLength=0
local IFS=$'\n'
while read -rd $'\n' || [[ -n ${REPLY:-} ]]; do
currentLineLength=${#REPLY}
if (( currentLineLength > maxLineLength )); then
maxLineLength=${currentLineLength}
fi
done <"${filePath}"
RETURNED_VALUE="${maxLineLength}"
}

# ## fs::getFileLineCount
#
# Get the number of lines in a file.
Expand All @@ -609,15 +572,6 @@ function fs::getFileMaxLineLength() {
# ```
function fs::getFileLineCount() {
local filePath="${1}"

if [[ ${VALET_CONFIG_STRICT_PURE_BASH:-false} != "true" ]] && command -v awk &>/dev/null; then
# shellcheck source=lib-exe
source exe
exe::captureOutput awk 'END { print NR }' "${filePath}"
RETURNED_VALUE=${RETURNED_VALUE%%[[:space:]]}
return 0
fi

local -i lineCount=0
while read -rd $'\n' || [[ -n ${REPLY:-} ]]; do
((lineCount++))
Expand Down
14 changes: 7 additions & 7 deletions libraries.d/lib-interactive
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function interactive::displayAnswer() {
# ```bash
# interactive::displayDialogBox "system" "This is a system message."
# ```
interactive::displayDialogBox() {
function interactive::displayDialogBox() {
local speaker="${1}"
local text="${2}"
local requiredMaxTextWidth="${3:-${GLOBAL_COLUMNS}}"
Expand All @@ -313,11 +313,11 @@ interactive::displayDialogBox() {
local -i lineNumber=0 maxLineLength=0
local IFS=$'\n'

for line in ${wrappedText}; do
while read -r line; do
if (( ${#line} > maxLineLength )); then
maxLineLength=${#line}
fi
done
done <<<"${wrappedText}"
textWidth=${maxLineLength}

if [[ ${speaker} == "user" ]]; then
Expand All @@ -328,29 +328,29 @@ interactive::displayDialogBox() {
startColumn+=1

finalString+="${AC__TEXT_FAINT}${AC__CURSOR_MOVE__}${startColumn}${__AC__COLUMN}┌─${AC__REPEAT__}${textWidth}${__AC__LAST_CHAR}─┐${AC__TEXT_RESET}"$'\n'
for line in ${wrappedText}; do
while read -r line; do
if (( lineNumber == 0 )); then
sideString="├──░"
else
sideString=""
fi
finalString+="${AC__TEXT_FAINT}${AC__CURSOR_MOVE__}${startColumn}${__AC__COLUMN}${AC__TEXT_RESET} ${line} ${AC__CURSOR_MOVE__}$((textWidth + 3 + startColumn))${__AC__COLUMN}${AC__TEXT_FAINT}${sideString}${AC__TEXT_RESET}"$'\n'
lineNumber+=1
done
done <<<"${wrappedText}"
finalString+="${AC__TEXT_FAINT}${AC__CURSOR_MOVE__}${startColumn}${__AC__COLUMN}└─${AC__REPEAT__}${textWidth}${__AC__LAST_CHAR}─┘${AC__TEXT_RESET}"$'\n'

elif [[ ${speaker} == "system" ]]; then

finalString+="${AC__TEXT_FAINT} ┌─${AC__REPEAT__}${textWidth}${__AC__LAST_CHAR}─┐${AC__TEXT_RESET}"$'\n'
for line in ${wrappedText}; do
while read -r line; do
if (( lineNumber == 0 )); then
sideString="░──┤"
else
sideString=""
fi
finalString+="${AC__TEXT_FAINT}${sideString}${AC__TEXT_RESET} ${line} ${AC__CURSOR_MOVE__}$((textWidth + 7))${__AC__COLUMN}${AC__TEXT_FAINT}${AC__TEXT_RESET}"$'\n'
lineNumber+=1
done
done <<<"${wrappedText}"
finalString+="${AC__TEXT_FAINT} └─${AC__REPEAT__}${textWidth}${__AC__LAST_CHAR}─┘${AC__TEXT_RESET}"$'\n'

fi
Expand Down
Loading

0 comments on commit 589e4a7

Please sign in to comment.