Giter Club home page Giter Club logo

Comments (12)

theckman avatar theckman commented on June 19, 2024

Are you able to be more specific about the use case? I'm not sure I follow.

Are you talking about when the output is piped?

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

@theckman ya, happy to discuss more. Basically, my specific use case is I want to use yacspin within https://github.com/rivo/tview - That's a Terminal UI Framework. Since that framework is what "draws" on the screen, all I need from yacspin is the string that is produced, then notify tview to "redraw".

There's some more details here including some example code: rivo/tview#462

from yacspin.

theckman avatar theckman commented on June 19, 2024

@ghostsquad I'm fairly ignorant to how tview works, so apologies if I'm asking some obvious questions.

I assume the code with yacspin running is being invoked by tview, and then the output from the yacspin'd binary is being printed by tview?

If so, might it be better to say that the issue is yacspin blindly assumes it's in an interactive terminal session, and then tries to behave as such? Including using \r to overwrite the line? If it were to identify it's not connected to a TTY directly, we could have it behave differently and not write those characters out.

Would you say that's a reasonable understanding of the situation and one of the potential solutions? Trying to make sure I fully grok the problem. :)

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

You nailed it. With one caveat. You can't really use io.Writer since that assumes it's ok to just continue writing updates to the same stream. I need to know the "current" state of the spinner.

from yacspin.

theckman avatar theckman commented on June 19, 2024

Could you explain what you mean by needing to know the state?

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

State == what should be on the screen at any given time

from yacspin.

theckman avatar theckman commented on June 19, 2024

@ghostsquad I am trying to understand whether this is a problem that should be solved by yacspin, or if I should add support for detecting a TTY and then leave it up to the consumer to write a wrapper to support whatever peculiarities tview has. I am reluctant to expand the API to support behaviors of a project I hadn't seen before this issue was raised, without understanding the technical need and whether other things need the same type of hook.

Being very transparent, I'm now following the problem and what you need to solve the problem. Why do you need to know what's supposed to be on screen?

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

So that I can update the contents of tview.TextView object or a TableCell. This is a primitive object that simply displays text. tview will update that text.

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

Other clarifications. Since tview is a terminal gui, it would likely be running in a TTY, since that's it's primary use case.

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

If you have a better way of providing an isolated "snapshot" of what the spinner should look like at any given moment, and provide that to the client. Then update that snapshot (not append, which is what is currently being done with io.Writer), I'm happy to hear it. But I'm pretty sure that's what my PR does.

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

I'm not sure how else to explain it. Currently Yacspin supports only explicitly outputting to something like os.Stdout (assumed that it's a terminal), and takes advantage of carriage returns in order to "overwrite" previously written state. My PR allows each individual state update to be used however it's needed, as seen below. Each line would be considered a "snapshot" of the spinner.

| doing something
/ doing something
- doing something
\ doing something
✔️ done

from yacspin.

ghostsquad avatar ghostsquad commented on June 19, 2024

sorry for bothering you. This is clearly outside the scope of what you intend for this repo. I found an exceedingly simple alternative here that has the flexibility I need.

https://github.com/tj/go-spin

from yacspin.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.