Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Adding TextViews or other Primitives into List #228

Closed
diamondburned opened this issue Jan 18, 2019 · 8 comments
Closed

Comments

@diamondburned
Copy link

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.

@diamondburned
Copy link
Author

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

@rivo
Copy link
Owner

rivo commented 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.

@diamondburned
Copy link
Author

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.

@rivo
Copy link
Owner

rivo commented 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.

@diamondburned
Copy link
Author

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

@rivo
Copy link
Owner

rivo commented 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.

@diamondburned
Copy link
Author

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.

@rivo
Copy link
Owner

rivo commented Feb 15, 2019

That's great. Thanks for the feedback.

@rivo rivo closed this as completed Feb 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants