aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2021-08-03 18:07:10 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2021-08-03 13:07:10 -0700
commitda1e0d79561ded0b3998a50a1d14a16b5c9a24bc (patch)
tree79789e0d215c486c3f766f2467f2bbd72f68ddfc /hotline
parentb25c4a19420c2fde1f290dd360c68b84e4eaa1ed (diff)
Initial bookmark creation
Diffstat (limited to 'hotline')
-rw-r--r--hotline/client.go6
-rw-r--r--hotline/ui.go24
2 files changed, 26 insertions, 4 deletions
diff --git a/hotline/client.go b/hotline/client.go
index b423f9f..e676e65 100644
--- a/hotline/client.go
+++ b/hotline/client.go
@@ -46,6 +46,12 @@ func (cp *ClientPrefs) IconBytes() []byte {
return iconBytes
}
+func (cp *ClientPrefs) AddBookmark(name, addr, login, pass string) error {
+ cp.Bookmarks = append(cp.Bookmarks, Bookmark{Addr: addr, Login: login, Password: pass})
+
+ return nil
+}
+
func readConfig(cfgPath string) (*ClientPrefs, error) {
fh, err := os.Open(cfgPath)
if err != nil {
diff --git a/hotline/ui.go b/hotline/ui.go
index 5f1670d..b8c0430 100644
--- a/hotline/ui.go
+++ b/hotline/ui.go
@@ -95,7 +95,7 @@ func (ui *UI) showBookmarks() *tview.List {
list.AddItem(srv.Name, srv.Addr, rune(shortcut+i), func() {
ui.Pages.RemovePage("joinServer")
- newJS := ui.renderJoinServerForm(addr, login, pass, "bookmarks", true, true)
+ newJS := ui.renderJoinServerForm("", addr, login, pass, "bookmarks", true, true)
ui.Pages.AddPage("joinServer", newJS, true, true)
})
@@ -125,7 +125,7 @@ func (ui *UI) getTrackerList() *tview.List {
list.AddItem(string(srv.Name), string(srv.Description), rune(shortcut+i), func() {
ui.Pages.RemovePage("joinServer")
- newJS := ui.renderJoinServerForm(addr, GuestAccount, "", trackerListPage, false, true)
+ newJS := ui.renderJoinServerForm("", addr, GuestAccount, "", trackerListPage, false, true)
ui.Pages.AddPage("joinServer", newJS, true, true)
ui.Pages.ShowPage("joinServer")
@@ -220,14 +220,30 @@ func (ui *UI) joinServer(addr, login, password string) error {
return nil
}
-func (ui *UI) renderJoinServerForm(server, login, password, backPage string, save, defaultConnect bool) *tview.Flex {
+func (ui *UI) renderJoinServerForm(name, server, login, password, backPage string, save, defaultConnect bool) *tview.Flex {
joinServerForm := tview.NewForm()
joinServerForm.
+ // AddInputField("Name", server, 0, func(textToCheck string, lastChar rune) bool {
+ // return false
+ //}, nil).
AddInputField("Server", server, 0, nil, nil).
AddInputField("Login", login, 0, nil, nil).
AddPasswordField("Password", password, 0, '*', nil).
AddCheckbox("Save", save, func(checked bool) {
+ ui.HLClient.Logger.Infow("saving bookmark")
// TODO: Implement bookmark saving
+
+ ui.HLClient.pref.AddBookmark(joinServerForm.GetFormItem(0).(*tview.InputField).GetText(), joinServerForm.GetFormItem(0).(*tview.InputField).GetText(), joinServerForm.GetFormItem(1).(*tview.InputField).GetText(), joinServerForm.GetFormItem(2).(*tview.InputField).GetText())
+ out, err := yaml.Marshal(ui.HLClient.pref)
+ if err != nil {
+ panic(err)
+ }
+
+ err = ioutil.WriteFile(ui.HLClient.cfgPath, out, 0666)
+ if err != nil {
+ panic(err)
+ }
+ // pref := ui.HLClient.pref
}).
AddButton("Cancel", func() {
ui.Pages.SwitchToPage(backPage)
@@ -439,7 +455,7 @@ func (ui *UI) Start() {
)
mainMenu.AddItem("Join Server", "", 'j', func() {
- joinServerPage := ui.renderJoinServerForm("", GuestAccount, "", "home", false, false)
+ joinServerPage := ui.renderJoinServerForm("", "", GuestAccount, "", "home", false, false)
ui.Pages.AddPage("joinServer", joinServerPage, true, true)
}).
AddItem("Bookmarks", "", 'b', func() {