aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJulien Dessaux2021-01-18 12:05:52 +0100
committerJulien Dessaux2021-01-18 12:05:52 +0100
commitb466483e7a15f3e0045a98a766e50321dbf883e9 (patch)
tree00ba86f98442c25c2fa80af1b346c686cad0a8d2 /client
parentRemoved needlessly complex menu display offset settings (diff)
downloadshell-game-launcher-b466483e7a15f3e0045a98a766e50321dbf883e9.tar.gz
shell-game-launcher-b466483e7a15f3e0045a98a766e50321dbf883e9.tar.bz2
shell-game-launcher-b466483e7a15f3e0045a98a766e50321dbf883e9.zip
Display logged in status in menu
Diffstat (limited to 'client')
-rw-r--r--client/menu.go5
-rw-r--r--client/menu_test.go49
2 files changed, 52 insertions, 2 deletions
diff --git a/client/menu.go b/client/menu.go
index 19c8992..f6de082 100644
--- a/client/menu.go
+++ b/client/menu.go
@@ -6,6 +6,11 @@ func (s *State) displayMenu() {
menu := s.config.Menus[s.currentMenu]
fmt.Print("\033[2J") // clear the screen
fmt.Printf("%s\n\n", menu.Banner)
+ if s.login == "" {
+ fmt.Print("Not logged in.\n\n")
+ } else {
+ fmt.Printf("Logged in as: %s\n\n", s.login)
+ }
for i := 0; i < len(menu.MenuEntries); i++ {
fmt.Printf("%s) %s\n", menu.MenuEntries[i].Key, menu.MenuEntries[i].Label)
}
diff --git a/client/menu_test.go b/client/menu_test.go
index aaf3d81..9d7a8bc 100644
--- a/client/menu_test.go
+++ b/client/menu_test.go
@@ -14,7 +14,7 @@ func TestDisplayMenu(t *testing.T) {
r, w, _ := os.Pipe()
os.Stdout = w
- // Complete menu
+ // Complete menu, while not logged in
state := State{
config: &config.Config{
Menus: map[string]config.Menu{
@@ -31,11 +31,13 @@ func TestDisplayMenu(t *testing.T) {
},
},
currentMenu: "test",
- login: "nil",
+ login: "",
}
want := []byte("\033[2J" +
"TEST TEST TEST\n" +
"\n" +
+ "Not logged in.\n" +
+ "\n" +
"q) quit\n")
state.displayMenu()
// back to normal state
@@ -44,4 +46,47 @@ func TestDisplayMenu(t *testing.T) {
if !reflect.DeepEqual(out, want) {
t.Fatalf("menu displayed incorrectly:\nwant:%+v\ngot: %+v", want, out)
}
+
+ // Complete menu, while logged in
+ r, w, _ = os.Pipe()
+ os.Stdout = w
+
+ // Complete menu, while not logged in
+ state = State{
+ config: &config.Config{
+ Menus: map[string]config.Menu{
+ "test": config.Menu{
+ Banner: "TEST TEST TEST",
+ MenuEntries: []config.MenuEntry{
+ config.MenuEntry{
+ Key: "w",
+ Label: "wait",
+ Action: "wait",
+ },
+ config.MenuEntry{
+ Key: "q",
+ Label: "quit",
+ Action: "quit",
+ },
+ },
+ },
+ },
+ },
+ currentMenu: "test",
+ login: "test",
+ }
+ want = []byte("\033[2J" +
+ "TEST TEST TEST\n" +
+ "\n" +
+ "Logged in as: test\n" +
+ "\n" +
+ "w) wait\n" +
+ "q) quit\n")
+ state.displayMenu()
+ // back to normal state
+ w.Close()
+ out, _ = ioutil.ReadAll(r)
+ if !reflect.DeepEqual(out, want) {
+ t.Fatalf("menu displayed incorrectly:\nwant:%+v\ngot: %+v", want, out)
+ }
}