iridakos / stup

Daily notes in the terminal :penguin:
https://github.com/iridakos/stup
MIT License
415 stars 31 forks source link

Multi line notes don't play nice #39

Open ioanniswd opened 4 years ago

ioanniswd commented 4 years ago
$ 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 or n<Enter wouldn't be so difficult)

Applies to both add and copy commands.

iridakos commented 4 years ago

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

ghost commented 4 years ago

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).

ioanniswd commented 4 years ago

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
iridakos commented 4 years ago

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

ghost commented 4 years ago

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

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)

iridakos commented 4 years ago

@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

ghost commented 4 years ago

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.