Minor changes and switch to tview fork
This commit is contained in:
parent
e50a36cb47
commit
08f5db1a74
8
debug.go
8
debug.go
@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"maunium.net/go/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DebugPaneHeight = 40
|
const DebugPaneHeight = 40
|
||||||
@ -54,17 +54,17 @@ func NewDebugPane(gmx Gomuks) *DebugPane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *DebugPane) Printf(text string, args ...interface{}) {
|
func (db *DebugPane) Printf(text string, args ...interface{}) {
|
||||||
db.Write(fmt.Sprintf(text, args...))
|
db.Write(fmt.Sprintf(text, args...) + "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DebugPane) Print(text ...interface{}) {
|
func (db *DebugPane) Print(text ...interface{}) {
|
||||||
db.Write(fmt.Sprint(text...))
|
db.Write(fmt.Sprintln(text...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DebugPane) Write(text string) {
|
func (db *DebugPane) Write(text string) {
|
||||||
if db.pane != nil {
|
if db.pane != nil {
|
||||||
db.num++
|
db.num++
|
||||||
fmt.Fprintf(db.pane, "[%d] %s\n", db.num, text)
|
fmt.Fprintf(db.pane, "[%d] %s", db.num, text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/rivo/tview"
|
"maunium.net/go/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Gomuks interface {
|
type Gomuks interface {
|
||||||
|
2
ui.go
2
ui.go
@ -17,7 +17,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rivo/tview"
|
"maunium.net/go/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Allowed views in GomuksUI
|
// Allowed views in GomuksUI
|
||||||
|
@ -18,7 +18,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"maunium.net/go/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Center(width, height int, p tview.Primitive) tview.Primitive {
|
func Center(width, height int, p tview.Primitive) tview.Primitive {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/rivo/tview"
|
"maunium.net/go/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ui *GomuksUI) MakeLoginUI() tview.Primitive {
|
func (ui *GomuksUI) MakeLoginUI() tview.Primitive {
|
||||||
@ -26,6 +26,11 @@ func (ui *GomuksUI) MakeLoginUI() tview.Primitive {
|
|||||||
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.
|
form.
|
||||||
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).
|
||||||
|
33
view-main.go
33
view-main.go
@ -21,30 +21,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"maunium.net/go/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RoomView struct {
|
type RoomView struct {
|
||||||
*tview.Grid
|
*tview.TextView
|
||||||
|
|
||||||
sender, message *tview.TextView
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRoomView() *RoomView {
|
func NewRoomView() *RoomView {
|
||||||
view := &RoomView{
|
view := &RoomView{
|
||||||
tview.NewGrid(),
|
|
||||||
tview.NewTextView(),
|
|
||||||
tview.NewTextView(),
|
tview.NewTextView(),
|
||||||
}
|
}
|
||||||
view.SetColumns(30, 0).SetRows(0)
|
|
||||||
|
|
||||||
view.sender.SetTextAlign(tview.AlignRight)
|
|
||||||
view.sender.SetScrollable(true)
|
|
||||||
view.message.SetScrollable(true)
|
|
||||||
|
|
||||||
view.AddItem(view.sender, 0, 0, 1, 1, 1, 1, false)
|
|
||||||
view.AddItem(view.message, 0, 1, 1, 1, 1, 1, false)
|
|
||||||
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,11 +40,11 @@ func (ui *GomuksUI) MakeMainUI() tview.Primitive {
|
|||||||
|
|
||||||
ui.mainViewRoomList = tview.NewList().ShowSecondaryText(false)
|
ui.mainViewRoomList = tview.NewList().ShowSecondaryText(false)
|
||||||
ui.mainViewRoomList.SetBorderPadding(1, 1, 1, 1)
|
ui.mainViewRoomList.SetBorderPadding(1, 1, 1, 1)
|
||||||
ui.mainView.AddItem(ui.mainViewRoomList, 0, 0, 2, 1, 2, 1, false)
|
ui.mainView.AddItem(ui.mainViewRoomList, 0, 0, 2, 1, 2, 2, false)
|
||||||
|
|
||||||
ui.mainViewRoomView = tview.NewPages()
|
ui.mainViewRoomView = tview.NewPages()
|
||||||
ui.mainViewRoomView.SetChangedFunc(ui.Render)
|
ui.mainViewRoomView.SetChangedFunc(ui.Render)
|
||||||
ui.mainView.AddItem(ui.mainViewRoomView, 0, 1, 1, 1, 1, 1, false)
|
ui.mainView.AddItem(ui.mainViewRoomView, 0, 1, 1, 1, 2, 2, false)
|
||||||
|
|
||||||
ui.mainViewInput = tview.NewInputField()
|
ui.mainViewInput = tview.NewInputField()
|
||||||
ui.mainViewInput.SetDoneFunc(func(key tcell.Key) {
|
ui.mainViewInput.SetDoneFunc(func(key tcell.Key) {
|
||||||
@ -76,7 +63,7 @@ func (ui *GomuksUI) MakeMainUI() tview.Primitive {
|
|||||||
ui.mainViewInput.SetText("")
|
ui.mainViewInput.SetText("")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ui.mainView.AddItem(ui.mainViewInput, 1, 1, 1, 1, 1, 1, true)
|
ui.mainView.AddItem(ui.mainViewInput, 1, 1, 1, 1, 2, 2, true)
|
||||||
|
|
||||||
ui.debug.Print(ui.mainViewInput.SetInputCapture(ui.MainUIKeyHandler))
|
ui.debug.Print(ui.mainViewInput.SetInputCapture(ui.MainUIKeyHandler))
|
||||||
|
|
||||||
@ -104,7 +91,7 @@ func (ui *GomuksUI) HandleCommand(room, command string, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ui *GomuksUI) MainUIKeyHandler(key *tcell.EventKey) *tcell.EventKey {
|
func (ui *GomuksUI) MainUIKeyHandler(key *tcell.EventKey) *tcell.EventKey {
|
||||||
ui.debug.Print(key)
|
ui.debug.Print("Main UI keypress:", key.Key(), key.Modifiers())
|
||||||
if key.Modifiers() == tcell.ModCtrl {
|
if key.Modifiers() == tcell.ModCtrl {
|
||||||
if key.Key() == tcell.KeyDown {
|
if key.Key() == tcell.KeyDown {
|
||||||
ui.SwitchRoom(ui.currentRoomIndex + 1)
|
ui.SwitchRoom(ui.currentRoomIndex + 1)
|
||||||
@ -112,10 +99,11 @@ func (ui *GomuksUI) MainUIKeyHandler(key *tcell.EventKey) *tcell.EventKey {
|
|||||||
} else if key.Key() == tcell.KeyUp {
|
} else if key.Key() == tcell.KeyUp {
|
||||||
ui.SwitchRoom(ui.currentRoomIndex - 1)
|
ui.SwitchRoom(ui.currentRoomIndex - 1)
|
||||||
ui.mainViewRoomList.SetCurrentItem(ui.currentRoomIndex)
|
ui.mainViewRoomList.SetCurrentItem(ui.currentRoomIndex)
|
||||||
|
} else {
|
||||||
|
return key
|
||||||
}
|
}
|
||||||
} else if key.Key() == tcell.KeyPgUp || key.Key() == tcell.KeyPgDn {
|
} else if key.Key() == tcell.KeyPgUp || key.Key() == tcell.KeyPgDn {
|
||||||
ui.mainViewRooms[ui.currentRoom()].sender.InputHandler()(key, nil)
|
ui.mainViewRooms[ui.currentRoom()].InputHandler()(key, nil)
|
||||||
ui.mainViewRooms[ui.currentRoom()].message.InputHandler()(key, nil)
|
|
||||||
} else {
|
} else {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
@ -157,8 +145,7 @@ func (ui *GomuksUI) SwitchRoom(roomIndex int) {
|
|||||||
func (ui *GomuksUI) Append(room, sender, message string) {
|
func (ui *GomuksUI) Append(room, sender, message string) {
|
||||||
roomView, ok := ui.mainViewRooms[room]
|
roomView, ok := ui.mainViewRooms[room]
|
||||||
if ok {
|
if ok {
|
||||||
fmt.Fprintf(roomView.sender, sender)
|
fmt.Fprintf(roomView, "<%s> %s\n", sender, message)
|
||||||
fmt.Fprintf(roomView.message, sender)
|
|
||||||
ui.Render()
|
ui.Render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user