HAAAAAAAAANDS

This commit is contained in:
Tulir Asokan 2018-03-15 21:28:21 +02:00
parent 2bf057d27c
commit f99cede432
5 changed files with 49 additions and 41 deletions

View File

@ -73,9 +73,12 @@ func NewGomuks(debug bool) *gomuks {
}
func (gmx *gomuks) Stop() {
gmx.debug.Print("Disconnecting from Matrix...")
gmx.matrix.Stop()
gmx.debug.Print("Cleaning up UI...")
gmx.app.Stop()
if gmx.config.Session != nil {
gmx.debug.Print("Saving session...")
gmx.config.Session.Save()
}
}

View File

@ -103,8 +103,10 @@ func (c *MatrixContainer) Login(user, password string) error {
}
func (c *MatrixContainer) Stop() {
c.stop <- true
c.client.StopSync()
if c.running {
c.stop <- true
c.client.StopSync()
}
}
func (c *MatrixContainer) UpdateRoomList() {

10
ui.go
View File

@ -35,12 +35,13 @@ type GomuksUI struct {
config *Config
views *tview.Pages
mainView *MainView
mainView *MainView
loginView *tview.Form
}
func init() {
tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault
tview.Styles.ContrastBackgroundColor = tcell.ColorDefault
tview.Styles.ContrastBackgroundColor = tcell.ColorDarkGreen
}
func NewGomuksUI(gmx Gomuks) (ui *GomuksUI) {
@ -65,9 +66,8 @@ func (ui *GomuksUI) SetView(name string) {
}
func (ui *GomuksUI) InitViews() tview.Primitive {
ui.mainView = ui.NewMainView()
ui.views.AddPage(ViewLogin, ui.MakeLoginUI(), true, true)
ui.views.AddPage(ViewMain, ui.mainView, true, false)
ui.views.AddPage(ViewLogin, ui.NewLoginView(), true, true)
ui.views.AddPage(ViewMain, ui.NewMainView(), true, false)
return ui.views
}

View File

@ -20,35 +20,31 @@ import (
"maunium.net/go/tview"
)
func (ui *GomuksUI) MakeLoginUI() tview.Primitive {
form := tview.NewForm().SetButtonsAlign(tview.AlignCenter)
func (ui *GomuksUI) NewLoginView() tview.Primitive {
hs := ui.config.HS
if len(hs) == 0 {
hs = "https://matrix.org"
}
// homeserver := tview.NewInputField().SetLabel("Homeserver").SetText(hs).SetFieldWidth(30)
// username := tview.NewInputField().SetLabel("Username").SetText(ui.config.MXID).SetFieldWidth(30)
// password := tview.NewInputField().SetLabel("Password").SetMaskCharacter('*').SetFieldWidth(30)
// form.AddFormItem(homeserver).AddFormItem(username).AddFormItem(password)
form.
ui.loginView = tview.NewForm()
ui.loginView.
AddInputField("Homeserver", hs, 30, nil, nil).
AddInputField("Username", ui.config.MXID, 30, nil, nil).
AddPasswordField("Password", "", 30, '*', nil).
AddButton("Log in", ui.login(form))
form.SetBorder(true).SetTitle("Log in to Matrix")
return Center(45, 13, form)
AddButton("Log in", ui.login).
AddButton("Quit", ui.gmx.Stop).
SetButtonsAlign(tview.AlignCenter).
SetBorder(true).SetTitle("Log in to Matrix")
return Center(45, 11, ui.loginView)
}
func (ui *GomuksUI) login(form *tview.Form) func() {
return func() {
hs := form.GetFormItem(0).(*tview.InputField).GetText()
mxid := form.GetFormItem(1).(*tview.InputField).GetText()
password := form.GetFormItem(2).(*tview.InputField).GetText()
func (ui *GomuksUI) login() {
hs := ui.loginView.GetFormItem(0).(*tview.InputField).GetText()
mxid := ui.loginView.GetFormItem(1).(*tview.InputField).GetText()
password := ui.loginView.GetFormItem(2).(*tview.InputField).GetText()
ui.debug.Printf("Logging into %s as %s...", hs, mxid)
ui.config.HS = hs
ui.debug.Print(ui.matrix.InitClient())
ui.debug.Print(ui.matrix.Login(mxid, password))
}
ui.debug.Printf("Logging into %s as %s...", hs, mxid)
ui.config.HS = hs
ui.debug.Print("Connect result:", ui.matrix.InitClient())
ui.debug.Print("Login result:", ui.matrix.Login(mxid, password))
}

View File

@ -45,8 +45,8 @@ func (view *MainView) addItem(p tview.Primitive, x, y, w, h int) {
view.Grid.AddItem(p, x, y, w, h, 0, 0, false)
}
func (ui *GomuksUI) NewMainView() *MainView {
mainUI := &MainView{
func (ui *GomuksUI) NewMainView() tview.Primitive {
mainView := &MainView{
Grid: tview.NewGrid(),
roomList: tview.NewList(),
roomView: tview.NewPages(),
@ -60,27 +60,34 @@ func (ui *GomuksUI) NewMainView() *MainView {
parent: ui,
}
mainUI.SetColumns(30, 1, 0).SetRows(0, 1)
mainView.SetColumns(30, 1, 0).SetRows(0, 1)
mainUI.roomList.
mainView.roomList.
ShowSecondaryText(false).
SetBorderPadding(0, 0, 1, 0)
mainUI.input.
SetDoneFunc(mainUI.InputDone).
SetChangedFunc(mainUI.InputChanged).
SetInputCapture(mainUI.InputCapture)
mainView.input.
SetDoneFunc(mainView.InputDone).
SetChangedFunc(mainView.InputChanged).
SetFieldBackgroundColor(tcell.ColorDefault).
SetInputCapture(mainView.InputCapture)
mainUI.addItem(mainUI.roomList, 0, 0, 2, 1)
mainUI.addItem(NewBorder(), 0, 1, 2, 1)
mainUI.addItem(mainUI.roomView, 0, 2, 1, 1)
mainUI.AddItem(mainUI.input, 1, 2, 1, 1, 0, 0, true)
mainView.addItem(mainView.roomList, 0, 0, 2, 1)
mainView.addItem(NewBorder(), 0, 1, 2, 1)
mainView.addItem(mainView.roomView, 0, 2, 1, 1)
mainView.AddItem(mainView.input, 1, 2, 1, 1, 0, 0, true)
return mainUI
ui.mainView = mainView
return mainView
}
func (view *MainView) InputChanged(text string) {
view.matrix.SendTyping(view.CurrentRoomID(), len(text) > 0)
if len(text) == 0 {
view.matrix.SendTyping(view.CurrentRoomID(), false)
} else if text[0] != '/' {
view.matrix.SendTyping(view.CurrentRoomID(), true)
}
}
func (view *MainView) InputDone(key tcell.Key) {