From a1d46e596ea0556ddeffc7abb595c7f81c505558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sat, 24 Sep 2022 20:19:39 -0500 Subject: [PATCH 1/9] Add -tx and -channel flags. For example, to join 'My Channel' and start transmitting immediately: ./barnard -tx -channel "My Channel" --- barnard.go | 6 ++++-- main.go | 8 ++++++-- ui.go | 14 +++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/barnard.go b/barnard.go index 0e121b3..5359aa1 100644 --- a/barnard.go +++ b/barnard.go @@ -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 diff --git a/main.go b/main.go index 7a779d5..e17f56b 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/ui.go b/ui.go index 98b7b7b..ec7d283 100644 --- a/ui.go +++ b/ui.go @@ -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 @@ -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) { @@ -158,6 +162,14 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) { b.Ui.AddKeyListener(b.OnScrollOutputBottom, uiterm.KeyEnd) 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) { From 8d461751a25de280ec1d0c3b453f7187fb68acb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sat, 24 Sep 2022 20:25:53 -0500 Subject: [PATCH 2/9] add development dependency information --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 4bfbdec..8b5e624 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ To fetch and build: 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 From 8be99f2c26297fd8c1ec93fee5eae362c0e0c81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sat, 24 Sep 2022 20:36:19 -0500 Subject: [PATCH 3/9] update to new go syntax --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b5e624..6f2b711 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Requirements: To fetch and build: - go get -u layeh.com/barnard + go install layeh.com/barnard@latest After running the command above, `barnard` will be compiled as `$(go env GOPATH)/bin/barnard`. From cb04fd2fcddac8660e3c554a62f54d3bbb3ff1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sat, 24 Sep 2022 21:53:07 -0500 Subject: [PATCH 4/9] work on formatting --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f2b711..6d58b37 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,21 @@ Requirements: To fetch and build: - go install layeh.com/barnard@latest +```` +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 From 8dfde491e8d51a3d34e2f6d8b87e327ecc6738e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sun, 25 Sep 2022 06:50:31 -0500 Subject: [PATCH 5/9] add help text on startup --- ui.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ui.go b/ui.go index ec7d283..9365b4e 100644 --- a/ui.go +++ b/ui.go @@ -163,6 +163,15 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) { b.start() + b.AddOutputLine("F1 : 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") + if b.StartTX { b.ToggleVoice() } From 5af73815339481f9c965e1eb94088fa1ecaabe39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sun, 25 Sep 2022 08:47:01 -0500 Subject: [PATCH 6/9] move welcome message --- ui.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ui.go b/ui.go index 9365b4e..c6ad971 100644 --- a/ui.go +++ b/ui.go @@ -161,8 +161,9 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) { b.Ui.AddKeyListener(b.OnScrollOutputTop, uiterm.KeyHome) b.Ui.AddKeyListener(b.OnScrollOutputBottom, uiterm.KeyEnd) - b.start() - + b.AddOutputLine(" Welcome to Barnard ") + b.AddOutputLine("--------------------------------------------------") + b.AddOutputLine("HELP:") b.AddOutputLine("F1 : Toggle Voice Transmission") b.AddOutputLine("CTRL+L : Clear chat log") b.AddOutputLine("TAB : Toggle focus between chat and user tree") @@ -171,6 +172,9 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) { b.AddOutputLine("HOME : Scroll chat to the top") b.AddOutputLine("END : Scroll chat to the bottom") b.AddOutputLine("F10 : Quit") + b.AddOutputLine("--------------------------------------------------") + + b.start() if b.StartTX { b.ToggleVoice() From 618ebf31fbbc23b0c8228646386dc6735a8c3c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sun, 25 Sep 2022 08:56:18 -0500 Subject: [PATCH 7/9] F1 help. F2 TX Toggle --- ui.go | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/ui.go b/ui.go index c6ad971..1db6059 100644 --- a/ui.go +++ b/ui.go @@ -153,7 +153,8 @@ 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) @@ -161,18 +162,7 @@ func (b *Barnard) OnUiInitialize(ui *uiterm.Ui) { b.Ui.AddKeyListener(b.OnScrollOutputTop, uiterm.KeyHome) b.Ui.AddKeyListener(b.OnScrollOutputBottom, uiterm.KeyEnd) - b.AddOutputLine(" Welcome to Barnard ") - b.AddOutputLine("--------------------------------------------------") - b.AddOutputLine("HELP:") - b.AddOutputLine("F1 : 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("--------------------------------------------------") + b.showHelp() b.start() @@ -194,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() +} From 5ca53cb459687912db2a1c0d1902f0e5f7478fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sun, 25 Sep 2022 16:44:35 -0500 Subject: [PATCH 8/9] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d58b37..e7cc424 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ go build ### Key bindings -- F1: toggle voice transmission +- F1: show help +- F2: toggle voice transmission - Ctrl+L: clear chat log - Tab: toggle focus between chat and user tree - Page Up: scroll chat up From f9843f5064c87c6619da6fb5f7c53c32321bb09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A0=20Gregory=20L=2E=20Dietsche=20=E2=9C=A0?= Date: Sun, 25 Sep 2022 18:03:07 -0500 Subject: [PATCH 9/9] When exiting in error the console stops working Properly close termbox so that the user's cursor will work correctly. Without this fix, the user needs to run `reset` to restore normal console functionality. --- client.go | 2 ++ uiterm/ui.go | 1 + 2 files changed, 3 insertions(+) diff --git a/client.go b/client.go index 6f932e5..a1857fe 100644 --- a/client.go +++ b/client.go @@ -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) } @@ -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 { diff --git a/uiterm/ui.go b/uiterm/ui.go index 31114c7..a5b8f59 100644 --- a/uiterm/ui.go +++ b/uiterm/ui.go @@ -45,6 +45,7 @@ func New(manager UiManager) *Ui { func (ui *Ui) Close() { if termbox.IsInit { + termbox.Close() ui.close <- true } }