From a22de02531864759e773650a988a9ebbd99cd4b7 Mon Sep 17 00:00:00 2001 From: John Brooks Date: Sat, 22 Oct 2016 17:50:21 -0700 Subject: [PATCH] cli: Make UI struct singleton --- cli/cli.go | 7 +++---- cli/client.go | 5 ++--- cli/ui.go | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 4a8ffe7..efd9295 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -35,11 +35,10 @@ func main() { client := &Client{ Backend: rpc.NewRicochetCoreClient(conn), } - ui := &UI{ + Ui = UI{ Input: input, Client: client, } - client.Ui = ui fmt.Print("Connecting to backend...\n") @@ -49,9 +48,9 @@ func main() { os.Exit(1) } client.Block() - ui.PrintStatus() + Ui.PrintStatus() client.Unblock() }() - ui.CommandLoop() + Ui.CommandLoop() } diff --git a/cli/client.go b/cli/client.go index b54b4d3..1b9291e 100644 --- a/cli/client.go +++ b/cli/client.go @@ -9,7 +9,6 @@ import ( type Client struct { Backend ricochet.RicochetCoreClient - Ui *UI ServerStatus ricochet.ServerStatusReply Identity ricochet.Identity @@ -227,8 +226,8 @@ func (c *Client) onContactEvent(event *ricochet.ContactEvent) { contact, _ := c.Contacts.Deleted(data) - if c.Ui.CurrentContact == contact { - c.Ui.SetCurrentContact(nil) + if Ui.CurrentContact == contact { + Ui.SetCurrentContact(nil) } default: diff --git a/cli/ui.go b/cli/ui.go index b8cc5cc..2aa539b 100644 --- a/cli/ui.go +++ b/cli/ui.go @@ -10,6 +10,8 @@ import ( "strings" ) +var Ui UI + type UI struct { Input *readline.Instance Client *Client