Skip to content

Commit

Permalink
code: ensure that when wrapping a message across lines that words nee…
Browse files Browse the repository at this point in the history
…d to wrap.

Fixes #9
  • Loading branch information
1egoman committed May 27, 2017
1 parent b77a323 commit e55b665
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions gateway/printable_message.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gateway

import (
// "log"
"log"
"strings"
)

Expand Down Expand Up @@ -92,11 +92,15 @@ func (p *PrintableMessage) Lines(width int) [][]PrintableMessagePart {
// "window width"
// (done, since the line length < window width)

wordsInLastMessagePart := strings.Split(part.Content, " ")
for len(strings.Join(wordsInLastMessagePart, " ")) > maximumLengthOfLastMessagePart {
// Remove one word from the last message part
extraWords = append([]string{wordsInLastMessagePart[len(wordsInLastMessagePart) - 1]}, extraWords...)
wordsInLastMessagePart = wordsInLastMessagePart[:len(wordsInLastMessagePart)-1]
if maximumLengthOfLastMessagePart > 0 { // Ensure that we should remove words. Fixes #9.
wordsInLastMessagePart := strings.Split(part.Content, " ")
for len(strings.Join(wordsInLastMessagePart, " ")) > maximumLengthOfLastMessagePart {
// Remove one word from the last message part
log.Printf("len(wordsInLastMessagePart) = %d", len(wordsInLastMessagePart))
log.Printf("wordsInLastMessagePart[-1] = %+v", wordsInLastMessagePart[len(wordsInLastMessagePart)-1])
extraWords = append([]string{wordsInLastMessagePart[len(wordsInLastMessagePart) - 1]}, extraWords...)
wordsInLastMessagePart = wordsInLastMessagePart[:len(wordsInLastMessagePart)-1]
}
}

// If the last message part in a line has content to append, then add it. However, if
Expand Down

0 comments on commit e55b665

Please sign in to comment.