Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -tx and -channel command line options #51

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@ Requirements:

To fetch and build:

go get -u layeh.com/barnard
````
apt install libalut-dev libopus-dev
go install layeh.com/barnard@latest
````

After running the command above, `barnard` will be compiled as `$(go env GOPATH)/bin/barnard`.

## Development Environment Setup

````
apt install libalut-dev libopus-dev
go mod init
go get
go build
````

## Manual

### Key bindings

- <kbd>F1</kbd>: toggle voice transmission
- <kbd>F1</kbd>: show help
- <kbd>F2</kbd>: toggle voice transmission
- <kbd>Ctrl+L</kbd>: clear chat log
- <kbd>Tab</kbd>: toggle focus between chat and user tree
- <kbd>Page Up</kbd>: scroll chat up
Expand Down
6 changes: 4 additions & 2 deletions barnard.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ type Barnard struct {
Config *gumble.Config
Client *gumble.Client

Address string
TLSConfig tls.Config
Address string
TLSConfig tls.Config
StartTX bool
StartupChannel string

Stream *gumbleopenal.Stream

Expand Down
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func (b *Barnard) start() {
var err error
_, err = gumble.DialWithDialer(new(net.Dialer), b.Address, b.Config, &b.TLSConfig)
if err != nil {
b.Ui.Close()
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
Expand All @@ -26,6 +27,7 @@ func (b *Barnard) start() {
os.Setenv("ALSOFT_LOGLEVEL", "0")
}
if stream, err := gumbleopenal.New(b.Client); err != nil {
b.Ui.Close()
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
} else {
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ func main() {
password := flag.String("password", "", "the password of the server")
insecure := flag.Bool("insecure", false, "skip server certificate verification")
certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
channel := flag.String("channel", "", "the channel to join")
starttx := flag.Bool("tx", false, "start transmitting immediately")

flag.Parse()

// Initialize
b := Barnard{
Config: gumble.NewConfig(),
Address: *server,
Config: gumble.NewConfig(),
Address: *server,
StartTX: *starttx,
StartupChannel: *channel,
}

b.Config.Username = *username
Expand Down
39 changes: 37 additions & 2 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func (b *Barnard) AddOutputMessage(sender *gumble.User, message string) {
}

func (b *Barnard) OnVoiceToggle(ui *uiterm.Ui, key uiterm.Key) {
b.ToggleVoice()
ui.Refresh()
}

func (b *Barnard) ToggleVoice() {
if b.UiStatus.Text == " Tx " {
b.UiStatus.Text = " Idle "
b.UiStatus.Fg = uiterm.ColorBlack
Expand All @@ -55,7 +60,6 @@ func (b *Barnard) OnVoiceToggle(ui *uiterm.Ui, key uiterm.Key) {
b.UiStatus.Text = " Tx "
b.Stream.StartSource()
}
ui.Refresh()
}

func (b *Barnard) OnQuitPress(ui *uiterm.Ui, key uiterm.Key) {
Expand Down Expand Up @@ -149,15 +153,26 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) {
ui.Add(uiViewTree, &b.UiTree)

b.Ui.AddKeyListener(b.OnFocusPress, uiterm.KeyTab)
b.Ui.AddKeyListener(b.OnVoiceToggle, uiterm.KeyF1)
b.Ui.AddKeyListener(b.ShowHelp, uiterm.KeyF1)
b.Ui.AddKeyListener(b.OnVoiceToggle, uiterm.KeyF2)
b.Ui.AddKeyListener(b.OnQuitPress, uiterm.KeyF10)
b.Ui.AddKeyListener(b.OnClearPress, uiterm.KeyCtrlL)
b.Ui.AddKeyListener(b.OnScrollOutputUp, uiterm.KeyPgup)
b.Ui.AddKeyListener(b.OnScrollOutputDown, uiterm.KeyPgdn)
b.Ui.AddKeyListener(b.OnScrollOutputTop, uiterm.KeyHome)
b.Ui.AddKeyListener(b.OnScrollOutputBottom, uiterm.KeyEnd)

b.showHelp()

b.start()

if b.StartTX {
b.ToggleVoice()
}

if b.StartupChannel != "" {
b.Client.Self.Move(b.Client.Channels.Find(b.StartupChannel))
}
}

func (b *Barnard) OnUiResize(ui *uiterm.Ui, width, height int) {
Expand All @@ -169,3 +184,23 @@ func (b *Barnard) OnUiResize(ui *uiterm.Ui, width, height int) {
ui.SetBounds(uiViewOutput, 0, 1, width-20, height-2)
ui.SetBounds(uiViewTree, width-20, 1, width, height-2)
}

func (b *Barnard) showHelp() {
b.AddOutputLine(" Welcome to Barnard ")
b.AddOutputLine("--------------------------------------------------")
b.AddOutputLine("HELP:")
b.AddOutputLine("F1 : Show this help message")
b.AddOutputLine("F2 : Toggle Voice Transmission")
b.AddOutputLine("CTRL+L : Clear chat log")
b.AddOutputLine("TAB : Toggle focus between chat and user tree")
b.AddOutputLine("Page Up : Scroll chat up")
b.AddOutputLine("Page Down: Scroll chat down")
b.AddOutputLine("HOME : Scroll chat to the top")
b.AddOutputLine("END : Scroll chat to the bottom")
b.AddOutputLine("F10 : Quit")
b.AddOutputLine("--------------------------------------------------")
}

func (b *Barnard) ShowHelp(ui *uiterm.Ui, key uiterm.Key) {
b.showHelp()
}
1 change: 1 addition & 0 deletions uiterm/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func New(manager UiManager) *Ui {

func (ui *Ui) Close() {
if termbox.IsInit {
termbox.Close()
ui.close <- true
}
}
Expand Down