gosuri / uilive

uilive is a go library for updating terminal output in realtime
MIT License
1.7k stars 87 forks source link

The last line is being overwritten when width of the buffer exceeds screen width #3

Closed gosuri closed 5 years ago

gosuri commented 8 years ago

The last line seems to be overwritten when width of the buffer exceeds screen width:

screen shot 2015-12-08 at 11 11 19

Code:

package main

import (
    "fmt"
    "time"

    "github.com/gosuri/uilive"
)

func main() {
    writer := uilive.New()

    // start listening for updates and render
    writer.Start()

    str := ""
    for i := 0; i <= 100; i++ {
        str = str + "s"
    }
    str = str + "[end]"

    for i := 0; i <= 100; i++ {
        fmt.Fprintf(writer, "%d %s\n", i, str)
        time.Sleep(time.Second)
    }

    writer.Stop() // flush and stop rendering
}

(Ref #2)

apoorvam commented 8 years ago

This commit on my fork works for windows too. It has a dependency on github.com/nsf/termbox-go.

Example code which works with this forked package:

package main

import (
    "fmt"
    "time"

    "github.com/apoorva/uilive"
)

func main() {
    writer := uilive.New()

    // start listening for updates and render
    writer.Start()
    uilive.InitializeTerminalWidth()

    str := ""
    for i:=0; i<200; i++ {
        str += "s"
    }

    str += "[end]"

    for i := 0; i <= 100; i++ {
        fmt.Fprintf(writer, "%d %s\n", i, str)
        time.Sleep(time.Second)
    }

    fmt.Fprintln(writer, "Finished: Downloaded 100GB")
    writer.Stop() // flush and stop rendering
}
asahasrabuddhe commented 5 years ago

This might be late for you but I think this could be helpful for you or someone else who might stumble over this issue:

I have made a fork of this library and have managed to fix most of the issues. I would gladly do a PR here if @gosuri is interested in reviving this package. Until then, we could collaborate and keep this wonderful package alive right here: https://github.com/asahasrabuddhe/uilive