mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
Add keybindings to roster view
This commit is contained in:
parent
167b4a497b
commit
a5ac5ec86e
4 changed files with 57 additions and 13 deletions
|
@ -90,6 +90,7 @@ type Keybind struct {
|
|||
|
||||
type ParsedKeybindings struct {
|
||||
Main map[Keybind]string
|
||||
Roster map[Keybind]string
|
||||
Room map[Keybind]string
|
||||
Modal map[Keybind]string
|
||||
Visual map[Keybind]string
|
||||
|
@ -97,6 +98,7 @@ type ParsedKeybindings struct {
|
|||
|
||||
type RawKeybindings struct {
|
||||
Main map[string]string `yaml:"main,omitempty"`
|
||||
Roster map[string]string `yaml:"roster,omitempty"`
|
||||
Room map[string]string `yaml:"room,omitempty"`
|
||||
Modal map[string]string `yaml:"modal,omitempty"`
|
||||
Visual map[string]string `yaml:"visual,omitempty"`
|
||||
|
@ -277,6 +279,7 @@ func (config *Config) LoadKeybindings() {
|
|||
_ = config.load("keybindings", config.Dir, "keybindings.yaml", &inputConfig)
|
||||
|
||||
config.Keybindings.Main = parseKeybindings(inputConfig.Main)
|
||||
config.Keybindings.Roster = parseKeybindings(inputConfig.Roster)
|
||||
config.Keybindings.Room = parseKeybindings(inputConfig.Room)
|
||||
config.Keybindings.Modal = parseKeybindings(inputConfig.Modal)
|
||||
config.Keybindings.Visual = parseKeybindings(inputConfig.Visual)
|
||||
|
|
|
@ -15,6 +15,13 @@ main:
|
|||
'Alt+a': next_active_room
|
||||
'Alt+l': show_bare
|
||||
|
||||
roster:
|
||||
'j': next_room
|
||||
'k': prev_room
|
||||
'Down': next_room
|
||||
'Up': prev_room
|
||||
'Escape': clear
|
||||
|
||||
modal:
|
||||
'Tab': select_next
|
||||
'Down': select_next
|
||||
|
|
|
@ -172,6 +172,8 @@ func (view *MainView) OnKeyEvent(event mauview.KeyEvent) bool {
|
|||
|
||||
if view.modal != nil {
|
||||
return view.modal.OnKeyEvent(event)
|
||||
} else if view.config.Preferences.DisplayMode == config.DisplayModeModern {
|
||||
return view.rosterView.OnKeyEvent(event)
|
||||
}
|
||||
|
||||
kb := config.Keybind{
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"go.mau.fi/mauview"
|
||||
"go.mau.fi/tcell"
|
||||
|
||||
"maunium.net/go/gomuks/config"
|
||||
"maunium.net/go/gomuks/matrix/rooms"
|
||||
"maunium.net/go/gomuks/ui/widget"
|
||||
"maunium.net/go/mautrix/event"
|
||||
|
@ -35,13 +36,6 @@ type RosterView struct {
|
|||
|
||||
height, width int
|
||||
|
||||
// The item main text color.
|
||||
mainTextColor tcell.Color
|
||||
// The text color for selected items.
|
||||
selectedTextColor tcell.Color
|
||||
// The background color for selected items.
|
||||
selectedBackgroundColor tcell.Color
|
||||
|
||||
parent *MainView
|
||||
}
|
||||
|
||||
|
@ -116,7 +110,7 @@ func (rstr *RosterView) getMostRecentMessage(room *rooms.Room) (string, bool) {
|
|||
func (rstr *RosterView) Draw(screen mauview.Screen) {
|
||||
rstr.width, rstr.height = screen.Size()
|
||||
|
||||
titleStyle := tcell.StyleDefault.Foreground(rstr.mainTextColor).Bold(true)
|
||||
titleStyle := tcell.StyleDefault.Foreground(tcell.ColorDefault).Bold(true)
|
||||
mainStyle := titleStyle.Bold(false)
|
||||
|
||||
now := time.Now()
|
||||
|
@ -145,12 +139,12 @@ func (rstr *RosterView) Draw(screen mauview.Screen) {
|
|||
isSelected := room == rstr.selected
|
||||
|
||||
style := tcell.StyleDefault.
|
||||
Foreground(rstr.mainTextColor).
|
||||
Foreground(tcell.ColorDefault).
|
||||
Bold(room.HasNewMessages())
|
||||
if isSelected {
|
||||
style = style.
|
||||
Foreground(rstr.selectedTextColor).
|
||||
Background(rstr.selectedBackgroundColor)
|
||||
Foreground(tcell.ColorBlack).
|
||||
Background(tcell.ColorWhite)
|
||||
}
|
||||
|
||||
timestamp := room.LastReceivedMessage
|
||||
|
@ -167,11 +161,14 @@ func (rstr *RosterView) Draw(screen mauview.Screen) {
|
|||
|
||||
lastMessage, received := rstr.getMostRecentMessage(room)
|
||||
msgStyle := style.Foreground(tcell.ColorGray).Italic(!received)
|
||||
if isSelected {
|
||||
msgStyle = msgStyle.Background(tcell.ColorWhite)
|
||||
}
|
||||
|
||||
tmX := rstr.width - 3 - len(tm)
|
||||
widget.WriteLine(screen, mauview.AlignLeft, room.GetTitle(), 2, y, tmX, style)
|
||||
widget.WriteLinePadded(screen, mauview.AlignLeft, room.GetTitle(), 2, y, tmX, style)
|
||||
widget.WriteLine(screen, mauview.AlignLeft, tm, tmX, y, 2+len(tm), style)
|
||||
widget.WriteLine(screen, mauview.AlignLeft, lastMessage, 2, y+1, rstr.width-5, msgStyle)
|
||||
widget.WriteLinePadded(screen, mauview.AlignLeft, lastMessage, 2, y+1, rstr.width-5, msgStyle)
|
||||
|
||||
y += renderHeight
|
||||
if y >= rstr.height {
|
||||
|
@ -179,3 +176,38 @@ func (rstr *RosterView) Draw(screen mauview.Screen) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (rstr *RosterView) OnKeyEvent(event mauview.KeyEvent) bool {
|
||||
kb := config.Keybind{
|
||||
Key: event.Key(),
|
||||
Ch: event.Rune(),
|
||||
Mod: event.Modifiers(),
|
||||
}
|
||||
switch rstr.parent.config.Keybindings.Roster[kb] {
|
||||
case "next_room":
|
||||
if index := rstr.index(rstr.selected); index == -1 || index == len(rstr.rooms)-1 {
|
||||
rstr.selected = rstr.First()
|
||||
} else {
|
||||
rstr.selected = rstr.rooms[index+1]
|
||||
}
|
||||
case "prev_room":
|
||||
if index := rstr.index(rstr.selected); index < 1 {
|
||||
rstr.selected = rstr.Last()
|
||||
} else {
|
||||
rstr.selected = rstr.rooms[index-1]
|
||||
}
|
||||
case "clear":
|
||||
rstr.selected = nil
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (rstr *RosterView) First() *rooms.Room {
|
||||
return rstr.rooms[0]
|
||||
}
|
||||
|
||||
func (rstr *RosterView) Last() *rooms.Room {
|
||||
return rstr.rooms[len(rstr.rooms)-1]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue