#!/bin/bash -i
# hastily written
# but does the job
# whatever

TODO_FILE=${HOME}/.local/share/${USER}/.todo
SIZE=$((${COLUMNS} - 4))

append() {
    echo "$*" >> ${TODO_FILE}
}

awk_print() {
    awk '{}'
}

splitline() {
    printf "\n  +"
    printf %$(($(echo -n ${COLUMNS}) - 6))s | tr ' ' '-'
    printf "+  \n"
}

splititem() {
    number='-'
    [ ! -z $1 ] && number=$1

    printf "\n"%$((($(echo -n ${COLUMNS}) - 3) / 2))s
    echo "- ${number} -"
    #printf %$((($(echo -n ${COLUMNS}) - 5) / 2))s"\n"
}

printitem() {
    [ $(printf "$*" | wc -c) -gt $((${COLUMNS} - 4)) ] && printf "  $*  " && return
    count=$(printf "$*" | wc -c)
    border=$(((${COLUMNS} - count) / 2))
    printf "%${border}s$*%${border}s\n"
}

# check existence of todo file, create if not
[ ! -f "${TODO_FILE}" ] && touch "${TODO_FILE}"

# for appending lines (removing done via 'done')
[ ! -z "$*" ] && append $* && echo "noted" && exit 0

[ $(($(cat "${TODO_FILE}" | wc -c))) -lt 2 ] && echo "nothing to do" && exit 0

splitline
# iterate over lines, not words
IFS="
"
index=1
for i in $(cat "${TODO_FILE}"); do
    splititem ${index}
    printitem $i
    index=$((${index} + 1))
done
splitline
