ref: 35959699c979b584314702e7d6f27c6cebf25c69
dir: /hellclient.go/
package main
import (
"io"
"strings"
"sync"
"github.com/chzyer/readline"
"github.com/mattn/go-mastodon"
)
var (
ErrInterrupt = readline.ErrInterrupt
EOF = io.EOF
)
type Hellclient struct {
isPaused bool
rl *readline.Instance
block sync.Mutex
//Only use these in one routine at a time unless you add a mutex
homeMap map[string]*mastodon.Status
debugMap map[string]interface{}
}
func NewHellclient() (*Hellclient, error) {
rl, err := readline.New("> ")
homeMap := make(map[string]*mastodon.Status)
debugMap := make(map[string]interface{})
if err != nil {
return nil, err
}
return &Hellclient{rl: rl, homeMap: homeMap, debugMap: debugMap, isPaused: false}, nil
}
func (hc *Hellclient) updatePrompt() {
var sb strings.Builder
if hc.isPaused {
sb.WriteString("STREAMING PAUSED ")
}
sb.WriteString("> ")
hc.rl.SetPrompt(sb.String())
}
func (hc *Hellclient) pause(on bool) {
hc.isPaused = on
hc.updatePrompt()
}
func (hc *Hellclient) togglepause() {
hc.isPaused = !hc.isPaused
hc.updatePrompt()
}
func (hc *Hellclient) lock() {
hc.block.Lock()
}
func (hc *Hellclient) unlock() {
hc.block.Unlock()
}