1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Add warning for empty grid values (#741)

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer 2019-11-09 15:13:30 -08:00 committed by GitHub
parent b2093314f0
commit 251e3fe10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,13 +3,16 @@ package utils
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"github.com/logrusorgru/aurora"
"github.com/olebedev/config"
)
@ -137,6 +140,12 @@ func CalculateDimensions(moduleConfig, globalConfig *config.Config) (int, int, e
cols := ToInts(grid.UList("columns"))
rows := ToInts(grid.UList("rows"))
// If they're defined in the config, they cannot be empty
if len(cols) == 0 || len(rows) == 0 {
displayGridConfigError()
os.Exit(1)
}
// Read the source data from the config
left := moduleConfig.UInt("position.left", 0)
top := moduleConfig.UInt("position.top", 0)
@ -196,3 +205,19 @@ func Clamp(x, a, b int) int {
}
return x
}
/* -------------------- Unexported Functions -------------------- */
func displayGridConfigError() {
fmt.Printf("\n%s 'grid' config values are invalid. 'columns' and 'rows' cannot be empty.\n", aurora.Red("ERROR"))
fmt.Println()
fmt.Println("This is invalid:")
fmt.Println()
fmt.Println(" grid:")
fmt.Println(" columns: []")
fmt.Println(" rows: []")
fmt.Println()
fmt.Printf("%s If you want the columns and rows to be dynamically-determined, remove the 'grid' key and child keys from your config file.\n", aurora.Yellow("*"))
fmt.Printf("%s If you want explicit widths and heights, add integer values to the 'columns' and 'rows' arrays.\n", aurora.Yellow("*"))
fmt.Println()
}