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() { func (gmx *gomuks) Stop() {
gmx.debug.Print("Disconnecting from Matrix...")
gmx.matrix.Stop() gmx.matrix.Stop()
gmx.debug.Print("Cleaning up UI...")
gmx.app.Stop() gmx.app.Stop()
if gmx.config.Session != nil { if gmx.config.Session != nil {
gmx.debug.Print("Saving session...")
gmx.config.Session.Save() gmx.config.Session.Save()
} }
} }

View File

@ -103,9 +103,11 @@ func (c *MatrixContainer) Login(user, password string) error {
} }
func (c *MatrixContainer) Stop() { func (c *MatrixContainer) Stop() {
if c.running {
c.stop <- true c.stop <- true
c.client.StopSync() c.client.StopSync()
} }
}
func (c *MatrixContainer) UpdateRoomList() { func (c *MatrixContainer) UpdateRoomList() {
rooms, err := c.client.JoinedRooms() rooms, err := c.client.JoinedRooms()

8
ui.go
View File

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

View File

@ -20,35 +20,31 @@ import (
"maunium.net/go/tview" "maunium.net/go/tview"
) )
func (ui *GomuksUI) MakeLoginUI() tview.Primitive { func (ui *GomuksUI) NewLoginView() tview.Primitive {
form := tview.NewForm().SetButtonsAlign(tview.AlignCenter)
hs := ui.config.HS hs := ui.config.HS
if len(hs) == 0 { if len(hs) == 0 {
hs = "https://matrix.org" 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("Homeserver", hs, 30, nil, nil).
AddInputField("Username", ui.config.MXID, 30, nil, nil). AddInputField("Username", ui.config.MXID, 30, nil, nil).
AddPasswordField("Password", "", 30, '*', nil). AddPasswordField("Password", "", 30, '*', nil).
AddButton("Log in", ui.login(form)) AddButton("Log in", ui.login).
form.SetBorder(true).SetTitle("Log in to Matrix") AddButton("Quit", ui.gmx.Stop).
return Center(45, 13, form) SetButtonsAlign(tview.AlignCenter).
SetBorder(true).SetTitle("Log in to Matrix")
return Center(45, 11, ui.loginView)
} }
func (ui *GomuksUI) login(form *tview.Form) func() { func (ui *GomuksUI) login() {
return func() { hs := ui.loginView.GetFormItem(0).(*tview.InputField).GetText()
hs := form.GetFormItem(0).(*tview.InputField).GetText() mxid := ui.loginView.GetFormItem(1).(*tview.InputField).GetText()
mxid := form.GetFormItem(1).(*tview.InputField).GetText() password := ui.loginView.GetFormItem(2).(*tview.InputField).GetText()
password := form.GetFormItem(2).(*tview.InputField).GetText()
ui.debug.Printf("Logging into %s as %s...", hs, mxid) ui.debug.Printf("Logging into %s as %s...", hs, mxid)
ui.config.HS = hs ui.config.HS = hs
ui.debug.Print(ui.matrix.InitClient()) ui.debug.Print("Connect result:", ui.matrix.InitClient())
ui.debug.Print(ui.matrix.Login(mxid, password)) 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) view.Grid.AddItem(p, x, y, w, h, 0, 0, false)
} }
func (ui *GomuksUI) NewMainView() *MainView { func (ui *GomuksUI) NewMainView() tview.Primitive {
mainUI := &MainView{ mainView := &MainView{
Grid: tview.NewGrid(), Grid: tview.NewGrid(),
roomList: tview.NewList(), roomList: tview.NewList(),
roomView: tview.NewPages(), roomView: tview.NewPages(),
@ -60,27 +60,34 @@ func (ui *GomuksUI) NewMainView() *MainView {
parent: ui, parent: ui,
} }
mainUI.SetColumns(30, 1, 0).SetRows(0, 1) mainView.SetColumns(30, 1, 0).SetRows(0, 1)
mainUI.roomList. mainView.roomList.
ShowSecondaryText(false). ShowSecondaryText(false).
SetBorderPadding(0, 0, 1, 0) SetBorderPadding(0, 0, 1, 0)
mainUI.input. mainView.input.
SetDoneFunc(mainUI.InputDone). SetDoneFunc(mainView.InputDone).
SetChangedFunc(mainUI.InputChanged). SetChangedFunc(mainView.InputChanged).
SetInputCapture(mainUI.InputCapture) SetFieldBackgroundColor(tcell.ColorDefault).
SetInputCapture(mainView.InputCapture)
mainUI.addItem(mainUI.roomList, 0, 0, 2, 1) mainView.addItem(mainView.roomList, 0, 0, 2, 1)
mainUI.addItem(NewBorder(), 0, 1, 2, 1) mainView.addItem(NewBorder(), 0, 1, 2, 1)
mainUI.addItem(mainUI.roomView, 0, 2, 1, 1) mainView.addItem(mainView.roomView, 0, 2, 1, 1)
mainUI.AddItem(mainUI.input, 1, 2, 1, 1, 0, 0, true) mainView.AddItem(mainView.input, 1, 2, 1, 1, 0, 0, true)
return mainUI ui.mainView = mainView
return mainView
} }
func (view *MainView) InputChanged(text string) { 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) { func (view *MainView) InputDone(key tcell.Key) {