aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gomuks.go3
-rw-r--r--matrix.go6
-rw-r--r--ui.go10
-rw-r--r--view-login.go36
-rw-r--r--view-main.go35
5 files changed, 49 insertions, 41 deletions
diff --git a/gomuks.go b/gomuks.go
index 3e2fb85..acb64c9 100644
--- a/gomuks.go
+++ b/gomuks.go
@@ -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()
}
}
diff --git a/matrix.go b/matrix.go
index 6a75966..9200649 100644
--- a/matrix.go
+++ b/matrix.go
@@ -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() {
diff --git a/ui.go b/ui.go
index 7ead0c4..96b4e41 100644
--- a/ui.go
+++ b/ui.go
@@ -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
}
diff --git a/view-login.go b/view-login.go
index 9b46102..0c18fbc 100644
--- a/view-login.go
+++ b/view-login.go
@@ -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))
}
diff --git a/view-main.go b/view-main.go
index b7a0b27..21e209f 100644
--- a/view-main.go
+++ b/view-main.go
@@ -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) {