clui icon indicating copy to clipboard operation
clui copied to clipboard

Is textreader example idiomatic to this lib?

Open inliquid opened this issue 5 years ago • 5 comments

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?

inliquid avatar Mar 15 '19 20:03 inliquid

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 avatar Mar 16 '19 03:03 VladimirMarkelov

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.

VladimirMarkelov avatar Mar 16 '19 04:03 VladimirMarkelov

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.

inliquid avatar Mar 16 '19 18:03 inliquid

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.

VladimirMarkelov avatar Mar 16 '19 22:03 VladimirMarkelov

Makes sense. Thank you.

inliquid avatar Mar 16 '19 23:03 inliquid