-
Notifications
You must be signed in to change notification settings - Fork 0
/
df.go
82 lines (65 loc) · 1.31 KB
/
df.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"github.com/ayang64/doomfire/inferno"
"golang.org/x/crypto/ssh/terminal"
)
func fire(ctx context.Context) chan inferno.Dimensions {
rc := make(chan inferno.Dimensions)
go func() {
inf, err := inferno.NewFlame(inferno.WithDimentions(0, 0))
if err != nil {
return
}
for {
select {
case <-ctx.Done():
rc <- inferno.Dimensions{}
return
case dims := <-rc:
inf.SetDimensions(dims)
default:
// display grid
inf.Render()
// percollate values up
inf.Spread()
}
}
}()
return rc
}
func run() error {
width, height, err := terminal.GetSize(0)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
dims := fire(ctx)
dims <- inferno.Dimensions{Width: width, Height: height * 2}
sigs := make(chan os.Signal)
signal.Notify(sigs, syscall.SIGWINCH, syscall.SIGINT)
innerloop:
for sig := range sigs {
switch sig {
case syscall.SIGWINCH:
width, height, _ := terminal.GetSize(0)
dims <- inferno.Dimensions{Width: width, Height: height * 2}
case syscall.SIGINT:
cancel()
break innerloop
}
}
<-dims
os.Stdout.Write([]byte("\x1b[39;m"))
os.Stdout.Write([]byte("\x1b[49;m"))
return nil
}
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}