Skip to content

Commit

Permalink
Fix display for multi-line comments (#123)
Browse files Browse the repository at this point in the history
* Update Note display to handle multi-string comments

* Update TestNoteStrings to test for multi-line comments
  • Loading branch information
goyalmunish authored May 28, 2022
1 parent 8c71bb7 commit 25c24a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
16 changes: 15 additions & 1 deletion internal/model/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@ import (
func printNoteField(fieldName string, fieldValue interface{}) string {
var strs []string
fieldDynamicType := fmt.Sprintf("%T", fieldValue)
// construct the display text based on value type
if fieldDynamicType == "[]string" {
items := fieldValue.([]string)
strs = append(strs, fmt.Sprintf(" | %12v:\n", fieldName))
if items != nil {
for _, v := range items {
strs = append(strs, fmt.Sprintf(" | %12v: %v\n", "", v))
if strings.Contains(v, "\n") {
// the string is multi-line
data := strings.Split(v, "\n")
heading, subItems := data[0], data[1:]
strs = append(strs, fmt.Sprintf(" | %12v: %v\n", "", heading))
for _, e := range subItems {
e = strings.TrimSpace(e)
if e != "" {
strs = append(strs, fmt.Sprintf(" | %18v %v\n", "", e))
}
}
} else {
strs = append(strs, fmt.Sprintf(" | %12v: %v\n", "", v))
}
}
}
} else {
Expand Down
7 changes: 5 additions & 2 deletions internal/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ func TestNotesByDueDate(t *testing.T) {

func TestNoteStrings(t *testing.T) {
utils.Location = utils.UTCLocation()
comments := model.Comments{&model.Comment{Text: "c1"}, &model.Comment{Text: "c2"}, &model.Comment{Text: "c3"}}
comments := model.Comments{&model.Comment{Text: "c1:\n- line 1\n\n- line 2\n- line 3"}, &model.Comment{Text: "c2"}, &model.Comment{Text: "c3"}}
note := &model.Note{Text: "dummy text", Comments: comments, Status: "pending", TagIds: []int{1, 2}, CompleteBy: 1609669235}
want := `[ | Text: dummy text
| Comments:
| : [nil] c1
| : [nil] c1:
| - line 1
| - line 2
| - line 3
| : [nil] c2
| : [nil] c3
| Summary:
Expand Down
4 changes: 2 additions & 2 deletions internal/model/reminder_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (reminderData *ReminderData) NotesApprachingDueDate(view string) Notes {
noteTimestampPrevious := noteTimestampCurrent - 365*24*60*60
noteTimestampNext := noteTimestampCurrent + 365*24*60*60
daysBefore := int64(3) // days before to start showing the note
daysAfter := int64(7) // days after until to show the note
daysAfter := int64(7) // days after until to show the note
if view == "long" {
daysBefore = int64(365)
}
Expand All @@ -318,7 +318,7 @@ func (reminderData *ReminderData) NotesApprachingDueDate(view string) Notes {
noteTimestampPrevious := noteTimestampCurrent - 30*24*60*60
noteTimestampNext := noteTimestampCurrent + 30*24*60*60
daysBefore := int64(1) // days beofre to start showing the note
daysAfter := int64(3) // days after until to show the note
daysAfter := int64(3) // days after until to show the note
if view == "long" {
daysBefore = int64(31)
}
Expand Down

0 comments on commit 25c24a6

Please sign in to comment.