Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build on Plan 9 #163

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module github.com/cheggaaa/pb

require (
github.com/fatih/color v1.7.0
github.com/mattn/go-colorable v0.1.2
github.com/fatih/color v1.9.0
github.com/mattn/go-colorable v0.1.4
github.com/mattn/go-runewidth v0.0.4
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037
)

go 1.12
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
70 changes: 70 additions & 0 deletions pb_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package pb

import (
"errors"
"os"
"os/signal"
"sync"
"syscall"
)

var ErrPoolWasStarted = errors.New("Bar pool was started")

var (
echoLockMutex sync.Mutex
consctl *os.File
)

// terminalWidth returns width of the terminal.
func terminalWidth() (int, error) {
return 0, errors.New("Not Supported")
}

func lockEcho() (shutdownCh chan struct{}, err error) {
echoLockMutex.Lock()
defer echoLockMutex.Unlock()

if consctl != nil {
return nil, ErrPoolWasStarted
}
consctl, err = os.OpenFile("/dev/consctl", os.O_WRONLY, 0)
if err != nil {
return nil, err
}
_, err = consctl.WriteString("rawon")
if err != nil {
consctl.Close()
consctl = nil
return nil, err
}
shutdownCh = make(chan struct{})
go catchTerminate(shutdownCh)
return
}

func unlockEcho() error {
echoLockMutex.Lock()
defer echoLockMutex.Unlock()

if consctl == nil {
return nil
}
if err := consctl.Close(); err != nil {
return err
}
consctl = nil
return nil
}

// listen exit signals and restore terminal state
func catchTerminate(shutdownCh chan struct{}) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM, syscall.SIGKILL)
defer signal.Stop(sig)
select {
case <-shutdownCh:
unlockEcho()
case <-sig:
unlockEcho()
}
}
2 changes: 1 addition & 1 deletion pool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux darwin freebsd netbsd openbsd solaris dragonfly windows
// +build linux darwin freebsd netbsd openbsd solaris dragonfly windows plan9

package pb

Expand Down
2 changes: 1 addition & 1 deletion pool_x.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux darwin freebsd netbsd openbsd solaris dragonfly
// +build linux darwin freebsd netbsd openbsd solaris dragonfly plan9

package pb

Expand Down
3 changes: 1 addition & 2 deletions v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ require (
github.com/VividCortex/ewma v1.1.1
github.com/fatih/color v1.7.0
github.com/mattn/go-colorable v0.1.2
github.com/mattn/go-isatty v0.0.10
github.com/mattn/go-isatty v0.0.12
github.com/mattn/go-runewidth v0.0.7
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
)

go 1.12
4 changes: 4 additions & 0 deletions v3/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3 changes: 1 addition & 2 deletions v3/termutil/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"os/signal"
"sync"
"syscall"
)

var echoLocked bool
Expand Down Expand Up @@ -46,7 +45,7 @@ func RawModeOff() (err error) {
// listen exit signals and restore terminal state
func catchTerminate(quit chan struct{}) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(sig, unlockSignals...)
defer signal.Stop(sig)
select {
case <-quit:
Expand Down
50 changes: 50 additions & 0 deletions v3/termutil/term_plan9.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package termutil

import (
"errors"
"os"
"syscall"
)

var (
consctl *os.File

// Plan 9 doesn't have syscall.SIGQUIT
unlockSignals = []os.Signal{
os.Interrupt, syscall.SIGTERM, syscall.SIGKILL,
}
)

// TerminalWidth returns width of the terminal.
func TerminalWidth() (int, error) {
return 0, errors.New("Not supported")
}

func lockEcho() error {
if consctl != nil {
return errors.New("consctl already open")
}
var err error
consctl, err = os.OpenFile("/dev/consctl", os.O_WRONLY, 0)
if err != nil {
return err
}
_, err = consctl.WriteString("rawon")
if err != nil {
consctl.Close()
consctl = nil
return err
}
return nil
}

func unlockEcho() error {
if consctl == nil {
return nil
}
if err := consctl.Close(); err != nil {
return err
}
consctl = nil
return nil
}
8 changes: 7 additions & 1 deletion v3/termutil/term_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import (
"unsafe"
)

var tty = os.Stdin
var (
tty = os.Stdin

unlockSignals = []os.Signal{
os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
}
)

var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
Expand Down
8 changes: 7 additions & 1 deletion v3/termutil/term_x.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import (
"unsafe"
)

var tty *os.File
var (
tty *os.File

unlockSignals = []os.Signal{
os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
}
)

type window struct {
Row uint16
Expand Down