peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.05k stars 132 forks source link

Async control, may fix #16 #46 #119

Closed complyue closed 5 years ago

complyue commented 5 years ago

This may fix #16 #46 and less racy, tho I don't know how it'll work on windows.

a

    // fancy count down to test/showcase async control of liner
    he.ExposeFunction("sd", func(cnt int) string {
        go func() {

            for n := cnt; n > 0; n-- {
                line.ChangePrompt(fmt.Sprintf("SelfDtor(%d): ", n))

                time.Sleep(1 * time.Second)

                line.HidePrompt()
                fmt.Printf(" %d seconds passed.\n", 1+cnt-n)
                line.ShowPrompt()
            }
            line.HidePrompt()
            fmt.Println("Boom!!!")
            line.ShowPrompt()

            line.ChangePrompt("!!<defunct> ")
        }()

        return fmt.Sprintf("Self Destruction in %d seconds ...", cnt)
    })
complyue commented 5 years ago

I tested on windows and added compatibility updates, changing prompt on-the-fly seems not working, maybe the line clearing issue? At least it runs on windows with no error.

peterh commented 5 years ago

Thanks for taking the time to experiment. Please accept my apologies for taking so long to review this pull request. Unfortunately, there are a lot of issues with this pull request:

All that aside, the main problem with this pull request is that I've changed my opinion since my comments in #16 and #46. I no longer think this feature is appropriate, regardless of how carefully it has been implemented. If you want "print above prompt", you want a different library than this one. I will not be accepting a pull request that adds such a feature. At most, I could accept a pull request that adds a link in README.md that points to other libraries that support this feature (whether a fork of liner or an entirely unrelated library).