From 4a808e5c97725b0fb4174b6961722a3f4600b9a7 Mon Sep 17 00:00:00 2001
From: Flu0r1ne <flur01ne@flu0r1ne.net>
Date: Fri, 13 Aug 2021 18:15:26 -0500
Subject: Clean up fencing

---
 cmd/planr/sub/cli.go | 53 ++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

(limited to 'cmd')

diff --git a/cmd/planr/sub/cli.go b/cmd/planr/sub/cli.go
index 2bcaed9..da888d9 100644
--- a/cmd/planr/sub/cli.go
+++ b/cmd/planr/sub/cli.go
@@ -4,6 +4,7 @@ import (
 	"github.com/fatih/color"
 	"golang.flu0r1ne.net/planr"
         "fmt"
+        "strings"
 )
 
 var (
@@ -43,31 +44,19 @@ func pprintLabeled(label, value string) {
 }
 
 const (
-  FENCE_WIDTH = 80
+  FENCE_WIDTH = 78
 )
 
 func pprintFenced(title, value string) {
   wingWidth := FENCE_WIDTH - len(title) - 2
+  wing := strings.Repeat("-", wingWidth / 2)
+  fence := strings.Repeat("-", FENCE_WIDTH) 
 
-  for i := 0; i < wingWidth / 2; i++ {
-    fmt.Print("-")
-  }
-
-  fmt.Printf(" %s ", title)
+  fmt.Printf("  %s %s %s\n", wing, title, wing)
   
-  for i := 0; i < wingWidth / 2; i++ {
-    fmt.Print("-")
-  }
-
-  fmt.Println()
-
-  fmt.Print(value)
+  fmt.Print("  " + strings.ReplaceAll(value, "\n", "\n  "))
 
-  for i := 0; i < FENCE_WIDTH; i++ {
-    fmt.Print("-") 
-  }
-  
-  fmt.Println()
+  fmt.Println(fence)
 }
 
 func tcStatusLine(tc planr.TestCase) {
@@ -95,14 +84,24 @@ func tcPprint(tc planr.TestCase) {
     pprintLabeled("description", *tc.Config.Description)
   }
 
-  if tc.Result.DebugOutput != "" {
-    fmt.Println()
-    pprintFenced("compilation output", tc.Result.DebugOutput);
-  }
+  res := tc.Result
+
+  if res.Status == planr.COMPILATION_FAILURE {
+    
+    if res.DebugOutput != "" {
+      fmt.Println()
+      pprintFenced("compilation output", tc.Result.DebugOutput);
+    } else {
+      fmt.Println("WARN: No debug output provided")
+    }
 
-  if tc.Result.FailureMsg != "" {
-    fmt.Println()
-    pprintFenced("test output", tc.Result.FailureMsg);
+  } else if res.Status == planr.RUNTIME_FAILURE {
+
+    if tc.Result.FailureMsg != "" {
+      fmt.Println()
+      pprintFenced("test output", tc.Result.FailureMsg);
+    }
+    
   }
 
   fmt.Println()
@@ -113,7 +112,9 @@ func printResults(passed, tc_total int, earned, points_total float64) {
   
   pprintLabeled("passed", fmt.Sprintf("%d/%d", passed, tc_total));
 
+  percent := earned / points_total * 100
+
   pprintLabeled("score", fmt.Sprintf(
-    "%.2f/%.2f ~= %.1f%%", earned, points_total, earned / points_total * 100,
+    "%.2f/%.2f ~= %.1f%%", earned, points_total, percent,
   ));
 }
-- 
cgit v1.2.3