mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-21 23:01:03 +00:00
Merge pull request #103 from jesseduffield/window-check
bump gocui fork to check window size
This commit is contained in:
commit
91e3c0fb0f
4 changed files with 71 additions and 8 deletions
2
go.mod
2
go.mod
|
|
@ -15,7 +15,7 @@ require (
|
|||
github.com/imdario/mergo v0.3.7
|
||||
github.com/integrii/flaggy v0.0.0-20190517180110-07ea7eb77404
|
||||
github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190703115836-08c34c9081b3
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190706002342-e625df489460
|
||||
github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7
|
||||
github.com/jesseduffield/termbox-go v0.0.0-20190630083001-9dd53af7214e // indirect
|
||||
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -40,6 +40,10 @@ github.com/jesseduffield/gocui v0.3.1-0.20190703114758-e3a97494ac41 h1:WHt3Pmhgx
|
|||
github.com/jesseduffield/gocui v0.3.1-0.20190703114758-e3a97494ac41/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190703115836-08c34c9081b3 h1:F9a1FHBFAEa1Jqrd1+vc1UhwVCQH8yywV1qSNadO81U=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190703115836-08c34c9081b3/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190705132128-68f2ad6e3532 h1:PBs+XBBrhHBIfEm9uw0EcxG4hsFkUslwrjcgEOF6cfI=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190705132128-68f2ad6e3532/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190706002342-e625df489460 h1:ZE/5AVVJV5j7cVFvnQ/YsogDiUh544Qoh4ib/iVyKf8=
|
||||
github.com/jesseduffield/gocui v0.3.1-0.20190706002342-e625df489460/go.mod h1:2RtZznzYKt8RLRwvFiSkXjU0Ei8WwHdubgnlaYH47dw=
|
||||
github.com/jesseduffield/roll v0.0.0-20190629104057-695be2e62b00 h1:+JaOkfBNYQYlGD7dgru8mCwYNEc5tRRI8mThlVANhSM=
|
||||
github.com/jesseduffield/roll v0.0.0-20190629104057-695be2e62b00/go.mod h1:cWNQljQAWYBp4wchyGfql4q2jRNZXxiE1KhVQgz+JaM=
|
||||
github.com/jesseduffield/rollrus v0.0.0-20190701125922-dd028cb0bfd7 h1:CRD7bVjlGIiV+M0jlsa+XWpneW0KY0e7Y4z3GWb5S4o=
|
||||
|
|
|
|||
71
vendor/github.com/jesseduffield/gocui/gui.go
generated
vendored
71
vendor/github.com/jesseduffield/gocui/gui.go
generated
vendored
|
|
@ -6,16 +6,19 @@ package gocui
|
|||
|
||||
import (
|
||||
standardErrors "errors"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
|
||||
"github.com/jesseduffield/termbox-go"
|
||||
)
|
||||
|
||||
// this comment is here for no good reason (or is it) (I think it is)
|
||||
|
||||
var (
|
||||
// ErrQuit is used to decide if the MainLoop finished successfully.
|
||||
ErrQuit = standardErrors.New("quit")
|
||||
|
|
@ -95,12 +98,21 @@ type Gui struct {
|
|||
|
||||
// NewGui returns a new Gui object with a given output mode.
|
||||
func NewGui(mode OutputMode, supportOverlaps bool) (*Gui, error) {
|
||||
g := &Gui{}
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
var err error
|
||||
if g.maxX, g.maxY, err = g.getTermWindowSize(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
g.maxX, g.maxY = termbox.Size()
|
||||
}
|
||||
|
||||
if err := termbox.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
g := &Gui{}
|
||||
|
||||
g.outputMode = mode
|
||||
termbox.SetOutputMode(termbox.OutputMode(mode))
|
||||
|
||||
|
|
@ -109,8 +121,6 @@ func NewGui(mode OutputMode, supportOverlaps bool) (*Gui, error) {
|
|||
g.tbEvents = make(chan termbox.Event, 20)
|
||||
g.userEvents = make(chan userEvent, 20)
|
||||
|
||||
g.maxX, g.maxY = termbox.Size()
|
||||
|
||||
g.BgColor, g.FgColor = ColorDefault, ColorDefault
|
||||
g.SelBgColor, g.SelFgColor = ColorDefault, ColorDefault
|
||||
|
||||
|
|
@ -848,3 +858,52 @@ func (g *Gui) loaderTick() {
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
type windowSize struct {
|
||||
rows uint16
|
||||
cols uint16
|
||||
xpixels uint16
|
||||
ypixels uint16
|
||||
}
|
||||
|
||||
// getTermWindowSize is get terminal window size on linux or unix.
|
||||
// When gocui run inside the docker contaienr need to check and get the window size.
|
||||
func (g *Gui) getTermWindowSize() (int, int, error) {
|
||||
out, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
signalCh := make(chan os.Signal, 1)
|
||||
signal.Notify(signalCh, syscall.SIGWINCH, syscall.SIGINT)
|
||||
defer signal.Stop(signalCh)
|
||||
|
||||
var sz windowSize
|
||||
|
||||
for {
|
||||
_, _, err = syscall.Syscall(
|
||||
syscall.SYS_IOCTL,
|
||||
out.Fd(),
|
||||
uintptr(syscall.TIOCGWINSZ),
|
||||
uintptr(unsafe.Pointer(&sz)),
|
||||
)
|
||||
|
||||
// check terminal window size
|
||||
if sz.cols > 0 && sz.rows > 0 {
|
||||
return int(sz.cols), int(sz.rows), nil
|
||||
}
|
||||
|
||||
select {
|
||||
case signal := <-signalCh:
|
||||
switch signal {
|
||||
// when the terminal window size is changed
|
||||
case syscall.SIGWINCH:
|
||||
continue
|
||||
// ctrl + c to cancel
|
||||
case syscall.SIGINT:
|
||||
return 0, 0, errors.New("There was not enough window space to start the application")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
|
@ -42,7 +42,7 @@ github.com/imdario/mergo
|
|||
github.com/integrii/flaggy
|
||||
# github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee
|
||||
github.com/jesseduffield/asciigraph
|
||||
# github.com/jesseduffield/gocui v0.3.1-0.20190703115836-08c34c9081b3
|
||||
# github.com/jesseduffield/gocui v0.3.1-0.20190706002342-e625df489460
|
||||
github.com/jesseduffield/gocui
|
||||
# github.com/jesseduffield/roll v0.0.0-20190629104057-695be2e62b00
|
||||
github.com/jesseduffield/roll
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue