Muting a channel now stops you from transmitting, it acts sort of like deafen.
This commit is contained in:
parent
2e337db3c5
commit
356ff5a3a8
162
barnard.go
162
barnard.go
@ -1,38 +1,138 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
|
||||||
"git.stormux.org/storm/barnard/config"
|
"git.stormux.org/storm/barnard/config"
|
||||||
"git.stormux.org/storm/barnard/gumble/gumble"
|
"git.stormux.org/storm/barnard/gumble/gumble"
|
||||||
"git.stormux.org/storm/barnard/gumble/gumbleopenal"
|
"git.stormux.org/storm/barnard/gumble/gumbleopenal"
|
||||||
"git.stormux.org/storm/barnard/uiterm"
|
"git.stormux.org/storm/barnard/uiterm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Barnard struct {
|
type TreeItem struct {
|
||||||
Config *gumble.Config
|
User *gumble.User
|
||||||
UserConfig *config.Config
|
Channel *gumble.Channel
|
||||||
Hotkeys *config.Hotkeys
|
}
|
||||||
Client *gumble.Client
|
|
||||||
|
type Barnard struct {
|
||||||
Address string
|
Config *gumble.Config
|
||||||
TLSConfig tls.Config
|
UserConfig *config.Config
|
||||||
|
Hotkeys *config.Hotkeys
|
||||||
Stream *gumbleopenal.Stream
|
Client *gumble.Client
|
||||||
Tx bool
|
|
||||||
Connected bool
|
Address string
|
||||||
|
TLSConfig tls.Config
|
||||||
Ui *uiterm.Ui
|
|
||||||
UiOutput uiterm.Textview
|
Stream *gumbleopenal.Stream
|
||||||
UiInput uiterm.Textbox
|
Tx bool
|
||||||
UiStatus uiterm.Label
|
Connected bool
|
||||||
UiTree uiterm.Tree
|
|
||||||
UiInputStatus uiterm.Label
|
Ui *uiterm.Ui
|
||||||
SelectedChannel *gumble.Channel
|
UiOutput uiterm.Textview
|
||||||
selectedUser *gumble.User
|
UiInput uiterm.Textbox
|
||||||
|
UiStatus uiterm.Label
|
||||||
notifyChannel chan []string
|
UiTree uiterm.Tree
|
||||||
|
UiInputStatus uiterm.Label
|
||||||
exitStatus int
|
SelectedChannel *gumble.Channel
|
||||||
exitMessage string
|
selectedUser *gumble.User
|
||||||
|
|
||||||
|
notifyChannel chan []string
|
||||||
|
|
||||||
|
exitStatus int
|
||||||
|
exitMessage string
|
||||||
|
|
||||||
|
// Added for channel muting
|
||||||
|
MutedChannels map[uint32]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Barnard) StopTransmission() {
|
||||||
|
if b.Tx {
|
||||||
|
b.Notify("micdown", "me", "")
|
||||||
|
b.Tx = false
|
||||||
|
b.UpdateGeneralStatus(" Idle ", false)
|
||||||
|
b.Stream.StopSource()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Barnard) TreeItemCharacter(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm.TreeItem, ch rune) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm.TreeItem, key uiterm.Key) {
|
||||||
|
treeItem := item.(TreeItem)
|
||||||
|
if key == uiterm.KeyEnter {
|
||||||
|
if treeItem.Channel != nil {
|
||||||
|
b.Client.Self.Move(treeItem.Channel)
|
||||||
|
b.SetSelectedUser(nil)
|
||||||
|
b.GotoChat()
|
||||||
|
}
|
||||||
|
if treeItem.User != nil {
|
||||||
|
if b.selectedUser == treeItem.User {
|
||||||
|
b.SetSelectedUser(nil)
|
||||||
|
b.GotoChat()
|
||||||
|
} else {
|
||||||
|
b.SetSelectedUser(treeItem.User)
|
||||||
|
b.GotoChat()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle mute toggle
|
||||||
|
if treeItem.Channel != nil {
|
||||||
|
if key == *b.Hotkeys.MuteToggle {
|
||||||
|
// Toggle mute for all users in channel
|
||||||
|
users := makeUsersArray(treeItem.Channel.Users)
|
||||||
|
for _, u := range users {
|
||||||
|
b.UserConfig.ToggleMute(u)
|
||||||
|
if u.AudioSource != nil {
|
||||||
|
if u.LocallyMuted {
|
||||||
|
u.AudioSource.SetGain(0)
|
||||||
|
} else {
|
||||||
|
u.AudioSource.SetGain(u.Volume)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle channel mute state
|
||||||
|
if b.MutedChannels[treeItem.Channel.ID] {
|
||||||
|
delete(b.MutedChannels, treeItem.Channel.ID)
|
||||||
|
} else {
|
||||||
|
b.MutedChannels[treeItem.Channel.ID] = true
|
||||||
|
// If this is the current channel, stop transmission
|
||||||
|
if b.Client.Self.Channel.ID == treeItem.Channel.ID && b.Tx {
|
||||||
|
b.StopTransmission()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.UiTree.Rebuild()
|
||||||
|
b.Ui.Refresh()
|
||||||
|
}
|
||||||
|
if key == *b.Hotkeys.VolumeDown {
|
||||||
|
b.changeVolume(makeUsersArray(treeItem.Channel.Users), -0.1)
|
||||||
|
}
|
||||||
|
if key == *b.Hotkeys.VolumeUp {
|
||||||
|
b.changeVolume(makeUsersArray(treeItem.Channel.Users), 0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if treeItem.User != nil {
|
||||||
|
if key == *b.Hotkeys.MuteToggle {
|
||||||
|
// Toggle mute for single user
|
||||||
|
b.UserConfig.ToggleMute(treeItem.User)
|
||||||
|
if treeItem.User.AudioSource != nil {
|
||||||
|
if treeItem.User.LocallyMuted {
|
||||||
|
treeItem.User.AudioSource.SetGain(0)
|
||||||
|
} else {
|
||||||
|
treeItem.User.AudioSource.SetGain(treeItem.User.Volume)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.UiTree.Rebuild()
|
||||||
|
b.Ui.Refresh()
|
||||||
|
}
|
||||||
|
if key == *b.Hotkeys.VolumeDown {
|
||||||
|
b.changeVolume([]*gumble.User{treeItem.User}, -0.1)
|
||||||
|
}
|
||||||
|
if key == *b.Hotkeys.VolumeUp {
|
||||||
|
b.changeVolume([]*gumble.User{treeItem.User}, 0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
1
main.go
1
main.go
@ -158,6 +158,7 @@ func main() {
|
|||||||
Config: gumble.NewConfig(),
|
Config: gumble.NewConfig(),
|
||||||
UserConfig: userConfig,
|
UserConfig: userConfig,
|
||||||
Address: *server,
|
Address: *server,
|
||||||
|
MutedChannels: make(map[uint32]bool),
|
||||||
}
|
}
|
||||||
b.Config.Buffers = *buffers
|
b.Config.Buffers = *buffers
|
||||||
|
|
||||||
|
414
ui.go
414
ui.go
@ -1,323 +1,315 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.stormux.org/storm/barnard/gumble/gumble"
|
"git.stormux.org/storm/barnard/gumble/gumble"
|
||||||
"git.stormux.org/storm/barnard/uiterm"
|
"git.stormux.org/storm/barnard/uiterm"
|
||||||
"github.com/kennygrant/sanitize"
|
"github.com/kennygrant/sanitize"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
uiViewLogo = "logo"
|
uiViewLogo = "logo"
|
||||||
uiViewTop = "top"
|
uiViewTop = "top"
|
||||||
uiViewStatus = "status"
|
uiViewStatus = "status"
|
||||||
uiViewInput = "input"
|
uiViewInput = "input"
|
||||||
uiViewInputStatus = "inputstatus"
|
uiViewInputStatus = "inputstatus"
|
||||||
uiViewOutput = "output"
|
uiViewOutput = "output"
|
||||||
uiViewTree = "tree"
|
uiViewTree = "tree"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Beep() {
|
func Beep() {
|
||||||
cmd := exec.Command("beep")
|
cmd := exec.Command("beep")
|
||||||
cmdout, err := cmd.Output()
|
cmdout, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if cmdout != nil {
|
if cmdout != nil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func esc(str string) string {
|
func esc(str string) string {
|
||||||
return sanitize.HTML(str)
|
return sanitize.HTML(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) Notify(event string, who string, what string) {
|
func (b *Barnard) Notify(event string, who string, what string) {
|
||||||
b.notifyChannel <- []string{event, who, what}
|
b.notifyChannel <- []string{event, who, what}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) Beep() {
|
func (b *Barnard) Beep() {
|
||||||
Beep()
|
Beep()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) SetSelectedUser(user *gumble.User) {
|
func (b *Barnard) SetSelectedUser(user *gumble.User) {
|
||||||
b.selectedUser = user
|
b.selectedUser = user
|
||||||
if user == nil {
|
if user == nil {
|
||||||
if len(b.UiInput.Text) > 0 {
|
if len(b.UiInput.Text) > 0 {
|
||||||
}
|
}
|
||||||
b.UpdateInputStatus(fmt.Sprintf("[%s]", b.Client.Self.Channel.Name))
|
b.UpdateInputStatus(fmt.Sprintf("[%s]", b.Client.Self.Channel.Name))
|
||||||
} else {
|
} else {
|
||||||
b.UpdateInputStatus(fmt.Sprintf("[@%s]", user.Name))
|
b.UpdateInputStatus(fmt.Sprintf("[@%s]", user.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) GetInputStatus() string {
|
func (b *Barnard) GetInputStatus() string {
|
||||||
return b.UiInputStatus.Text
|
return b.UiInputStatus.Text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) UpdateInputStatus(status string) {
|
func (b *Barnard) UpdateInputStatus(status string) {
|
||||||
if len(status) > 20 {
|
if len(status) > 20 {
|
||||||
status = status[:17] + "..." + "]"
|
status = status[:17] + "..." + "]"
|
||||||
}
|
}
|
||||||
b.UiInputStatus.Text = status
|
b.UiInputStatus.Text = status
|
||||||
b.UiTree.Rebuild()
|
b.UiTree.Rebuild()
|
||||||
b.Ui.Refresh()
|
b.Ui.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) AddOutputLine(line string) {
|
func (b *Barnard) AddOutputLine(line string) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
b.UiOutput.AddLine(fmt.Sprintf("[%02d:%02d:%02d] %s", now.Hour(), now.Minute(), now.Second(), line))
|
b.UiOutput.AddLine(fmt.Sprintf("[%02d:%02d:%02d] %s", now.Hour(), now.Minute(), now.Second(), line))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) AddOutputMessage(sender *gumble.User, message string) {
|
func (b *Barnard) AddOutputMessage(sender *gumble.User, message string) {
|
||||||
if sender == nil {
|
if sender == nil {
|
||||||
b.AddOutputLine(message)
|
b.AddOutputLine(message)
|
||||||
} else {
|
} else {
|
||||||
b.AddOutputLine(fmt.Sprintf("%s: %s", sender.Name, strings.TrimSpace(esc(message))))
|
b.AddOutputLine(fmt.Sprintf("%s: %s", sender.Name, strings.TrimSpace(esc(message))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) AddOutputPrivateMessage(source *gumble.User, dest *gumble.User, message string) {
|
func (b *Barnard) AddOutputPrivateMessage(source *gumble.User, dest *gumble.User, message string) {
|
||||||
var sender string
|
var sender string
|
||||||
if source == nil {
|
if source == nil {
|
||||||
sender = "Server"
|
sender = "Server"
|
||||||
} else {
|
} else {
|
||||||
sender = source.Name
|
sender = source.Name
|
||||||
}
|
}
|
||||||
b.AddOutputLine(fmt.Sprintf("pm/%s/%s: %s", sender, dest.Name, strings.TrimSpace(esc(message))))
|
b.AddOutputLine(fmt.Sprintf("pm/%s/%s: %s", sender, dest.Name, strings.TrimSpace(esc(message))))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnTimestampToggle(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnTimestampToggle(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.UiOutput.ToggleTimestamps()
|
b.UiOutput.ToggleTimestamps()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) UpdateGeneralStatus(text string, notice bool) {
|
func (b *Barnard) UpdateGeneralStatus(text string, notice bool) {
|
||||||
// if (b.UiStatus.Text == text) {
|
if notice {
|
||||||
//return
|
b.UiStatus.Fg = uiterm.ColorWhite | uiterm.AttrBold
|
||||||
//}
|
b.UiStatus.Bg = uiterm.ColorRed
|
||||||
if notice {
|
} else {
|
||||||
b.UiStatus.Fg = uiterm.ColorWhite | uiterm.AttrBold
|
b.UiStatus.Fg = uiterm.ColorBlack
|
||||||
b.UiStatus.Bg = uiterm.ColorRed
|
b.UiStatus.Bg = uiterm.ColorWhite
|
||||||
} else {
|
}
|
||||||
b.UiStatus.Fg = uiterm.ColorBlack
|
b.UiStatus.Text = text
|
||||||
b.UiStatus.Bg = uiterm.ColorWhite
|
b.Ui.Refresh()
|
||||||
}
|
|
||||||
b.UiStatus.Text = text
|
|
||||||
b.Ui.Refresh()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnVoiceToggle(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnVoiceToggle(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.setTransmit(ui, 2)
|
b.setTransmit(ui, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) CommandLog(ui *uiterm.Ui, cmd string) {
|
func (b *Barnard) CommandLog(ui *uiterm.Ui, cmd string) {
|
||||||
b.AddOutputLine("command " + cmd)
|
b.AddOutputLine("command " + cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) CommandTalk(ui *uiterm.Ui, cmd string) {
|
func (b *Barnard) CommandTalk(ui *uiterm.Ui, cmd string) {
|
||||||
b.setTransmit(ui, 2)
|
b.setTransmit(ui, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) CommandMicUp(ui *uiterm.Ui, cmd string) {
|
func (b *Barnard) CommandMicUp(ui *uiterm.Ui, cmd string) {
|
||||||
b.setTransmit(ui, 1)
|
b.setTransmit(ui, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) CommandMicDown(ui *uiterm.Ui, cmd string) {
|
func (b *Barnard) CommandMicDown(ui *uiterm.Ui, cmd string) {
|
||||||
b.setTransmit(ui, 0)
|
b.setTransmit(ui, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) {
|
func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) {
|
||||||
if b.Tx && val == 1 {
|
if b.Tx && val == 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if b.Tx == false && val == 0 {
|
if b.Tx == false && val == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if b.Tx {
|
if b.Tx {
|
||||||
b.Notify("micdown", "me", "")
|
b.Notify("micdown", "me", "")
|
||||||
b.Tx = false
|
b.Tx = false
|
||||||
b.UpdateGeneralStatus(" Idle ", false)
|
b.UpdateGeneralStatus(" Idle ", false)
|
||||||
b.Stream.StopSource()
|
b.Stream.StopSource()
|
||||||
} else if b.Connected == false {
|
} else if b.Connected == false {
|
||||||
b.Notify("error", "me", "no tx while disconnected")
|
b.Notify("error", "me", "no tx while disconnected")
|
||||||
b.Tx = false
|
b.Tx = false
|
||||||
b.UpdateGeneralStatus("no tx while disconnected", true)
|
b.UpdateGeneralStatus("no tx while disconnected", true)
|
||||||
} else {
|
} else if b.MutedChannels[b.Client.Self.Channel.ID] {
|
||||||
b.Tx = true
|
// Check if current channel is muted
|
||||||
err := b.Stream.StartSource(b.UserConfig.GetInputDevice())
|
b.Notify("error", "me", "cannot transmit in muted channel")
|
||||||
if err != nil {
|
b.Tx = false
|
||||||
b.Notify("error", "me", err.Error())
|
b.UpdateGeneralStatus("cannot transmit in muted channel", true)
|
||||||
b.UpdateGeneralStatus(err.Error(), true)
|
} else {
|
||||||
} else {
|
b.Tx = true
|
||||||
b.Notify("micup", "me", "")
|
err := b.Stream.StartSource(b.UserConfig.GetInputDevice())
|
||||||
b.UpdateGeneralStatus(" Tx ", true)
|
if err != nil {
|
||||||
} //if error transmit
|
b.Notify("error", "me", err.Error())
|
||||||
} //not transmitting
|
b.UpdateGeneralStatus(err.Error(), true)
|
||||||
} //func
|
} else {
|
||||||
|
b.Notify("micup", "me", "")
|
||||||
|
b.UpdateGeneralStatus(" Tx ", true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnMicVolumeDown(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnMicVolumeDown(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.Stream.SetMicVolume(-0.1, true)
|
b.Stream.SetMicVolume(-0.1, true)
|
||||||
b.UserConfig.SetMicVolume(b.Stream.GetMicVolume())
|
b.UserConfig.SetMicVolume(b.Stream.GetMicVolume())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnMicVolumeUp(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnMicVolumeUp(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.Stream.SetMicVolume(0.1, true)
|
b.Stream.SetMicVolume(0.1, true)
|
||||||
b.UserConfig.SetMicVolume(b.Stream.GetMicVolume())
|
b.UserConfig.SetMicVolume(b.Stream.GetMicVolume())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnQuitPress(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnQuitPress(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.Client.Disconnect()
|
b.Client.Disconnect()
|
||||||
b.Ui.Close()
|
b.Ui.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) CommandExit(ui *uiterm.Ui, cmd string) {
|
func (b *Barnard) CommandExit(ui *uiterm.Ui, cmd string) {
|
||||||
b.Client.Disconnect()
|
b.Client.Disconnect()
|
||||||
b.Ui.Close()
|
b.Ui.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnClearPress(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnClearPress(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.UiOutput.Clear()
|
b.UiOutput.Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnScrollOutputUp(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnScrollOutputUp(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.UiOutput.ScrollUp()
|
b.UiOutput.ScrollUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnScrollOutputDown(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnScrollOutputDown(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.UiOutput.ScrollDown()
|
b.UiOutput.ScrollDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnScrollOutputTop(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnScrollOutputTop(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.UiOutput.ScrollTop()
|
b.UiOutput.ScrollTop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnScrollOutputBottom(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnScrollOutputBottom(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
b.UiOutput.ScrollBottom()
|
b.UiOutput.ScrollBottom()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnFocusPress(ui *uiterm.Ui, key uiterm.Key) {
|
func (b *Barnard) OnFocusPress(ui *uiterm.Ui, key uiterm.Key) {
|
||||||
active := b.Ui.Active()
|
active := b.Ui.Active()
|
||||||
if active == uiViewInput {
|
if active == uiViewInput {
|
||||||
b.Ui.SetActive(uiViewTree)
|
b.Ui.SetActive(uiViewTree)
|
||||||
} else if active == uiViewTree {
|
} else if active == uiViewTree {
|
||||||
b.Ui.SetActive(uiViewInput)
|
b.Ui.SetActive(uiViewInput)
|
||||||
}
|
}
|
||||||
width, height := termbox.Size()
|
width, height := termbox.Size()
|
||||||
b.OnUiResize(ui, width, height)
|
b.OnUiResize(ui, width, height)
|
||||||
ui.Refresh()
|
ui.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnTextInput(ui *uiterm.Ui, textbox *uiterm.Textbox, text string) {
|
func (b *Barnard) OnTextInput(ui *uiterm.Ui, textbox *uiterm.Textbox, text string) {
|
||||||
if text == "" {
|
if text == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if b.Client != nil && b.Client.Self != nil {
|
if b.Client != nil && b.Client.Self != nil {
|
||||||
if b.selectedUser != nil {
|
if b.selectedUser != nil {
|
||||||
b.selectedUser.Send(text)
|
b.selectedUser.Send(text)
|
||||||
b.AddOutputPrivateMessage(b.Client.Self, b.selectedUser, text)
|
b.AddOutputPrivateMessage(b.Client.Self, b.selectedUser, text)
|
||||||
} else {
|
} else {
|
||||||
b.Client.Self.Channel.Send(text, false)
|
b.Client.Self.Channel.Send(text, false)
|
||||||
b.AddOutputMessage(b.Client.Self, text)
|
b.AddOutputMessage(b.Client.Self, text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) GotoChat() {
|
func (b *Barnard) GotoChat() {
|
||||||
b.OnFocusPress(b.Ui, uiterm.KeyTab)
|
b.OnFocusPress(b.Ui, uiterm.KeyTab)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnUiDoneInitialize(ui *uiterm.Ui) {
|
func (b *Barnard) OnUiDoneInitialize(ui *uiterm.Ui) {
|
||||||
b.start()
|
b.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) {
|
func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) {
|
||||||
ui.Add(uiViewLogo, &uiterm.Label{
|
ui.Add(uiViewLogo, &uiterm.Label{
|
||||||
Text: "Barnard ",
|
Text: "Barnard ",
|
||||||
Fg: uiterm.ColorWhite | uiterm.AttrBold,
|
Fg: uiterm.ColorWhite | uiterm.AttrBold,
|
||||||
Bg: uiterm.ColorMagenta,
|
Bg: uiterm.ColorMagenta,
|
||||||
})
|
})
|
||||||
|
|
||||||
// ui.Add(uiViewTop, &uiterm.Label{
|
b.UiStatus = uiterm.Label{
|
||||||
// Fg: uiterm.ColorWhite,
|
Text: " Idle ",
|
||||||
// Bg: uiterm.ColorBlue,
|
Fg: uiterm.ColorBlack,
|
||||||
// })
|
Bg: uiterm.ColorWhite,
|
||||||
|
}
|
||||||
|
ui.Add(uiViewStatus, &b.UiStatus)
|
||||||
|
|
||||||
b.UiStatus = uiterm.Label{
|
b.UiInput = uiterm.Textbox{
|
||||||
Text: " Idle ",
|
Fg: uiterm.ColorWhite,
|
||||||
Fg: uiterm.ColorBlack,
|
Bg: uiterm.ColorBlack,
|
||||||
Bg: uiterm.ColorWhite,
|
Input: b.OnTextInput,
|
||||||
}
|
}
|
||||||
ui.Add(uiViewStatus, &b.UiStatus)
|
ui.Add(uiViewInput, &b.UiInput)
|
||||||
|
|
||||||
b.UiInput = uiterm.Textbox{
|
b.UiInputStatus = uiterm.Label{
|
||||||
Fg: uiterm.ColorWhite,
|
Fg: uiterm.ColorBlack,
|
||||||
Bg: uiterm.ColorBlack,
|
Bg: uiterm.ColorWhite,
|
||||||
Input: b.OnTextInput,
|
}
|
||||||
}
|
ui.Add(uiViewInputStatus, &b.UiInputStatus)
|
||||||
ui.Add(uiViewInput, &b.UiInput)
|
|
||||||
|
|
||||||
b.UiInputStatus = uiterm.Label{
|
b.UiOutput = uiterm.Textview{
|
||||||
Fg: uiterm.ColorBlack,
|
Fg: uiterm.ColorWhite,
|
||||||
Bg: uiterm.ColorWhite,
|
Bg: uiterm.ColorBlack,
|
||||||
}
|
}
|
||||||
ui.Add(uiViewInputStatus, &b.UiInputStatus)
|
ui.Add(uiViewOutput, &b.UiOutput)
|
||||||
|
|
||||||
b.UiOutput = uiterm.Textview{
|
b.UiTree = uiterm.Tree{
|
||||||
Fg: uiterm.ColorWhite,
|
Generator: b.TreeItemBuild,
|
||||||
Bg: uiterm.ColorBlack,
|
KeyListener: b.TreeItemKeyPress,
|
||||||
}
|
CharacterListener: b.TreeItemCharacter,
|
||||||
ui.Add(uiViewOutput, &b.UiOutput)
|
Fg: uiterm.ColorWhite,
|
||||||
|
Bg: uiterm.ColorBlack,
|
||||||
|
}
|
||||||
|
ui.Add(uiViewTree, &b.UiTree)
|
||||||
|
|
||||||
b.UiTree = uiterm.Tree{
|
b.Ui.AddCommandListener(b.CommandMicUp, "micup")
|
||||||
Generator: b.TreeItemBuild,
|
b.Ui.AddCommandListener(b.CommandMicDown, "micdown")
|
||||||
KeyListener: b.TreeItemKeyPress,
|
b.Ui.AddCommandListener(b.CommandTalk, "toggle")
|
||||||
CharacterListener: b.TreeItemCharacter,
|
b.Ui.AddCommandListener(b.CommandTalk, "talk")
|
||||||
Fg: uiterm.ColorWhite,
|
b.Ui.AddCommandListener(b.CommandExit, "exit")
|
||||||
Bg: uiterm.ColorBlack,
|
b.Ui.AddKeyListener(b.OnFocusPress, b.Hotkeys.SwitchViews)
|
||||||
}
|
b.Ui.AddKeyListener(b.OnVoiceToggle, b.Hotkeys.Talk)
|
||||||
ui.Add(uiViewTree, &b.UiTree)
|
b.Ui.AddKeyListener(b.OnTimestampToggle, b.Hotkeys.ToggleTimestamps)
|
||||||
|
b.Ui.AddKeyListener(b.OnQuitPress, b.Hotkeys.Exit)
|
||||||
//add this to see what your commands are coming in as raw strings
|
b.Ui.AddKeyListener(b.OnScrollOutputUp, b.Hotkeys.ScrollUp)
|
||||||
// b.Ui.AddCommandListener(b.CommandLog, "*")
|
b.Ui.AddKeyListener(b.OnScrollOutputDown, b.Hotkeys.ScrollDown)
|
||||||
b.Ui.AddCommandListener(b.CommandMicUp, "micup")
|
b.Ui.AddKeyListener(b.OnScrollOutputTop, b.Hotkeys.ScrollToTop)
|
||||||
b.Ui.AddCommandListener(b.CommandMicDown, "micdown")
|
b.Ui.AddKeyListener(b.OnScrollOutputBottom, b.Hotkeys.ScrollToBottom)
|
||||||
b.Ui.AddCommandListener(b.CommandTalk, "toggle")
|
b.Ui.SetActive(uiViewInput)
|
||||||
b.Ui.AddCommandListener(b.CommandTalk, "talk")
|
b.UiTree.Rebuild()
|
||||||
b.Ui.AddCommandListener(b.CommandExit, "exit")
|
b.Ui.Refresh()
|
||||||
b.Ui.AddKeyListener(b.OnFocusPress, b.Hotkeys.SwitchViews)
|
|
||||||
b.Ui.AddKeyListener(b.OnVoiceToggle, b.Hotkeys.Talk)
|
|
||||||
b.Ui.AddKeyListener(b.OnTimestampToggle, b.Hotkeys.ToggleTimestamps)
|
|
||||||
b.Ui.AddKeyListener(b.OnQuitPress, b.Hotkeys.Exit)
|
|
||||||
b.Ui.AddKeyListener(b.OnScrollOutputUp, b.Hotkeys.ScrollUp)
|
|
||||||
b.Ui.AddKeyListener(b.OnScrollOutputDown, b.Hotkeys.ScrollDown)
|
|
||||||
b.Ui.AddKeyListener(b.OnScrollOutputTop, b.Hotkeys.ScrollToTop)
|
|
||||||
b.Ui.AddKeyListener(b.OnScrollOutputBottom, b.Hotkeys.ScrollToBottom)
|
|
||||||
b.Ui.SetActive(uiViewInput)
|
|
||||||
b.UiTree.Rebuild()
|
|
||||||
b.Ui.Refresh()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) OnUiResize(ui *uiterm.Ui, width, height int) {
|
func (b *Barnard) OnUiResize(ui *uiterm.Ui, width, height int) {
|
||||||
treeHeight := 0
|
treeHeight := 0
|
||||||
outputHeight := 0
|
outputHeight := 0
|
||||||
active := b.Ui.Active()
|
active := b.Ui.Active()
|
||||||
if active == uiViewTree {
|
if active == uiViewTree {
|
||||||
treeHeight = height - 4
|
treeHeight = height - 4
|
||||||
outputHeight = 0
|
outputHeight = 0
|
||||||
} else {
|
} else {
|
||||||
treeHeight = 0
|
treeHeight = 0
|
||||||
outputHeight = height - 4
|
outputHeight = height - 4
|
||||||
}
|
}
|
||||||
// ui.SetBounds(uiViewLogo, 0, 0, 9, 1)
|
ui.SetBounds(uiViewOutput, 0, 1, width, outputHeight+1)
|
||||||
ui.SetBounds(uiViewOutput, 0, 1, width, outputHeight+1)
|
ui.SetBounds(uiViewTree, 0, 1, width, treeHeight+1)
|
||||||
ui.SetBounds(uiViewTree, 0, 1, width, treeHeight+1)
|
ui.SetBounds(uiViewStatus, 0, height-2, width, height-1)
|
||||||
ui.SetBounds(uiViewStatus, 0, height-2, width, height-1)
|
ui.SetBounds(uiViewInputStatus, 0, height-1, len(b.GetInputStatus()), height)
|
||||||
ui.SetBounds(uiViewInputStatus, 0, height-1, len(b.GetInputStatus()), height)
|
ui.SetBounds(uiViewInput, len(b.GetInputStatus())+1, height-1, width, height)
|
||||||
//setting this to inputStatus+1 will leave one space between inputStatus and input box
|
|
||||||
//x starts at 0, so 10 chars of text will go from 0 to 9, there'll be a space at char 10, and we'll start at (10+1)=11
|
|
||||||
ui.SetBounds(uiViewInput, len(b.GetInputStatus())+1, height-1, width, height)
|
|
||||||
}
|
}
|
||||||
|
82
ui_tree.go
82
ui_tree.go
@ -6,11 +6,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TreeItem struct {
|
|
||||||
User *gumble.User
|
|
||||||
Channel *gumble.Channel
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ti TreeItem) String() string {
|
func (ti TreeItem) String() string {
|
||||||
if ti.User != nil {
|
if ti.User != nil {
|
||||||
if ti.User.LocallyMuted {
|
if ti.User.LocallyMuted {
|
||||||
@ -34,9 +29,6 @@ func (ti TreeItem) TreeItemStyle(fg, bg uiterm.Attribute, active bool) (uiterm.A
|
|||||||
return fg, bg
|
return fg, bg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) TreeItemCharacter(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm.TreeItem, ch rune) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Barnard) changeVolume(users []*gumble.User, change float32) {
|
func (b *Barnard) changeVolume(users []*gumble.User, change float32) {
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
au := u.AudioSource
|
au := u.AudioSource
|
||||||
@ -78,74 +70,6 @@ func makeUsersArray(users gumble.Users) []*gumble.User {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm.TreeItem, key uiterm.Key) {
|
|
||||||
treeItem := item.(TreeItem)
|
|
||||||
if key == uiterm.KeyEnter {
|
|
||||||
if treeItem.Channel != nil {
|
|
||||||
b.Client.Self.Move(treeItem.Channel)
|
|
||||||
b.SetSelectedUser(nil)
|
|
||||||
b.GotoChat()
|
|
||||||
}
|
|
||||||
if treeItem.User != nil {
|
|
||||||
if b.selectedUser == treeItem.User {
|
|
||||||
b.SetSelectedUser(nil)
|
|
||||||
b.GotoChat()
|
|
||||||
} else {
|
|
||||||
b.SetSelectedUser(treeItem.User)
|
|
||||||
b.GotoChat()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle mute toggle
|
|
||||||
if treeItem.Channel != nil {
|
|
||||||
if key == *b.Hotkeys.MuteToggle {
|
|
||||||
// Toggle mute for all users in channel
|
|
||||||
users := makeUsersArray(treeItem.Channel.Users)
|
|
||||||
for _, u := range users {
|
|
||||||
b.UserConfig.ToggleMute(u)
|
|
||||||
if u.AudioSource != nil {
|
|
||||||
if u.LocallyMuted {
|
|
||||||
u.AudioSource.SetGain(0)
|
|
||||||
} else {
|
|
||||||
u.AudioSource.SetGain(u.Volume)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.UiTree.Rebuild()
|
|
||||||
b.Ui.Refresh()
|
|
||||||
}
|
|
||||||
if key == *b.Hotkeys.VolumeDown {
|
|
||||||
b.changeVolume(makeUsersArray(treeItem.Channel.Users), -0.1)
|
|
||||||
}
|
|
||||||
if key == *b.Hotkeys.VolumeUp {
|
|
||||||
b.changeVolume(makeUsersArray(treeItem.Channel.Users), 0.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if treeItem.User != nil {
|
|
||||||
if key == *b.Hotkeys.MuteToggle {
|
|
||||||
// Toggle mute for single user
|
|
||||||
b.UserConfig.ToggleMute(treeItem.User)
|
|
||||||
if treeItem.User.AudioSource != nil {
|
|
||||||
if treeItem.User.LocallyMuted {
|
|
||||||
treeItem.User.AudioSource.SetGain(0)
|
|
||||||
} else {
|
|
||||||
treeItem.User.AudioSource.SetGain(treeItem.User.Volume)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
b.UiTree.Rebuild()
|
|
||||||
b.Ui.Refresh()
|
|
||||||
}
|
|
||||||
if key == *b.Hotkeys.VolumeDown {
|
|
||||||
b.changeVolume([]*gumble.User{treeItem.User}, -0.1)
|
|
||||||
}
|
|
||||||
if key == *b.Hotkeys.VolumeUp {
|
|
||||||
b.changeVolume([]*gumble.User{treeItem.User}, 0.1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Barnard) TreeItemBuild(item uiterm.TreeItem) []uiterm.TreeItem {
|
func (b *Barnard) TreeItemBuild(item uiterm.TreeItem) []uiterm.TreeItem {
|
||||||
if b.Client == nil {
|
if b.Client == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -195,6 +119,12 @@ func (b *Barnard) TreeItemBuild(item uiterm.TreeItem) []uiterm.TreeItem {
|
|||||||
return cl[i].Name < cl[j].Name
|
return cl[i].Name < cl[j].Name
|
||||||
})
|
})
|
||||||
for _, subchannel := range cl {
|
for _, subchannel := range cl {
|
||||||
|
displayName := subchannel.Name
|
||||||
|
if b.MutedChannels[subchannel.ID] {
|
||||||
|
displayName = "[MUTED] #" + displayName
|
||||||
|
} else {
|
||||||
|
displayName = "#" + displayName
|
||||||
|
}
|
||||||
channels = append(channels, TreeItem{
|
channels = append(channels, TreeItem{
|
||||||
Channel: subchannel,
|
Channel: subchannel,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user