cli: Improve use of readline slightly

This commit is contained in:
John Brooks 2016-10-23 11:37:57 -07:00
parent 8664873b5b
commit eb9814c14b
3 changed files with 7 additions and 11 deletions

View File

@ -3,9 +3,9 @@ package main
import (
"bytes"
"fmt"
"github.com/chzyer/readline"
rpc "github.com/ricochet-im/ricochet-go/rpc"
"google.golang.org/grpc"
"gopkg.in/readline.v1"
"log"
"os"
)

View File

@ -48,10 +48,6 @@ func (c *Conversation) SendMessage(text string) error {
if err := c.validateMessage(msg); err != nil {
log.Printf("Conversation sent message does not validate: %v", err)
}
c.messages = append(c.messages, msg)
c.trimBacklog()
c.printMessage(msg)
return nil
}
@ -224,7 +220,7 @@ func (c *Conversation) printMessage(msg *ricochet.Message) {
}
// XXX shell escaping
fmt.Fprintf(Ui.Input.Stdout(), "\r%s | %s %s %s\n",
fmt.Fprintf(Ui.Input.Stdout(), "%s | %s %s %s\n",
ts,
c.Contact.Data.Nickname,
direction,

View File

@ -3,9 +3,9 @@ package main
import (
"errors"
"fmt"
"github.com/chzyer/readline"
"github.com/ricochet-im/ricochet-go/rpc"
"golang.org/x/net/context"
"gopkg.in/readline.v1"
"strconv"
"strings"
)
@ -163,17 +163,17 @@ func (ui *UI) SetCurrentContact(contact *Contact) {
ui.CurrentContact = contact
if ui.CurrentContact != nil {
config := *ui.Input.Config
config := ui.Input.Config.Clone()
config.Prompt = fmt.Sprintf("\x1b[90m00:00\x1b[39m | %s \x1b[34m<<\x1b[39m ", contact.Data.Nickname)
config.UniqueEditLine = true
ui.Input.SetConfig(&config)
ui.Input.SetConfig(config)
fmt.Printf("--- %s (%s) ---\n", contact.Data.Nickname, strings.ToLower(contact.Data.Status.String()))
contact.Conversation.PrintContext()
contact.Conversation.MarkAsRead()
} else {
config := *ui.Input.Config
config := ui.Input.Config.Clone()
config.Prompt = "> "
config.UniqueEditLine = false
ui.Input.SetConfig(&config)
ui.Input.SetConfig(config)
}
}