Skip to content

Commit

Permalink
Add Windows support
Browse files Browse the repository at this point in the history
Prior to this commit the support for Windows was limited to modern
temrinal emulators.

This commit uses colorable.NewColorableStout() if we detect a windows
OS. This handles the interpretation of the tput escape sequences and
color printing.

Currently tested on Server 2019
* cmd.exe
* pwsh 7.2
  • Loading branch information
chelnak committed Jul 20, 2022
1 parent 650cd27 commit 9b55564
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure('2') do |config|
config.vm.box = 'gusztavvargadr/windows-server-2019-standard'

config.vm.provider 'virtualbox' do |vb|
vb.memory = 8192
vb.cpus = 4
end

config.vm.provision 'shell', path: '../scripts/bootstrap.ps1'
profile_destination = 'C:\Users\vagrant\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
config.vm.provision 'file', source: '../scripts/profile.ps1', destination: profile_destination
end
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ module github.com/chelnak/ysmrr

go 1.18

require github.com/fatih/color v1.13.0
require (
github.com/fatih/color v1.13.0
github.com/mattn/go-colorable v0.1.9
github.com/stretchr/testify v1.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
14 changes: 12 additions & 2 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"io"
"os"
"os/signal"
"runtime"
"time"

"github.com/chelnak/ysmrr/pkg/charmap"
"github.com/chelnak/ysmrr/pkg/colors"
"github.com/chelnak/ysmrr/pkg/tput"
"github.com/mattn/go-colorable"
)

// SpinnerManager manages spinners
Expand Down Expand Up @@ -51,7 +53,6 @@ func (sm *spinnerManager) AddSpinner(message string) *Spinner {
ErrorColor: sm.errorColor,
MessageColor: sm.messageColor,
}

spinner := NewSpinner(opts)
sm.spinners = append(sm.spinners, spinner)
return spinner
Expand Down Expand Up @@ -184,7 +185,7 @@ func NewSpinnerManager(options ...Option) SpinnerManager {
errorColor: colors.FgHiRed,
completeColor: colors.FgHiGreen,
messageColor: colors.NoColor,
writer: os.Stdout,
writer: getWriter(),
done: make(chan bool),
}

Expand All @@ -195,6 +196,15 @@ func NewSpinnerManager(options ...Option) SpinnerManager {
return sm
}

func getWriter() io.Writer {
// Windows support conveniently provided by github.com/mattn/go-colorable <3.
if runtime.GOOS == "windows" {
return colorable.NewColorableStdout()
} else {
return os.Stdout
}
}

// WithCharMap sets the characters used for the spinners.
// Available charmaps can be found in the package github.com/chelnak/ysmrr/pkg/charmap.
// The default charmap is the Dots.
Expand Down

0 comments on commit 9b55564

Please sign in to comment.