HAAAAAAAAANDS
This commit is contained in:
parent
2bf057d27c
commit
f99cede432
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -103,9 +103,11 @@ func (c *MatrixContainer) Login(user, password string) error {
|
||||
}
|
||||
|
||||
func (c *MatrixContainer) Stop() {
|
||||
if c.running {
|
||||
c.stop <- true
|
||||
c.client.StopSync()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *MatrixContainer) UpdateRoomList() {
|
||||
rooms, err := c.client.JoinedRooms()
|
||||
|
8
ui.go
8
ui.go
@ -36,11 +36,12 @@ type GomuksUI struct {
|
||||
views *tview.Pages
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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.Print("Connect result:", ui.matrix.InitClient())
|
||||
ui.debug.Print("Login result:", ui.matrix.Login(mxid, password))
|
||||
}
|
||||
|
35
view-main.go
35
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user