Update mauview

Fixes #367
This commit is contained in:
Tulir Asokan
2022-04-17 23:54:40 +03:00
parent c45a66bbf9
commit fa79dc0ca1
5 changed files with 18 additions and 26 deletions

View File

@ -84,9 +84,7 @@ func (ui *GomuksUI) Stop() {
}
func (ui *GomuksUI) Finish() {
if ui.app.Screen() != nil {
ui.app.Screen().Fini()
}
ui.app.ForceStop()
}
func (ui *GomuksUI) Render() {
@ -106,15 +104,7 @@ func (ui *GomuksUI) HandleNewPreferences() {
}
func (ui *GomuksUI) SetView(name View) {
ui.app.Root = ui.views[name]
focusable, ok := ui.app.Root.(mauview.Focusable)
if ok {
focusable.Focus()
}
if ui.app.Screen() != nil {
ui.app.Screen().Clear()
ui.Render()
}
ui.app.SetRoot(ui.views[name])
}
func (ui *GomuksUI) MainView() ifc.MainView {
@ -122,14 +112,14 @@ func (ui *GomuksUI) MainView() ifc.MainView {
}
func (ui *GomuksUI) RunExternal(executablePath string, args ...string) error {
var err error
callback := make(chan error)
ui.app.Suspend(func() {
cmd := exec.Command(executablePath, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = os.Environ()
err = cmd.Run()
callback <- cmd.Run()
})
return err
return <-callback
}

View File

@ -19,6 +19,8 @@ package ui
import (
"math"
"github.com/mattn/go-runewidth"
"go.mau.fi/mauview"
"go.mau.fi/tcell"
@ -139,7 +141,7 @@ func (view *LoginView) Error(err string) {
view.AddComponent(view.error, 1, 11, 3, 1)
}
view.error.SetText(err)
errorHeight := int(math.Ceil(float64(mauview.StringWidth(err)) / 45))
errorHeight := int(math.Ceil(float64(runewidth.StringWidth(err)) / 45))
view.container.SetHeight(14 + errorHeight)
view.SetRow(11, errorHeight)
}

View File

@ -41,8 +41,7 @@ func WriteLineColor(screen mauview.Screen, align int, line string, x, y, maxWidt
func WriteLine(screen mauview.Screen, align int, line string, x, y, maxWidth int, style tcell.Style) {
offsetX := 0
if align == mauview.AlignRight {
// TODO is mauview.StringWidth correct here?
offsetX = maxWidth - mauview.StringWidth(line)
offsetX = maxWidth - runewidth.StringWidth(line)
}
if offsetX < 0 {
offsetX = 0