Commit fb0a2ea
Changed files (1)
command.go
@@ -5,6 +5,7 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "golang.org/x/crypto/ssh/terminal"
"io/ioutil"
"log"
"net/http"
@@ -108,18 +109,22 @@ func runTest(clientTest *ClientTest) {
numCorrect := 0
for i, record := range clientTest.Records {
fmt.Printf("%d) [%s] %s\n", i+1, COLOR_BLUE+categoryKeys[record.Category]+COLOR_RESET,
- COLOR_GREEN+record.Question+COLOR_RESET)
+ record.Question)
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
+ width, _, _ := terminal.GetSize(int(os.Stdin.Fd()))
if strings.Compare(input, record.Answer) == 0 {
- fmt.Println("Correct.")
+ // dynamically determine width of screen for right-alignment
+ fmt.Printf("%"+strconv.Itoa(width)+"s\n", COLOR_GREEN+"[ ]"+COLOR_RESET)
clientTest.Records[i].AnsweredCorrectly = true
numCorrect++
} else if strings.Compare(input, "exit") == 0 {
clientTest.Score = calculateScore(numCorrect, len(clientTest.Records))
return
} else {
- fmt.Printf("Incorrect. Correct answer was: %s\n", COLOR_RED+record.Answer+COLOR_RESET)
+ fmt.Printf("%s%"+strconv.Itoa(width-len(record.Answer)-5)+"s\n",
+ COLOR_RED+record.Answer,
+ "[x]"+COLOR_RESET)
clientTest.Records[i].ClientAnswer = input
}
}