2016-08-02 02:58:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-10-16 21:50:34 +00:00
|
|
|
"bytes"
|
2016-08-17 00:58:39 +00:00
|
|
|
"fmt"
|
2016-10-23 18:37:57 +00:00
|
|
|
"github.com/chzyer/readline"
|
2016-10-17 04:26:35 +00:00
|
|
|
rpc "github.com/ricochet-im/ricochet-go/rpc"
|
2016-08-02 02:58:10 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"log"
|
2016-09-30 05:17:03 +00:00
|
|
|
"os"
|
2016-08-02 02:58:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultAddress = "127.0.0.1:58281"
|
|
|
|
)
|
|
|
|
|
2016-10-16 21:50:34 +00:00
|
|
|
var LogBuffer bytes.Buffer
|
|
|
|
|
2016-08-17 00:58:39 +00:00
|
|
|
func main() {
|
2016-10-26 21:26:21 +00:00
|
|
|
input, err := readline.NewEx(&readline.Config{
|
|
|
|
InterruptPrompt: "^C",
|
|
|
|
EOFPrompt: "exit",
|
|
|
|
})
|
2016-08-02 23:28:26 +00:00
|
|
|
if err != nil {
|
2016-10-16 21:50:34 +00:00
|
|
|
fmt.Println(err)
|
2016-09-30 05:17:03 +00:00
|
|
|
os.Exit(1)
|
2016-08-02 23:28:26 +00:00
|
|
|
}
|
2016-10-16 21:50:34 +00:00
|
|
|
defer input.Close()
|
|
|
|
log.SetOutput(&LogBuffer)
|
2016-08-02 23:28:26 +00:00
|
|
|
|
2016-10-16 21:50:34 +00:00
|
|
|
conn, err := grpc.Dial(defaultAddress, grpc.WithInsecure())
|
2016-08-17 00:58:39 +00:00
|
|
|
if err != nil {
|
2016-10-16 21:50:34 +00:00
|
|
|
fmt.Printf("connection failed: %v\n", err)
|
2016-09-30 05:17:03 +00:00
|
|
|
os.Exit(1)
|
2016-08-17 00:58:39 +00:00
|
|
|
}
|
2016-10-16 21:50:34 +00:00
|
|
|
defer conn.Close()
|
2016-08-17 00:58:39 +00:00
|
|
|
|
2016-10-16 04:57:16 +00:00
|
|
|
client := &Client{
|
2016-08-17 00:58:39 +00:00
|
|
|
Backend: rpc.NewRicochetCoreClient(conn),
|
|
|
|
}
|
2016-10-23 00:50:21 +00:00
|
|
|
Ui = UI{
|
2016-10-16 04:57:16 +00:00
|
|
|
Input: input,
|
2016-10-23 19:42:45 +00:00
|
|
|
Stdout: input.Stdout(),
|
2016-10-16 04:57:16 +00:00
|
|
|
Client: client,
|
|
|
|
}
|
2016-08-17 00:58:39 +00:00
|
|
|
|
2016-10-16 21:50:34 +00:00
|
|
|
fmt.Print("Connecting to backend...\n")
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
if err := client.Initialize(); err != nil {
|
|
|
|
fmt.Printf("Error: %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
client.Block()
|
2016-10-23 00:50:21 +00:00
|
|
|
Ui.PrintStatus()
|
2016-10-16 21:50:34 +00:00
|
|
|
client.Unblock()
|
|
|
|
}()
|
2016-08-17 00:58:39 +00:00
|
|
|
|
2016-10-23 00:50:21 +00:00
|
|
|
Ui.CommandLoop()
|
2016-08-02 02:58:10 +00:00
|
|
|
}
|