Support Windows

This commit is contained in:
Yasuhiro Matsumoto 2021-11-03 01:05:42 +09:00 committed by Maas Lalani
parent eef558b980
commit 02c40b05f9
3 changed files with 38 additions and 9 deletions

View File

@ -10,7 +10,6 @@ import (
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"golang.org/x/term"
) )
const ( const (
@ -59,14 +58,6 @@ func Spawn(width, height int) []simulation.Particle {
return particles return particles
} }
func InitialModel() model {
width, height, err := term.GetSize(0)
if err != nil {
panic(err)
}
return InitialModelWithSize(width, height)
}
func InitialModelWithSize(width, height int) model { func InitialModelWithSize(width, height int) model {
return model{system: &simulation.System{ return model{system: &simulation.System{
Particles: Spawn(width, height), Particles: Spawn(width, height),

16
confetti/confetti_unix.go Normal file
View File

@ -0,0 +1,16 @@
//go:build !windows
// +build !windows
package confetti
import (
"golang.org/x/term"
)
func InitialModel() model {
width, height, err := term.GetSize(0)
if err != nil {
panic(err)
}
return InitialModelWithSize(width, height)
}

View File

@ -0,0 +1,22 @@
//go:build windows
// +build windows
package confetti
import (
"syscall"
"golang.org/x/term"
)
func InitialModel() model {
h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
if err != nil {
panic(err)
}
width, height, err := term.GetSize(int(h))
if err != nil {
panic(err)
}
return InitialModelWithSize(width, height)
}