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

Is textreader example idiomatic to this lib? #118

Open
inliquid opened this issue Mar 15, 2019 · 5 comments
Open

Is textreader example idiomatic to this lib? #118

inliquid opened this issue Mar 15, 2019 · 5 comments

Comments

@inliquid
Copy link

In particular

	b.OnDrawLine(func(ind int) string {
		return fmt.Sprintf("%03d line line line", ind+1)
	})

-> is this correct way to push some text content to output? I mean... no io.Writer/Reader interfaces or anything similar?

@VladimirMarkelov
Copy link
Owner

TextReader, like TableView, is a pure "virtual" control that uses as little memory as possible. It expects that the data are already prepared and kept somewhere outside - no text is stored in TextReader's memory, it is discarded right after it has been displayed. TextReader only asks for a certain line by index when it wants to draw the line. I am not sure how to make use of io.Reader/io.Writer in this case. If you have any idea, suggestions and idea are very welcome.

Though, as for TextView control - it may make sense to implement setting data with io.Reader. But it requires writing a text parsing module that can divide text to lines, convert between code pages, detect that io.Reader provides text(not binary) etc. It a big piece of work. Another question, if we use io.Reader: what to do with long lines? Do we need to implement word-wrap or hyphenation? At this moment, the library expects all the data are precalculated/preloaded/etc and it just use the external data.

@VladimirMarkelov
Copy link
Owner

I think contol's name TextReader is misleading but I failed to find a better name when I created it. Now it is not a good time to rename - it is breaking changes.

@inliquid
Copy link
Author

Thank you for clarification. I understand that Reader/Writer implementations will add complexity, and it's up to you how to better build the library. Just wanted to check if my understanding was correct. For long lines and other options it will of course require some kind of configuration like (*TextReader) SetWordWrap(bool) or smth. However for building end applications Reader/Writer is kind of expected and language-idiomatic form. If such improvement will take place it will be extremely useful.

@VladimirMarkelov
Copy link
Owner

I've renamed TextReader to TextDisplay to avoid confusion with io.Reader - the control does not read anything, it just shows some external data.

As for adding io.Reader support to TextView(now it supports only []string argument) - I think I can do a basic one: always assume that io.Redaer provides text file in UTF-8 format and split the data from io.Reader by new lines. And then let's see what happens - if anybody needs more.

@inliquid
Copy link
Author

Makes sense. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants