Last active
November 20, 2018 06:19
-
-
Save RitterHou/0ec4726577b0bbc7d241beb443b5c2b1 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
"path" | |
"time" | |
) | |
var ( | |
root string | |
interval int | |
) | |
func init() { | |
dir, err := os.Getwd() | |
if err != nil { | |
log.Fatal(err) | |
} | |
root = dir | |
flag.IntVar(&interval, "i", 120, "print interval") | |
flag.Parse() | |
} | |
func getAbsPath(filename string) (absPath string) { | |
absPath = path.Join(root, filename) | |
if _, err := os.Stat(absPath); os.IsNotExist(err) { | |
log.Fatalf("file '%s' not exist\n", filename) | |
} | |
return | |
} | |
func main() { | |
args := flag.Args() | |
if len(args) == 0 { | |
log.Fatal("error: no input file\n") | |
} | |
filename := args[0] | |
data, err := ioutil.ReadFile(getAbsPath(filename)) | |
if err != nil { | |
log.Fatal(err) | |
} | |
characters := []rune(string(data)) | |
for _, char := range characters { | |
time.Sleep(time.Millisecond * time.Duration(interval)) | |
fmt.Print(string(char)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment