From 02c40b05f905802888914b17c91d4dc3ec605094 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 3 Nov 2021 01:05:42 +0900 Subject: [PATCH] Support Windows --- confetti/confetti.go | 9 --------- confetti/confetti_unix.go | 16 ++++++++++++++++ confetti/confetti_windows.go | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 confetti/confetti_unix.go create mode 100644 confetti/confetti_windows.go diff --git a/confetti/confetti.go b/confetti/confetti.go index faf3a9a..8647f1a 100644 --- a/confetti/confetti.go +++ b/confetti/confetti.go @@ -10,7 +10,6 @@ import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" - "golang.org/x/term" ) const ( @@ -59,14 +58,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/confetti/confetti_unix.go b/confetti/confetti_unix.go new file mode 100644 index 0000000..91e6cfd --- /dev/null +++ b/confetti/confetti_unix.go @@ -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) +} diff --git a/confetti/confetti_windows.go b/confetti/confetti_windows.go new file mode 100644 index 0000000..6bc640a --- /dev/null +++ b/confetti/confetti_windows.go @@ -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) +}