cli: Improve use of readline slightly
This commit is contained in:
parent
8664873b5b
commit
eb9814c14b
|
@ -3,9 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chzyer/readline"
|
||||||
rpc "github.com/ricochet-im/ricochet-go/rpc"
|
rpc "github.com/ricochet-im/ricochet-go/rpc"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"gopkg.in/readline.v1"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
|
@ -48,10 +48,6 @@ func (c *Conversation) SendMessage(text string) error {
|
||||||
if err := c.validateMessage(msg); err != nil {
|
if err := c.validateMessage(msg); err != nil {
|
||||||
log.Printf("Conversation sent message does not validate: %v", err)
|
log.Printf("Conversation sent message does not validate: %v", err)
|
||||||
}
|
}
|
||||||
c.messages = append(c.messages, msg)
|
|
||||||
c.trimBacklog()
|
|
||||||
c.printMessage(msg)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +220,7 @@ func (c *Conversation) printMessage(msg *ricochet.Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX shell escaping
|
// 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,
|
ts,
|
||||||
c.Contact.Data.Nickname,
|
c.Contact.Data.Nickname,
|
||||||
direction,
|
direction,
|
||||||
|
|
10
cli/ui.go
10
cli/ui.go
|
@ -3,9 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/chzyer/readline"
|
||||||
"github.com/ricochet-im/ricochet-go/rpc"
|
"github.com/ricochet-im/ricochet-go/rpc"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"gopkg.in/readline.v1"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -163,17 +163,17 @@ func (ui *UI) SetCurrentContact(contact *Contact) {
|
||||||
|
|
||||||
ui.CurrentContact = contact
|
ui.CurrentContact = contact
|
||||||
if ui.CurrentContact != nil {
|
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.Prompt = fmt.Sprintf("\x1b[90m00:00\x1b[39m | %s \x1b[34m<<\x1b[39m ", contact.Data.Nickname)
|
||||||
config.UniqueEditLine = true
|
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()))
|
fmt.Printf("--- %s (%s) ---\n", contact.Data.Nickname, strings.ToLower(contact.Data.Status.String()))
|
||||||
contact.Conversation.PrintContext()
|
contact.Conversation.PrintContext()
|
||||||
contact.Conversation.MarkAsRead()
|
contact.Conversation.MarkAsRead()
|
||||||
} else {
|
} else {
|
||||||
config := *ui.Input.Config
|
config := ui.Input.Config.Clone()
|
||||||
config.Prompt = "> "
|
config.Prompt = "> "
|
||||||
config.UniqueEditLine = false
|
config.UniqueEditLine = false
|
||||||
ui.Input.SetConfig(&config)
|
ui.Input.SetConfig(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue