mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
Start work on tui
This commit is contained in:
parent
6a96f3f800
commit
cb7d053d9e
2 changed files with 94 additions and 13 deletions
24
tui/tui.go
24
tui/tui.go
|
@ -25,13 +25,21 @@ import (
|
||||||
"go.mau.fi/gomuks/pkg/gomuks"
|
"go.mau.fi/gomuks/pkg/gomuks"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type View string
|
||||||
|
|
||||||
|
// Allowed views in GomuksTUI
|
||||||
type GomuksTUI struct {
|
type GomuksTUI struct {
|
||||||
*gomuks.Gomuks
|
*gomuks.Gomuks
|
||||||
App *mauview.Application
|
App *mauview.Application
|
||||||
|
|
||||||
|
loginView *LoginView
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(gmx *gomuks.Gomuks) *GomuksTUI {
|
func New(gmx *gomuks.Gomuks) *GomuksTUI {
|
||||||
return &GomuksTUI{Gomuks: gmx}
|
return &GomuksTUI{
|
||||||
|
Gomuks: gmx,
|
||||||
|
App: mauview.NewApplication(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -44,22 +52,12 @@ func init() {
|
||||||
os.Setenv("TCELLDB", "/usr/share/tcell/database")
|
os.Setenv("TCELLDB", "/usr/share/tcell/database")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gt *GomuksTUI) Run() {
|
func (gt *GomuksTUI) Run() {
|
||||||
gt.App = mauview.NewApplication()
|
gt.App = mauview.NewApplication()
|
||||||
view := mauview.NewBox(mauview.NewTextView().SetText("Mui.")).SetBorder(true)
|
gt.App.SetRoot(gt.NewLoginView())
|
||||||
view.SetKeyCaptureFunc(func(event mauview.KeyEvent) mauview.KeyEvent {
|
|
||||||
if event.Key() == tcell.KeyEsc || event.Rune() == 'q' {
|
|
||||||
gt.App.ForceStop()
|
|
||||||
}
|
|
||||||
return event
|
|
||||||
})
|
|
||||||
gt.App.SetRoot(view)
|
|
||||||
go func() {
|
|
||||||
gt.Gomuks.WaitForInterrupt()
|
|
||||||
gt.App.ForceStop()
|
|
||||||
}()
|
|
||||||
err := gt.App.Start()
|
err := gt.App.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
83
tui/view-login.go
Normal file
83
tui/view-login.go
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"go.mau.fi/mauview"
|
||||||
|
"maunium.net/go/gomuks/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoginView struct {
|
||||||
|
*mauview.Form
|
||||||
|
|
||||||
|
container *mauview.Centerer
|
||||||
|
|
||||||
|
homeserverLabel *mauview.TextField
|
||||||
|
idLabel *mauview.TextField
|
||||||
|
passwordLabel *mauview.TextField
|
||||||
|
|
||||||
|
homeserver *mauview.InputField
|
||||||
|
id *mauview.InputField
|
||||||
|
password *mauview.InputField
|
||||||
|
error *mauview.TextView
|
||||||
|
|
||||||
|
loginButton *mauview.Button
|
||||||
|
quitButton *mauview.Button
|
||||||
|
|
||||||
|
loading bool
|
||||||
|
|
||||||
|
config *config.Config
|
||||||
|
parent *GomuksTUI
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gt *GomuksTUI) NewLoginView() mauview.Component {
|
||||||
|
view := &LoginView{
|
||||||
|
Form: mauview.NewForm(),
|
||||||
|
|
||||||
|
idLabel: mauview.NewTextField().SetText("User ID"),
|
||||||
|
passwordLabel: mauview.NewTextField().SetText("Password"),
|
||||||
|
homeserverLabel: mauview.NewTextField().SetText("Homeserver"),
|
||||||
|
|
||||||
|
id: mauview.NewInputField(),
|
||||||
|
password: mauview.NewInputField(),
|
||||||
|
homeserver: mauview.NewInputField(),
|
||||||
|
|
||||||
|
loginButton: mauview.NewButton("Login"),
|
||||||
|
quitButton: mauview.NewButton("Quit"),
|
||||||
|
|
||||||
|
parent: gt,
|
||||||
|
}
|
||||||
|
|
||||||
|
view.homeserver.SetPlaceholder("https://example.com").SetText("").SetTextColor(tcell.ColorWhite)
|
||||||
|
view.id.SetPlaceholder("@user:example.com").SetText("").SetTextColor(tcell.ColorWhite)
|
||||||
|
view.password.SetPlaceholder("correct horse battery staple").SetMaskCharacter('*').SetTextColor(tcell.ColorWhite)
|
||||||
|
|
||||||
|
view.quitButton.
|
||||||
|
SetOnClick(gt.App.ForceStop).
|
||||||
|
SetBackgroundColor(tcell.ColorDarkCyan).
|
||||||
|
SetForegroundColor(tcell.ColorWhite).
|
||||||
|
SetFocusedForegroundColor(tcell.ColorWhite)
|
||||||
|
view.loginButton.
|
||||||
|
SetBackgroundColor(tcell.ColorDarkCyan).
|
||||||
|
SetForegroundColor(tcell.ColorWhite).
|
||||||
|
SetFocusedForegroundColor(tcell.ColorWhite)
|
||||||
|
|
||||||
|
view.
|
||||||
|
SetColumns([]int{1, 10, 1, 30, 1}).
|
||||||
|
SetRows([]int{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
|
||||||
|
view.
|
||||||
|
AddFormItem(view.id, 3, 1, 1, 1).
|
||||||
|
AddFormItem(view.password, 3, 3, 1, 1).
|
||||||
|
AddFormItem(view.homeserver, 3, 5, 1, 1).
|
||||||
|
AddFormItem(view.loginButton, 1, 7, 3, 1).
|
||||||
|
AddFormItem(view.quitButton, 1, 9, 3, 1).
|
||||||
|
AddComponent(view.idLabel, 1, 1, 1, 1).
|
||||||
|
AddComponent(view.passwordLabel, 1, 3, 1, 1).
|
||||||
|
AddComponent(view.homeserverLabel, 1, 5, 1, 1)
|
||||||
|
view.FocusNextItem()
|
||||||
|
gt.loginView = view
|
||||||
|
|
||||||
|
view.container = mauview.Center(mauview.NewBox(view).SetTitle("Log in to Matrix"), 45, 13)
|
||||||
|
view.container.SetAlwaysFocusChild(true)
|
||||||
|
return view.container
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue