From 4c38fa40387973f82579a612b7ae3f596b7e959b Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 3 Nov 2021 10:03:47 +0900 Subject: [PATCH] Another fix on Windows --- fireworks/fireworks.go | 9 --------- fireworks/fireworks_unix.go | 16 ++++++++++++++++ fireworks/fireworks_windows.go | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 fireworks/fireworks_unix.go create mode 100644 fireworks/fireworks_windows.go diff --git a/fireworks/fireworks.go b/fireworks/fireworks.go index 3824221..485eebd 100644 --- a/fireworks/fireworks.go +++ b/fireworks/fireworks.go @@ -11,7 +11,6 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" - "golang.org/x/term" ) const ( @@ -60,14 +59,6 @@ func Spawn(width, height int) []simulation.Particle { 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 { return model{system: &simulation.System{ Particles: Spawn(width, height), diff --git a/fireworks/fireworks_unix.go b/fireworks/fireworks_unix.go new file mode 100644 index 0000000..0448347 --- /dev/null +++ b/fireworks/fireworks_unix.go @@ -0,0 +1,16 @@ +//go:build !windows +// +build !windows + +package fireworks + +import ( + "golang.org/x/term" +) + +func InitialModel() model { + width, height, err := term.GetSize(0) + if err != nil { + panic(err) + } + return InitialModelWithSize(width, height) +} diff --git a/fireworks/fireworks_windows.go b/fireworks/fireworks_windows.go new file mode 100644 index 0000000..c8298ad --- /dev/null +++ b/fireworks/fireworks_windows.go @@ -0,0 +1,22 @@ +//go:build windows +// +build windows + +package fireworks + +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) +}