cli: Prettify contacts list
This commit is contained in:
parent
60cdd16311
commit
db6295d5c8
|
@ -17,7 +17,10 @@ const (
|
||||||
var LogBuffer bytes.Buffer
|
var LogBuffer bytes.Buffer
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
input, err := readline.NewEx(&readline.Config{})
|
input, err := readline.NewEx(&readline.Config{
|
||||||
|
InterruptPrompt: "^C",
|
||||||
|
EOFPrompt: "exit",
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
28
cli/ui.go
28
cli/ui.go
|
@ -167,9 +167,14 @@ func (ui *UI) ListContacts() {
|
||||||
if len(contacts) == 0 {
|
if len(contacts) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Fprintf(ui.Stdout, ". %s\n", strings.ToLower(status.String()))
|
fmt.Fprintf(ui.Stdout, "%s\n", ColoredContactStatus(status))
|
||||||
for _, contact := range contacts {
|
for _, contact := range contacts {
|
||||||
fmt.Fprintf(ui.Stdout, "... [%d] %s\n", contact.Data.Id, contact.Data.Nickname)
|
unreadCount := contact.Conversation.UnreadCount()
|
||||||
|
if unreadCount > 0 {
|
||||||
|
fmt.Fprintf(ui.Stdout, " \x1b[1m%s\x1b[0m (\x1b[1m%d\x1b[0m) -- \x1b[34;1m%d new messages\x1b[0m\n", contact.Data.Nickname, contact.Data.Id, unreadCount)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(ui.Stdout, " %s (\x1b[1m%d\x1b[0m)\n", contact.Data.Nickname, contact.Data.Id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,6 +260,23 @@ func (ui *UI) setupConversationPrompt() {
|
||||||
listener.Install()
|
listener.Install()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ColoredContactStatus(status ricochet.Contact_Status) string {
|
||||||
|
switch status {
|
||||||
|
case ricochet.Contact_UNKNOWN:
|
||||||
|
return "\x1b[31moffline\x1b[39m"
|
||||||
|
case ricochet.Contact_OFFLINE:
|
||||||
|
return "\x1b[31moffline\x1b[39m"
|
||||||
|
case ricochet.Contact_ONLINE:
|
||||||
|
return "\x1b[32monline\x1b[39m"
|
||||||
|
case ricochet.Contact_REQUEST:
|
||||||
|
return "\x1b[33mcontact request\x1b[39m"
|
||||||
|
case ricochet.Contact_REJECTED:
|
||||||
|
return "\x1b[31mrejected\x1b[39m"
|
||||||
|
default:
|
||||||
|
return status.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ui *UI) SetCurrentContact(contact *Contact) {
|
func (ui *UI) SetCurrentContact(contact *Contact) {
|
||||||
if ui.CurrentContact == contact {
|
if ui.CurrentContact == contact {
|
||||||
return
|
return
|
||||||
|
@ -263,7 +285,7 @@ func (ui *UI) SetCurrentContact(contact *Contact) {
|
||||||
ui.CurrentContact = contact
|
ui.CurrentContact = contact
|
||||||
if ui.CurrentContact != nil {
|
if ui.CurrentContact != nil {
|
||||||
ui.setupConversationPrompt()
|
ui.setupConversationPrompt()
|
||||||
fmt.Fprintf(ui.Stdout, "--- %s (%s) ---\n", contact.Data.Nickname, strings.ToLower(contact.Data.Status.String()))
|
fmt.Fprintf(ui.Stdout, "------- \x1b[1m%s\x1b[0m is %s -------\n", contact.Data.Nickname, ColoredContactStatus(contact.Data.Status))
|
||||||
contact.Conversation.PrintContext()
|
contact.Conversation.PrintContext()
|
||||||
contact.Conversation.MarkAsRead()
|
contact.Conversation.MarkAsRead()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue