WordWrap does not split on newlines #72

Closed
opened 12 months ago by bacardi55 · 3 comments

When using color tags (simple like [red] or more complex like [red:-:b] in a Modal, the line breaks stop working.

Demo code (based on modal demo code):

package main

import (
	"code.rocketnine.space/tslocum/cview"
)

func main() {
	app := cview.NewApplication()
	app.EnableMouse(true)

	modal := cview.NewModal()
	//modal.SetText("Do you want to\n\n quit the application?")
	//modal.SetText("[red:-:-]Do you[blue:-:-] want to\n\n quit the application?")
	modal.SetText("[red:-:-]Do you[-:-:-] want to\n\n quit the application?")
	modal.AddButtons([]string{"Quit", "Cancel"})
	modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
		if buttonLabel == "Quit" {
			app.Stop()
		}
	})

	app.SetRoot(modal, false)
	if err := app.Run(); err != nil {
		panic(err)
	}
}

In this code, uncomment the first SetText and comment the 2nd and 3rd one => The line breaks will work.
In the other 2 example, it doesn't, but the colors work.

Tested on the latest commit 605d0123c1

(btw, thanks a lot for the other fix and the feature request, both tested today and they work as expected :)).

When using color tags (simple like `[red]` or more complex like `[red:-:b]` in a Modal, the line breaks stop working. Demo code (based on modal demo code): ``` package main import ( "code.rocketnine.space/tslocum/cview" ) func main() { app := cview.NewApplication() app.EnableMouse(true) modal := cview.NewModal() //modal.SetText("Do you want to\n\n quit the application?") //modal.SetText("[red:-:-]Do you[blue:-:-] want to\n\n quit the application?") modal.SetText("[red:-:-]Do you[-:-:-] want to\n\n quit the application?") modal.AddButtons([]string{"Quit", "Cancel"}) modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { if buttonLabel == "Quit" { app.Stop() } }) app.SetRoot(modal, false) if err := app.Run(); err != nil { panic(err) } } ``` In this code, uncomment the first SetText and comment the 2nd and 3rd one => The line breaks will work. In the other 2 example, it doesn't, but the colors work. Tested on the latest commit 605d0123c1 (btw, thanks a lot for the other fix and the feature request, both tested today and they work as expected :)).
tslocum added the
bug
label 12 months ago
tslocum changed title from Modal.SetText don't respect line breaks when using color tags to WordWrap does not split on newlines 12 months ago
Owner

Thanks for reporting this. WordWrap is returning strings containing a newline character (when each line should be a separate string). This is the root cause for the issue above.

Thanks for reporting this. `WordWrap` is returning strings containing a newline character (when each line should be a separate string). This is the root cause for the issue above.
Poster

Would this also be the cause of modal needing 2 "\n" to actually display a line break?

package main

import (
	"code.rocketnine.space/tslocum/cview"
)

func main() {
	app := cview.NewApplication()
	app.EnableMouse(true)

	modal := cview.NewModal()
	modal.SetText("Do you want to quit\n the application?")
	//modal.SetText("Do you want to quit\n\n the application?")
	modal.AddButtons([]string{"Quit", "Cancel"})
	modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) {
		if buttonLabel == "Quit" {
			app.Stop()
		}
	})

	app.SetRoot(modal, false)
	if err := app.Run(); err != nil {
		panic(err)
	}
}

In this case, having just one "\n" don't break the line. By adding 2 "\n" like in the commented line, then I see a line break in the modal.

Based on your comment, I'm thinking this may be related. But if that's not the case, happy to remove this comment and create a dedicated issue for this.

Would this also be the cause of modal needing 2 "\n" to actually display a line break? ``` package main import ( "code.rocketnine.space/tslocum/cview" ) func main() { app := cview.NewApplication() app.EnableMouse(true) modal := cview.NewModal() modal.SetText("Do you want to quit\n the application?") //modal.SetText("Do you want to quit\n\n the application?") modal.AddButtons([]string{"Quit", "Cancel"}) modal.SetDoneFunc(func(buttonIndex int, buttonLabel string) { if buttonLabel == "Quit" { app.Stop() } }) app.SetRoot(modal, false) if err := app.Run(); err != nil { panic(err) } } ``` In this case, having just one "\n" don't break the line. By adding 2 "\n" like in the commented line, then I see a line break in the modal. Based on your comment, I'm thinking this may be related. But if that's not the case, happy to remove this comment and create a dedicated issue for this.
Owner

Thanks. I've looked into this a bit, and shared what I've found here: #27.

Closing in favor of #27.

Thanks. I've looked into this a bit, and shared what I've found here: https://code.rocketnine.space/tslocum/cview/issues/27#issuecomment-3976. Closing in favor of #27.
tslocum closed this issue 11 months ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.