Commit c686b04

Richard Luby <richluby@gmail.com>
2016-11-17 09:00:31
fixed display issues
fixed issues with missing newlines or buffer not jumping to correct location. fixed issue where buffer would not update until user typed a key
1 parent 7fad08d
clientVisualization.go
@@ -255,7 +255,6 @@ func scrollView(v *gocui.View, dy int) error {
 // pressing 'Enter'
 func handleEnterKeyPress(g *gocui.Gui, v *gocui.View) error {
 	view, err := ApplicationView.MainGui.View(ApplicationView.MAIN_WINDOW_NAME)
-	view.Autoscroll = true
 	if readUserInputSemaphore.Queued() > 0 {
 		readUserInputSemaphore.V() //taken whenever user input is required
 		return nil
@@ -293,6 +292,8 @@ func handleEnterKeyPress(g *gocui.Gui, v *gocui.View) error {
 			log.Printf("Error while executing command: %+v", err)
 			setStatusBar(fmt.Sprintf(COLOR_RED+"Error while executing command: %+v"+COLOR_RESET, err))
 		}
+		view.Autoscroll = true
+		updateMainView()
 	}()
 	return nil
 }
command.go
@@ -98,7 +98,6 @@ func displayHelp(command Command) error {
 			}
 		}
 	}
-	updateMainView()
 	return nil
 }
 
@@ -129,16 +128,15 @@ func displayTests(clientTests *[]ClientTest) {
 	displayStringToMainScreen("\n" + hardRule + "\n")
 	displayStringToMainScreen(fmt.Sprintf("Average: %.2f%%\n%s\nQuestions Answered: %.0f\t Questions Correct: %.0f\n%s",
 		numCorrect/numQuestions*100, hardRule, numQuestions, numCorrect, hardRule))
-	updateMainView()
 }
 
 // displayTest displays a single test to the user
 func displayTest(clientTest ClientTest) {
-	displayStringToMainScreen(fmt.Sprintf("Questions: %3d\nScore: %5.2f%%\n",
+	displayStringToMainScreen(fmt.Sprintf("\nQuestions: %3d\nScore: %5.2f%%\n",
 		len(clientTest.Records), clientTest.Score))
 	//	width, _, _ := terminal.GetSize(int(os.Stdin.Fd()))
 	for i, record := range clientTest.Records {
-		displayStringToMainScreen(fmt.Sprintf("%2d) %s", i, record.Question))
+		displayStringToMainScreen(fmt.Sprintf("%2d) %s", i+1, record.Question))
 		answerLine := fmt.Sprintf("\nCorrect: %-25s Answer: %-25s",
 			COLOR_GREEN+record.Answer+COLOR_RESET, COLOR_RED+record.ClientAnswer+COLOR_RESET)
 		if record.AnsweredCorrectly {
@@ -244,7 +242,7 @@ func postRecordsToServer(recordArray *ClientTest) error {
 	if resp.StatusCode != http.StatusCreated {
 		return fmt.Errorf("Error sending the results to the server: %s", response)
 	} else {
-		displayStringToMainScreen("\nTest submitted successfully.")
+		setStatusBar("Test submitted successfully.")
 	}
 	return err
 }
@@ -316,13 +314,14 @@ func buildBluePrint(useBlueprint bool) (string, error) {
 		return "", nil
 	}
 	var blueprint string
-	displayStringToMainScreen("Categories\n----------\n")
+	displayStringToMainScreen("\nCategories\n----------\n")
 	for i := 0; i < len(categoryKeys)-1; i += 2 {
 		displayStringToMainScreen(fmt.Sprintf("%d) %-15s\t%d) %-15s\n",
 			i, categoryKeys[i],
 			i+1, categoryKeys[i+1]))
 	}
 	displayStringToMainScreen("Enter the category numbers, separated by a comma: ")
+	updateMainView()
 	readUserInputSemaphore.P()
 	input, _ := readInputFromMainScreen()
 	splits := strings.Split(input, ",")