VladimirMarkelov / clui

Command Line User Interface (Console UI inspired by TurboVision)
MIT License
670 stars 50 forks source link

Is textreader example idiomatic to this lib? #118

Open inliquid opened 5 years ago

inliquid commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Makes sense. Thank you.