[GH-ISSUE #228] Feature request: Adding TextViews or other Primitives into List #176

Closed
opened 2026-03-04 01:02:39 +03:00 by kerem · 8 comments
Owner

Originally created by @diamondburned on GitHub (Jan 18, 2019).
Original GitHub issue: https://github.com/rivo/tview/issues/228

Hello. I'm programming an application that requires changing live text data on the screen. Right now, I have one large TextView box that's formatted. However, I can't edit an existing text without seeking over the entire View.

It would be nice if there's a way to add small TextViews as List entries and set a unique identifier for them, so it's easier to iterate and replace the entry alone instead of the entire box.

Originally created by @diamondburned on GitHub (Jan 18, 2019). Original GitHub issue: https://github.com/rivo/tview/issues/228 Hello. I'm programming an application that requires changing live text data on the screen. Right now, I have one large TextView box that's formatted. However, I can't edit an existing text without seeking over the entire View. It would be nice if there's a way to add small TextViews as List entries and set a unique identifier for them, so it's easier to iterate and replace the entry alone instead of the entire box.
kerem closed this issue 2026-03-04 01:02:39 +03:00
Author
Owner

@diamondburned commented on GitHub (Jan 18, 2019):

I have looked into Regions. There isn't a method to change Region texts afaik.

<!-- gh-comment-id:455447936 --> @diamondburned commented on GitHub (Jan 18, 2019): I have looked into Regions. There isn't a method to change Region texts afaik.
Author
Owner

@rivo commented on GitHub (Jan 22, 2019):

I understand you want to have a way to edit the content of a TextView. There is an open issue #64 which asks for an editable TextArea. However, this goes very deep into "text editor" territory so it's a larger project I will need to tackle at some point, nothing that I can offer quickly.

As for your suggestion, I'm not sure how having a TextView inside a List entry would be different from what List entries offer now already. If you can split your original text into lines yourself, you can put them in a List (or in a Table) and let the user select them. A selection could open an InputField somewhere which allows the user to edit that line.

If this is not what you're looking for, I'm afraid I'll need more information. Maybe you can construct a screenshot or something that illustrates what you're looking for.

<!-- gh-comment-id:456493845 --> @rivo commented on GitHub (Jan 22, 2019): I understand you want to have a way to edit the content of a `TextView`. There is an open issue #64 which asks for an editable `TextArea`. However, this goes very deep into "text editor" territory so it's a larger project I will need to tackle at some point, nothing that I can offer quickly. As for your suggestion, I'm not sure how having a `TextView` inside a `List` entry would be different from what `List` entries offer now already. If you can split your original text into lines yourself, you can put them in a `List` (or in a `Table`) and let the user select them. A selection could open an `InputField` somewhere which allows the user to edit that line. If this is not what you're looking for, I'm afraid I'll need more information. Maybe you can construct a screenshot or something that illustrates what you're looking for.
Author
Owner

@diamondburned commented on GitHub (Jan 23, 2019):

I understand you want to have a way to edit the content of a TextView. There is an open issue #64 which asks for an editable TextArea. However, this goes very deep into "text editor" territory so it's a larger project I will need to tackle at some point, nothing that I can offer quickly.

As for your suggestion, I'm not sure how having a TextView inside a List entry would be different from what List entries offer now already. If you can split your original text into lines yourself, you can put them in a List (or in a Table) and let the user select them. A selection could open an InputField somewhere which allows the user to edit that line.

If this is not what you're looking for, I'm afraid I'll need more information. Maybe you can construct a screenshot or something that illustrates what you're looking for.

A list strips newlines off of subtitles for me, so it's not viable. Thanks for your help though.

<!-- gh-comment-id:456679501 --> @diamondburned commented on GitHub (Jan 23, 2019): > I understand you want to have a way to edit the content of a `TextView`. There is an open issue #64 which asks for an editable `TextArea`. However, this goes very deep into "text editor" territory so it's a larger project I will need to tackle at some point, nothing that I can offer quickly. > > As for your suggestion, I'm not sure how having a `TextView` inside a `List` entry would be different from what `List` entries offer now already. If you can split your original text into lines yourself, you can put them in a `List` (or in a `Table`) and let the user select them. A selection could open an `InputField` somewhere which allows the user to edit that line. > > If this is not what you're looking for, I'm afraid I'll need more information. Maybe you can construct a screenshot or something that illustrates what you're looking for. A list strips newlines off of subtitles for me, so it's not viable. Thanks for your help though.
Author
Owner

@rivo commented on GitHub (Jan 23, 2019):

Again, it seems I have trouble understanding your requirement. I'll leave this issue open for a while so you can post more information that may help me come up with a solution for you.

<!-- gh-comment-id:456868799 --> @rivo commented on GitHub (Jan 23, 2019): Again, it seems I have trouble understanding your requirement. I'll leave this issue open for a while so you can post more information that may help me come up with a solution for you.
Author
Owner

@diamondburned commented on GitHub (Jan 25, 2019):

Regarding just the ListView part of my "requirement":

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	list := tview.NewList().
		AddItem("List item 1", "New line \ndoesn't work", ' ', nil).
		AddItem("List item 2", "Another\nexample\nwith\n4 lines", ' ', nil).
		AddItem("Quit", "Press to exit", 'q', func() {
			app.Stop()
		})
	if err := app.SetRoot(list, true).Run(); err != nil {
		panic(err)
	}
}

I figured if we could have a TextView box for the ListView elements instead of individual strings, that would allow for more things such as colors, formatting and new lines (which is what the issue is in the example).

<!-- gh-comment-id:457454492 --> @diamondburned commented on GitHub (Jan 25, 2019): Regarding just the ListView part of my "requirement": ```go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() list := tview.NewList(). AddItem("List item 1", "New line \ndoesn't work", ' ', nil). AddItem("List item 2", "Another\nexample\nwith\n4 lines", ' ', nil). AddItem("Quit", "Press to exit", 'q', func() { app.Stop() }) if err := app.SetRoot(list, true).Run(); err != nil { panic(err) } } ``` I figured if we could have a TextView box for the ListView elements instead of individual strings, that would allow for more things such as colors, formatting and new lines (which is what the issue is in the example).
Author
Owner

@rivo commented on GitHub (Feb 14, 2019):

Apologies for the late reply.

Colors are allowed in lists:

package main

import (
	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	list := tview.NewList().
		AddItem("List item 1", "[red]Colors[green] are allowed", 0, nil).
		AddItem("Quit", "Press to exit", 'q', func() {
			app.Stop()
		})
	if err := app.SetRoot(list, true).Run(); err != nil {
		panic(err)
	}
}

I think the main issue is allowing multi-line list items. I'm not sure I will add this to a List in the near future. For something like this, the TextView can be used:

package main

import (
	"fmt"
	"strconv"
	"strings"

	"github.com/rivo/tview"
)

func main() {
	app := tview.NewApplication()
	textView := tview.NewTextView().
		SetRegions(true)

	items := []string{
		"This is the first list item",
		"This is the second list item",
		"This is a list\nitem split into three\ndifferent lines",
		"This is a list item\nsplit into two lines",
	}

	currentItem := 2

	// Generate text view string.
	formattedItems := make([]string, len(items))
	for index, item := range items {
		formattedItems[index] = fmt.Sprintf(`["%d"]%s[""]`, index, item)
	}

	// Set text view content.
	textView.SetText(strings.Join(formattedItems, "\n")).
		Highlight(strconv.Itoa(currentItem))

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

But your first comment in this thread mentioned "editing" list items. So I'm not quite sure if this would cover everything you want to do.

<!-- gh-comment-id:463681559 --> @rivo commented on GitHub (Feb 14, 2019): Apologies for the late reply. Colors are allowed in lists: ```go package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() list := tview.NewList(). AddItem("List item 1", "[red]Colors[green] are allowed", 0, nil). AddItem("Quit", "Press to exit", 'q', func() { app.Stop() }) if err := app.SetRoot(list, true).Run(); err != nil { panic(err) } } ``` I think the main issue is allowing multi-line list items. I'm not sure I will add this to a `List` in the near future. For something like this, the `TextView` can be used: ```go package main import ( "fmt" "strconv" "strings" "github.com/rivo/tview" ) func main() { app := tview.NewApplication() textView := tview.NewTextView(). SetRegions(true) items := []string{ "This is the first list item", "This is the second list item", "This is a list\nitem split into three\ndifferent lines", "This is a list item\nsplit into two lines", } currentItem := 2 // Generate text view string. formattedItems := make([]string, len(items)) for index, item := range items { formattedItems[index] = fmt.Sprintf(`["%d"]%s[""]`, index, item) } // Set text view content. textView.SetText(strings.Join(formattedItems, "\n")). Highlight(strconv.Itoa(currentItem)) if err := app.SetRoot(textView, true).Run(); err != nil { panic(err) } } ``` But your first comment in this thread mentioned "editing" list items. So I'm not quite sure if this would cover everything you want to do.
Author
Owner

@diamondburned commented on GitHub (Feb 15, 2019):

Thanks for replying. While developing my app, I have found out I could simply store the messages in an array and override the TextView when there's an edit. I thought the performance would be crap like in any GUI app I've ever worked with, but it turns out it worked really well.

<!-- gh-comment-id:464025606 --> @diamondburned commented on GitHub (Feb 15, 2019): Thanks for replying. While developing my app, I have found out I could simply store the messages in an array and override the TextView when there's an edit. I thought the performance would be crap like in any GUI app I've ever worked with, but it turns out it worked really well.
Author
Owner

@rivo commented on GitHub (Feb 15, 2019):

That's great. Thanks for the feedback.

<!-- gh-comment-id:464129798 --> @rivo commented on GitHub (Feb 15, 2019): That's great. Thanks for the feedback.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#176
No description provided.