Skip to content

Instantly share code, notes, and snippets.

@pazworld
Last active October 3, 2019 10:56
Show Gist options
  • Save pazworld/30f96bdd1d9ec3cc67b6b648ff09a20c to your computer and use it in GitHub Desktop.
Save pazworld/30f96bdd1d9ec3cc67b6b648ff09a20c to your computer and use it in GitHub Desktop.
slow pager first show stdin with fullspeed, then slow down
// slow pager
// show fullspeed duaring full_speed_period, then show with wait_per_line sleep
package main
import (
"bufio"
"flag"
"fmt"
"os"
"time"
)
// first fullspeed period
const full_speed_duaring = 1 * time.Second
func main() {
wait := flag.Int("w", 500, "wait per line (millisecond)")
flag.Parse()
wait_per_line := time.Duration(*wait) * time.Millisecond
start := time.Now()
stdin := bufio.NewScanner(os.Stdin)
for stdin.Scan() {
text := stdin.Text()
fmt.Println(text)
if time.Since(start) > full_speed_duaring {
time.Sleep(wait_per_line)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment