Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created February 20, 2019 09:35
Show Gist options
  • Save Integralist/5b4c9489bf307da542d5f087adbbff42 to your computer and use it in GitHub Desktop.
Save Integralist/5b4c9489bf307da542d5f087adbbff42 to your computer and use it in GitHub Desktop.
[Golang Print over last line - like a counter] #go #golang #counter #inplace #print
package main
import (
"fmt"
"time"
)
func main() {
ticker := time.Tick(time.Second)
for i := 1; i <= 10; i++ {
<-ticker
fmt.Printf("\x0cOn %d/10", i)
}
fmt.Println("\nAll is said and done.")
}
package main
import (
"fmt"
"time"
)
func main() {
ticker := time.Tick(time.Second)
for i := 1; i <= 10; i++ {
<-ticker
fmt.Printf("\rOn %d/10", i) // escape sequence is different in this environment
}
fmt.Println("\nAll is said and done.")
}
@iAmInActions
Copy link

Would it be possible to do this but instead of overwriting the line it scrolls up and places the text above the current bottom most line?
Im writing a telnet chat client in go and am having the issue of it overwriting my user input with chat messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment