From 82381ab48cbe18985a9dc9360197f7f2511c6832 Mon Sep 17 00:00:00 2001 From: woniuzfb <47843848+woniuzfb@users.noreply.github.com> Date: Thu, 21 Mar 2024 23:14:11 +0800 Subject: [PATCH] feat: search in inquirer + keyword support --- src/lhh | 145 ++++++++++++++------------------- utils/inquirer | 215 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 250 insertions(+), 110 deletions(-) diff --git a/src/lhh b/src/lhh index 6d57e08..7e2b273 100644 --- a/src/lhh +++ b/src/lhh @@ -300,7 +300,7 @@ reduce ({adapter,addtime,bookname,category_id,cover,drawing,m,muludir,original,p IFS="${delimiters[1]}" read -r -a result_publish <<< "$m_publish" IFS="${delimiters[1]}" read -r -a result_yd <<< "$m_yd" - local i j + local i j books new_book books_indices for((i=0;i 选择, 确认)\"`${normal}\n\n\n" + fi + inquirer:on_checkbox_input_up + return + fi + if [ "$checkbox_input_page" = true ] then checkbox_input_page=false @@ -424,7 +516,7 @@ inquirer() if [ "$checkbox_input_page_num" -gt "$checkbox_pages_count" ] || [ "$checkbox_input_page_num" -eq $((checkbox_pages_index+1)) ] then checkbox_input_page_num="" - return 0 + return fi checkbox_pages_index=$((checkbox_input_page_num-1)) @@ -516,7 +608,7 @@ inquirer() checkbox_input_page_num="" fi - return 0 + return fi for i in "${!checkbox_list[@]}" @@ -555,6 +647,12 @@ inquirer() } inquirer:on_checkbox_input_space() { + if [ "$checkbox_input_search" = true ] + then + inquirer:on_text_input_ascii + return + fi + local i inquirer:remove_instructions @@ -607,13 +705,80 @@ inquirer() inquirer:on_checkbox_input_ascii() { local key=$1 - case "$key" in - "w" ) inquirer:on_checkbox_input_up;; - "s" ) inquirer:on_checkbox_input_down;; - "a" ) inquirer:on_checkbox_input_left;; - "d" ) inquirer:on_checkbox_input_right;; - [0-9Pp] ) inquirer:on_checkbox_input_page "$1";; - esac + + if [ "$checkbox_input_search" = false ] + then + case "$key" in + "w" ) + inquirer:on_checkbox_input_up + return + ;; + "s" ) + inquirer:on_checkbox_input_down + return + ;; + "a" ) + inquirer:on_checkbox_input_left + return + ;; + "d" ) + inquirer:on_checkbox_input_right + return + ;; + esac + if [ "$key" == "/" ] + then + if [ "$checkbox_pages_count" -eq 1 ] + then + return + fi + + checkbox_input_search=true + text_input="" + current_pos=0 + + tput cub "$(tput cols)" + tput cud $((checkbox_list_perpage-current_index+1)) + + for((i=0;i<=checkbox_list_perpage;i++)); + do + tput el + tput cuu1 + done + + tput el + tput cud1 + + inquirer:print "${green}?${normal} ${bold}${bg_black}${white}输入搜索内容${bold} ${dim}( \xe2\x86\x91 返回)${normal}\n" + + stty -echo + tput cnorm + elif [[ "$key" =~ [0-9Pp] ]] + then + inquirer:on_checkbox_input_page "$key" + fi + return + fi + + inquirer:on_text_input_ascii "$key" + } + + inquirer:on_checkbox_input_not_ascii() { + if [ "$checkbox_input_search" = false ] + then + return + fi + + inquirer:on_text_input_not_ascii "$1" + } + + inquirer:on_checkbox_input_backspace() { + if [ "$checkbox_input_search" = false ] + then + return + fi + + inquirer:on_text_input_backspace } inquirer:_checkbox_input() { @@ -627,7 +792,8 @@ inquirer() checkbox_selected_options=("${checkbox_list[@]}") checkbox_selected_indices=(0) - return 0 + inquirer:print "${green}?${normal} ${bold}${bg_black}${white}${prompt} ${bg_black}${cyan}$(inquirer:join checkbox_selected_options)${normal}\n" + return fi checkbox_selected=() @@ -721,7 +887,7 @@ inquirer() tput cuu $checkbox_page_list_count - inquirer:on_keypress inquirer:on_checkbox_input_up inquirer:on_checkbox_input_down inquirer:on_checkbox_input_space inquirer:on_checkbox_input_enter inquirer:on_checkbox_input_left inquirer:on_checkbox_input_right inquirer:on_checkbox_input_ascii + inquirer:on_keypress inquirer:on_checkbox_input_up inquirer:on_checkbox_input_down inquirer:on_checkbox_input_space inquirer:on_checkbox_input_enter inquirer:on_checkbox_input_left inquirer:on_checkbox_input_right inquirer:on_checkbox_input_ascii inquirer:on_checkbox_input_backspace inquirer:on_checkbox_input_not_ascii } inquirer:checkbox_input() { @@ -751,7 +917,7 @@ inquirer() inquirer:on_sort_up() { if [ "${#sort_options[@]}" -eq 1 ] then - return 0 + return fi tput cub "$(tput cols)" @@ -775,7 +941,7 @@ inquirer() inquirer:on_sort_down() { if [ "${#sort_options[@]}" -eq 1 ] then - return 0 + return fi tput cub "$(tput cols)" @@ -799,7 +965,7 @@ inquirer() inquirer:on_sort_move_up() { if [ "${#sort_options[@]}" -eq 1 ] then - return 0 + return fi local i @@ -834,7 +1000,7 @@ inquirer() inquirer:on_sort_move_down() { if [ "${#sort_options[@]}" -eq 1 ] then - return 0 + return fi local i @@ -951,7 +1117,7 @@ inquirer() if [ "${#list_options[@]}" -eq 1 ] then - return 0 + return fi tput cub "$(tput cols)" @@ -977,7 +1143,7 @@ inquirer() if [ "${#list_options[@]}" -eq 1 ] then - return 0 + return fi tput cub "$(tput cols)" @@ -1030,7 +1196,7 @@ inquirer() if [ "${#list_options[@]}" -eq 1 ] then - return 0 + return fi first_keystroke=true @@ -1235,7 +1401,7 @@ inquirer() } inquirer:text_input_default_validator() { - return 0 + return } inquirer:text_input() { @@ -1276,7 +1442,7 @@ inquirer() then return 1 fi - return 0 + return } inquirer:remove_date_instructions() { @@ -1345,7 +1511,7 @@ inquirer() case $current_pos in 3) local year=$((${date_pick:0:4}-1)) - [ "$year" -eq 2020 ] && return 0 + [ "$year" -eq 2020 ] && return date_pick="$year${date_pick:4}" ;; 6) @@ -1592,6 +1758,7 @@ inquirer() checkbox_page_select_all=true \ checkbox_input_page=false \ checkbox_input_page_num \ + checkbox_input_search=false \ checkbox_pages_tip \ checkbox_pages_arrows="\xe2\x9d\xae\xe2\x9d\xaf" \ checkbox_pages_index=0 \