stup icon indicating copy to clipboard operation
stup copied to clipboard

Multi line notes don't play nice

Open ioanniswd opened this issue 4 years ago • 7 comments

$ stup add -n 'Multi                                                
quote> line            
quote> note'             
Successfully added 1 notes in category personal for Friday May 01, 2020
$ stup add -n 'Single line note'
Successfully added 1 notes in category personal for Friday May 01, 2020
$ stup show today
Displaying notes added for Friday May 01, 2020.

 # Notes in category: personal

  • Multi
  line
  note
  • Single line note

Mentioned in this issue comment by @tiosgz :

I'm quite curious how this could be done simply with multi-line notes (yes I use them a lot)… (OK, some more y<Enter> or n<Enter wouldn't be so difficult)

Applies to both add and copy commands.

ioanniswd avatar May 01 '20 12:05 ioanniswd

Hi @ioanniswd I can see the problem in indentation, is that what you are talking about or am I missing and something else?

iridakos avatar May 01 '20 15:05 iridakos

I don't think there is any problem at all until the notes are filtered one by one (happens with copy and I guess also search (haven't tested this yet)), except for the bullets (which don't look good IMO, anyway).

If you look at the .md file as if it was written manually: wouldn't you indent the next line so that it looks more natural? And if you add sub-lists (this is what I usually do), you have to indent them to be parsed as separate lists (and not just items of the top-level list).

ghost avatar May 01 '20 15:05 ghost

Yes, the indentation and the bullets are the issue when it comes to show. Also, in copy, we currently treat a multi line note as separate notes:

$ stup copy --to tomorrow --from today 
About to copy notes from Friday May 01, 2020 to Saturday May 02, 2020 for category personal


- Multi


>>> Copy this note [y,n,q,a]?: n


line


>>> Copy this note [y,n,q,a]?: n


note


>>> Copy this note [y,n,q,a]?: n


- Single line note


>>> Copy this note [y,n,q,a]?: n

ioanniswd avatar May 01 '20 15:05 ioanniswd

Ok, this needs a little work to think of the best approach to deal with.

The fact that each note starts with a dash might be helpful to be able to group distinguish multiline notes via a regex.

I will think about possible solutions. If anyone thinks of something let's add it here for discussion.

PS: I really appreciate your contributions @ioanniswd @tiosgz, thank you very much

iridakos avatar May 01 '20 16:05 iridakos

I haven't found a way to do this using one regex-ed line, but I think this could work

  • arr=()
  • read through the file
    • if the line starts with - , append it to the array
    • otherwise append it to the array's last item (don't forget a newline)
arr=()
while IFS='' read line
do
  if [[ "$line" =~ (^- ) ]]; then
    arr+=( "$line" )
  else
    last=$((${#arr[*]} - 1))
    arr[$last]+="\n$line"
  fi
done < $notes_file

Will find all the credits if you want (though it'd mean filtering ~20 tabs)

ghost avatar May 01 '20 21:05 ghost

@tiosgz I think it'll work. I can check that tomorrow and get back to you. If you already started or you want to work on this let me know to avoid conflict.

Will find all the credits if you want (though it'd mean filtering ~20 tabs)

:laughing: no, I don't

iridakos avatar May 01 '20 22:05 iridakos

If you already started or you want to work on this let me know to avoid conflict.

I don't plan doing this, because (as I know myself) I would never get it done.

ghost avatar May 02 '20 08:05 ghost