Last active
October 3, 2019 10:56
-
-
Save pazworld/30f96bdd1d9ec3cc67b6b648ff09a20c to your computer and use it in GitHub Desktop.
slow pager first show stdin with fullspeed, then slow down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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