Commit 457a368

Richard Luby <richluby@gmail.com>
2016-11-16 16:23:56
status bar used
program uses status bar to provide information to user on effectiveness of command
1 parent be19e62
Changed files (1)
clientVisualization.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"fmt"
 	"github.com/jroimartin/gocui"
 	"log"
 	"os"
@@ -46,6 +47,21 @@ func updateMainView() {
 	})
 }
 
+// updateMainView causes the main view to update
+// the display
+func setStatusBar(status string) {
+	ApplicationView.MainGui.Execute(func(arg1 *gocui.Gui) error {
+		if ApplicationView.MainGui == nil {
+			return nil
+		}
+		if view, err := ApplicationView.MainGui.View(ApplicationView.STATUS_BAR_NAME); err == nil {
+			view.Clear()
+			view.Write([]byte(status))
+		}
+		return nil
+	})
+}
+
 // reads input from the user in the main screen
 func readInputFromMainScreen() (string, error) {
 	if ApplicationView.MainGui == nil {
@@ -123,12 +139,12 @@ func initProgressView(g *gocui.Gui, maxX int, maxY int) error {
 	//Progress Bar
 	v, err := g.SetView(ApplicationView.STATUS_BAR_NAME,
 		0, maxY-ApplicationView.STATUS_BAR_HEIGHT-3,
-		maxX-4, maxY-2)
+		maxX-5, maxY-2)
 	if err != nil {
 		if err != gocui.ErrUnknownView {
 			return err
 		}
-		v.Title = "Progress"
+		v.Title = "Status"
 		v.Editable = false
 	}
 	return nil
@@ -214,9 +230,11 @@ func handleEnterKeyPress(g *gocui.Gui, v *gocui.View) error {
 	var input string
 	var command Command
 	var err error
+	setStatusBar("")
 	input, err = readInputFromMainScreen()
 	if err != nil {
 		log.Printf("Error reading input: %+v", err)
+		setStatusBar(fmt.Sprintf(COLOR_RED+"Error reading input: %+v"+COLOR_RESET, err))
 		return nil
 	}
 	args := strings.Fields(input)
@@ -226,18 +244,22 @@ func handleEnterKeyPress(g *gocui.Gui, v *gocui.View) error {
 	// select a command from the list of available commands
 	if command, err = SelectCommand(strings.TrimSpace(args[0]), commandArray); err != nil {
 		log.Printf("Error while parsing command: %+v", err)
+		setStatusBar(fmt.Sprintf(COLOR_RED+"Error while parsing command: %+v"+COLOR_RESET, err))
 		return nil
 	}
 	// parse the flags for the command
 	err = ParseUserCommands(args[1:], &command)
 	if err != nil {
 		log.Printf("Error while parsing parameters: %+v", err)
+		setStatusBar(fmt.Sprintf(COLOR_RED+"Error while parsing parameters: %+v"+COLOR_RESET, err))
 		return nil
 	}
 	// execute the command and check for any errors that may have occurred
-	go func() {
+	go func() { // must be separate function for the calls that block
+		// on user input
 		if err = command.Run(command); err != nil {
 			log.Printf("Error while executing command: %+v", err)
+			setStatusBar(fmt.Sprintf(COLOR_RED+"Error while executing command: %+v"+COLOR_RESET, err))
 		}
 	}()
 	return nil