diff -up a/iron b/iron --- a/iron 2022-09-24 11:53:05.582410603 +0200 +++ b/iron 2022-09-24 13:39:33.092900858 +0200 @@ -114,6 +114,8 @@ IRON_INIT() $0 && IRON_EXIT fi + basedir=$(pwd) + # check connection ping -q "1.1.1.1" -c 1 > /dev/null || IRON_FAIL_NOT_CONNECTED @@ -277,6 +279,17 @@ IRON_PRINT_MESSAGES() done fi + # apply hidden messages patch created + if [ "$haspatched" != "true" ]; then + if [ -e "$WDIR/iron-hiddenmessages.diff" ]; then + basedir=$(pwd) + cd $WDIR + patch -fs < $WDIR/iron-hiddenmessages.diff || FAIL_PATCH_DID_NOT_APPLY + haspatched=true + cd $basedir + fi + fi + # get the number of messages we need from the parsed list of stuff fold -w${SEPCOUNT} $WDIR/iron-messagedata | head -n $LINECOUNT printf "${COLOR_01}$FSEP" @@ -285,6 +298,78 @@ IRON_PRINT_MESSAGES() donotreprint=false } +# fail: patch didn't apply correctly +FAIL_PATCH_DID_NOT_APPLY() { + rm -f $WDIR/*.rej + rm -f $WDIR/*.orig + rm -f $WDIR/*.diff + rm -f $WDIR/iron-messagedata + rm -f $WDIR/iron-messagedata-tmp + clear + donotreprint=false + + cd $basedir + + # reprint everything because patch was bad + IRON_DOWNLOAD_API + IRON_HEADER + IRON_PRINT_MESSAGES + + $0 && IRON_EXIT +} + +# function to create a patch +IRON_HIDE_MSG() { + # if there is messagedata, continue + # otherwise, don't + if [ -e "$WDIR/iron-messagedata" ]; then + cp $WDIR/iron-messagedata $WDIR/iron-messagedata-tmp + else + return 1 + fi + + # choose editor to use + if [ "$EDITOR" = "" ]; then + vim $WDIR/iron-messagedata-tmp + else + $EDITOR $WDIR/iron-messagedata-tmp + fi + + # once the user has edited the temporary messagedata, make a patch with the changes + diff -up $WDIR/iron-messagedata $WDIR/iron-messagedata-tmp > $WDIR/iron-hiddenmessages.diff + + cd $WDIR + patch -fs < $WDIR/iron-hiddenmessages.diff || rm -f $WDIR/iron-messagedata $WDIR/iron-messagedata-tmp $WDIR/*.diff $WDIR/*.rej $WDIR/*.orig + haspatched=true + + cd $basedir + donotreprint=true + IRON_HEADER + IRON_PRINT_MESSAGES +} + +# hide messages +IRON_SHOW_MSG() { + if [ -e "$WDIR/iron-hiddenmessages.diff" ]; then + cd $WDIR + + # reverse changes + patch -R < $WDIR/iron-hiddenmessages.diff || FAIL_PATCH_DID_NOT_APPLY + + rm -f $WDIR/iron-hiddenmessages.diff + + # print messages + donotreprint=true + clear + IRON_HEADER + IRON_PRINT_MESSAGES + else + rm -f $WDIR/iron-hiddenmessages.diff + + FAIL_PATCH_DID_NOT_APPLY + fi +} + # send the message using curl that we composed IRON_SEND_MESSAGE() { @@ -363,10 +448,13 @@ IRON_CMD() "q") IRON_EXIT ;; "l") IRON_MAIN ;; "r") rm -f $WDIR/iron-messagedata && ${0} && IRON_EXIT ;; + "hide") IRON_HIDE_MSG ;; + "show") IRON_SHOW_MSG ;; "reset") rm -rf $WDIR/ && ${0} && IRON_EXIT ;; "e") touch $WDIR/iron-editor-message ; $EDITOR $WDIR/iron-editor-message && IRON_MESSAGE_TYPE=editor && IRON_SEND_MESSAGE ;; esac + cd $basedir $0 && IRON_EXIT }