From 1edef403422c8ad1ccc917cfba6d8d9c96e60978 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sun, 16 Jan 2022 23:37:50 +0100 Subject: [PATCH] Add possibility to -h to display info only for one specified step New way to display step arguments by moving the cursor around with escape sequences --- sequencer/sequencer.sh | 70 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index 657dbee..066fdff 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -7,8 +7,8 @@ ## Version information -VERSION_REV=13 -VERSION_MAJOR=3 +VERSION_REV=14 +VERSION_MAJOR=0 VERSION_MINOR=0 ## Start of generic script part @@ -24,6 +24,7 @@ STEP_RETURN=255 MAX_STEP=512 ALIAS= CONTEXT_HELP=0 +CONTEXT_EXE=0 SEQ_CONFIG_EDIT=0 SEQ_CONFIG_NAME=".seqs" SEQ_CONFIG_FILE= @@ -53,6 +54,10 @@ LIGHTCYAN= ; [ -t 1 ] && LIGHTCYAN='\033[1;36m' LIGHTGRAY= ; [ -t 1 ] && LIGHTGRAY='\033[0;37m' WHITE= ; [ -t 1 ] && WHITE='\033[1;37m' NC= ;[ -t 1 ] && NC='\033[0m' # No Color +SAVE_POS_ALIAS= ;[ -t 1 ] && SAVE_POS_ALIAS='\033[1A\033[1C\033[s\033[1B\033[1C' +SAVE_POS_EXE= ;[ -t 1 ] && SAVE_POS_EXE='\033[s' +SAVE_POS= ;[ -t 1 ] && SAVE_POS='\033[3D\033[s\033[3C' +RESTORE_POS= ;[ -t 1 ] && RESTORE_POS='\033[u' helpSequencer() { cat < [DESCRIPTION]${NC}" @@ -309,12 +321,22 @@ outColor() { # Echo additional line to info correctly indented INDENT_HELP=' : ' INDENTAPPEND_HELP=' ' -INDENTAPPEND_INFO=' ' echoinfo() { if [ $CONTEXT_HELP -ne 0 ] ; then printf '%s' "$INDENTAPPEND_HELP"; echo "$@" else - printf '%s' "$INDENTAPPEND_INFO"; echo "$@" + echo -ne "${RESTORE_POS}"; echo "$@" + fi +} + +# Echo info about step arguments +# Needs to be called first in _info() function +echoinfoArgs() { + echo -e "${RESTORE_POS}$@" + if [ $CONTEXT_EXE -ne 0 ]; then + echo -ne "${RESTORE_POS}" + else + printf '%s' "$INDENT_HELP" fi } @@ -685,10 +707,12 @@ execute() { fi if [ $QUIET -ne 2 ] ; then - echo -en "\n [STEP $1] " + echo -en "\n [STEP $1] ${SAVE_POS_EXE}" existsFunction step_${1}_info if [ $? -eq 0 ] ; then + CONTEXT_EXE=1 step_${1}_info $1 "${STEP_ARGS[@]}" + CONTEXT_EXE=0 outColor else # Add newline if no info is given @@ -910,11 +934,15 @@ parseAlias() { done } -# displayHelp [NO TEMPLATE] +# displayHelp [NO TEMPLATE] [STEP NUMBER OR ALIAS] # [NO TEMPLATE] # 0 (default) : Ask for template creation # 1 : Do not ask for template creation -# - Always display sequencer help and, if available, sequence help +# [STEP NUMBER OR ALIAS] +# [NO TEMPLATE] must be set +# Display step info function only for given step +# +# - Display sequencer help and, if available, sequence help # - Cluster continous (more than 1) steps visually together displayHelp() { local i @@ -923,8 +951,24 @@ displayHelp() { local lastClusterSize=0 local createTemplate=1 local stepsFound=0 + local loopStart=0 + local loopEnd=${MAX_STEP} CONTEXT_HELP=1 - helpSequencer + + # check if help is requested for a single step + if [ ! -z "$2" ]; then + parseAlias + checkStep "$2" + loopStart=$? + fi + + if [ "$loopStart" == "0" ]; then + helpSequencer + loopStart=1 + else + # Output loop only for one step + loopEnd=$loopStart + fi if [ ! -z $1 ] && [ $1 -eq 1 ] ; then createTemplate=0 @@ -961,7 +1005,7 @@ displayHelp() { exit 1; else echo -e "\n Step (= alias) documentation:" - for ((i=1; i<=${MAX_STEP}; i++)); do + for ((i=$loopStart; i<=$loopEnd; i++)); do # Display step reference in help if step function exists existsFunction step_${i} @@ -983,10 +1027,10 @@ displayHelp() { existsFunction step_${i}_alias if [ $? -eq 0 ] ; then step_${i}_alias - echo -e " = ${ORANGE}$ALIAS${NC}" + echo -e " = ${ORANGE}$ALIAS${NC}${SAVE_POS_ALIAS}" printf '%s' "$INDENT_HELP" else - echo -n " : " + echo -en " : ${SAVE_POS}" fi # Display step help only if info function exists @@ -1095,7 +1139,7 @@ main() { SEQUENCER_ARGS+=" $1" shift;; --help|-h) # show only help - displayHelp 1 + displayHelp 1 "$2" exit 0;; --helpapi|-ha) #show build-in functions helpApi