]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/client.go
Merge pull request #91 from jhalter/fix_article_reply_threading
[rbdr/mobius] / hotline / client.go
index c32256298def76bf16373d678d985071ecc8f308..c7c1463b118e4d5aa2a68fcb6cd8b456e137833e 100644 (file)
@@ -35,10 +35,11 @@ type Bookmark struct {
 }
 
 type ClientPrefs struct {
-       Username  string     `yaml:"Username"`
-       IconID    int        `yaml:"IconID"`
-       Bookmarks []Bookmark `yaml:"Bookmarks"`
-       Tracker   string     `yaml:"Tracker"`
+       Username   string     `yaml:"Username"`
+       IconID     int        `yaml:"IconID"`
+       Bookmarks  []Bookmark `yaml:"Bookmarks"`
+       Tracker    string     `yaml:"Tracker"`
+       EnableBell bool       `yaml:"EnableBell"`
 }
 
 func (cp *ClientPrefs) IconBytes() []byte {
@@ -237,7 +238,41 @@ func handleTranServerMsg(c *Client, t *Transaction) (res []Transaction, err erro
        return res, err
 }
 
+func (c *Client) showErrMsg(msg string) {
+       time := time.Now().Format(time.RFC850)
+
+       title := "| Error |"
+
+       msgBox := tview.NewTextView().SetScrollable(true)
+       msgBox.SetText(msg).SetBackgroundColor(tcell.ColorDarkRed)
+       msgBox.SetTitle(title).SetBorder(true)
+       msgBox.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
+               switch event.Key() {
+               case tcell.KeyEscape:
+                       c.UI.Pages.RemovePage("serverMsgModal" + time)
+               }
+               return event
+       })
+
+       centeredFlex := tview.NewFlex().
+               AddItem(nil, 0, 1, false).
+               AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
+                       AddItem(nil, 0, 1, false).
+                       AddItem(msgBox, 0, 2, true).
+                       AddItem(nil, 0, 1, false), 0, 2, true).
+               AddItem(nil, 0, 1, false)
+
+       c.UI.Pages.AddPage("serverMsgModal"+time, centeredFlex, true, true)
+       c.UI.App.Draw() // TODO: errModal doesn't render without this.  wtf?
+}
+
 func handleGetFileNameList(c *Client, t *Transaction) (res []Transaction, err error) {
+       if t.IsError() {
+               c.showErrMsg(string(t.GetField(fieldError).Data))
+               c.Logger.Infof("Error: %s", t.GetField(fieldError).Data)
+               return res, err
+       }
+
        fTree := tview.NewTreeView().SetTopLevel(1)
        root := tview.NewTreeNode("Root")
        fTree.SetRoot(root).SetCurrentNode(root)
@@ -432,6 +467,10 @@ func (c *Client) renderUserList() {
 }
 
 func handleClientChatMsg(c *Client, t *Transaction) (res []Transaction, err error) {
+       if c.pref.EnableBell {
+               fmt.Println("\a")
+       }
+
        _, _ = fmt.Fprintf(c.UI.chatBox, "%s \n", t.GetField(fieldData).Data)
 
        return res, err