Repaint on terminal resize

This commit is contained in:
Christian Rocha 2020-05-18 17:53:46 -04:00 committed by Christian Muehlhaeuser
parent 95fe84ebb4
commit 883fda2b06
3 changed files with 21 additions and 6 deletions

4
go.mod
View file

@ -3,8 +3,8 @@ module github.com/charmbracelet/glow
go 1.13
require (
github.com/charmbracelet/boba v0.5.1
github.com/charmbracelet/charm v0.3.1
github.com/charmbracelet/boba v0.6.0
github.com/charmbracelet/charm v0.4.0
github.com/charmbracelet/glamour v0.2.0
github.com/charmbracelet/tea v0.3.0
github.com/charmbracelet/teaparty v0.0.0-20200504225426-da64445a0e0d

8
go.sum
View file

@ -16,10 +16,10 @@ github.com/calmh/randomart v1.1.0 h1:evl+iwc10LXtHdMZhzLxmsCQVmWnkXs44SbC6Uk0Il8
github.com/calmh/randomart v1.1.0/go.mod h1:DQUbPVyP+7PAs21w/AnfMKG5NioxS3TbZ2F9MSK/jFM=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/charmbracelet/boba v0.5.0/go.mod h1:xqhji08CbPctzbvCi/GzmNvIFOhnWJnkl9N8T65gnK0=
github.com/charmbracelet/boba v0.5.1 h1:vC+2NPZM4ccoRHKzRhvzXNJaACN/EtAn1yQ0VSYGQ+w=
github.com/charmbracelet/boba v0.5.1/go.mod h1:xqhji08CbPctzbvCi/GzmNvIFOhnWJnkl9N8T65gnK0=
github.com/charmbracelet/charm v0.3.1 h1:5cuEcfl8yUdKKJDFoYyZvr6emdRvrIzPBf8zCwwjCdM=
github.com/charmbracelet/charm v0.3.1/go.mod h1:bZQON+c4uV9mgbZBvKzH7wA1zGII9Zfg26cL70NYdH0=
github.com/charmbracelet/boba v0.6.0 h1:ktCY611UE4ZJ4MS0FS6eCA/jqjJDyfNgFfdDKBgi07g=
github.com/charmbracelet/boba v0.6.0/go.mod h1:xqhji08CbPctzbvCi/GzmNvIFOhnWJnkl9N8T65gnK0=
github.com/charmbracelet/charm v0.4.0 h1:g76242+CxC7fPiOYTmb81q0ehFb2JpUr6yD7bbe/tM4=
github.com/charmbracelet/charm v0.4.0/go.mod h1:bZQON+c4uV9mgbZBvKzH7wA1zGII9Zfg26cL70NYdH0=
github.com/charmbracelet/glamour v0.2.0 h1:mTgaiNiumpqTZp3qVM6DH9UB0NlbY17wejoMf1kM8Pg=
github.com/charmbracelet/glamour v0.2.0/go.mod h1:UA27Kwj3QHialP74iU6C+Gpc8Y7IOAKupeKMLLBURWM=
github.com/charmbracelet/tea v0.2.0/go.mod h1:lADjwO2mMub9qvXSCA9vAkabVWO0HeUrv4uO/lG3C+k=

View file

@ -39,6 +39,7 @@ type errMsg error
type newCharmClientMsg *charm.Client
type sshAuthErrMsg struct{}
type contentRenderedMsg string
type terminalResizedMsg struct{}
type terminalSizeMsg struct {
width int
@ -107,6 +108,7 @@ func initialize(style string) func() (boba.Model, boba.Cmd) {
newCharmClient,
spinner.Tick(s),
getTerminalSize(),
listenForTerminalResize(),
)
}
}
@ -151,6 +153,12 @@ func update(msg boba.Msg, mdl boba.Model) (boba.Model, boba.Cmd) {
m.err = msg
return m, nil
case terminalResizedMsg:
return m, boba.Batch(
getTerminalSize(),
listenForTerminalResize(),
)
case terminalSizeMsg:
if msg.Error() != nil {
m.err = msg.Error()
@ -312,6 +320,13 @@ func statusBarView(m model) string {
}
// COMMANDS
func listenForTerminalResize() boba.Cmd {
return boba.OnResize(func() boba.Msg {
return terminalResizedMsg{}
})
}
func getTerminalSize() boba.Cmd {
return boba.GetTerminalSize(func(w, h int, err error) boba.TerminalSizeMsg {
return terminalSizeMsg{width: w, height: h, err: err}