Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Start watching Star Wars Episode IV from a shell like this:
curl https://asciitv.fr
```

Parameters
- `speed` - Any integer (default: 1)

<img src="./demo.svg">

## Credits
Expand Down
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type frame struct {
duration time.Duration
}

var speed = 1 // Default speed of the movie

func main() {
moviePtr := flag.String("movie", "resources/sw1.txt", "path to ASCII movie file")
addrPtr := flag.String("addr", ":8080", "TCP address to listen on")
Expand Down Expand Up @@ -44,16 +46,28 @@ func main() {
fmt.Fprintf(w, "Web browsers are so %d, use \"curl https://asciitv.fr\" from your terminal instead!\n", time.Now().Year()-1)
return
}

if value, ok := r.URL.Query()["speed"]; ok {
if speedInt, err := strconv.Atoi(value[0]); err == nil {
speed = speedInt
}
}

for _, frame := range frames {
// Clear terminal and move cursor to position (1,1)
fmt.Fprint(w, "\033[2J\033[1;1H")
for _, line := range frame.lines {
fmt.Fprintln(w, line)
}

if speed != 1 {
fmt.Fprintln(w, "\n\nSpeed:", speed)
}

if f, ok := w.(http.Flusher); ok {
f.Flush()
}
time.Sleep(frame.duration * time.Second / 15)
time.Sleep((frame.duration / time.Duration(speed)) * time.Second / 15)
}
})

Expand Down