Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
render-basic won't print off the end of lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Cohen committed Aug 25, 2015
1 parent 2ebc645 commit 72dc4b1
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions render-basic/Render.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Renderer struct {
colWidths *map[string]int
cols *[]string
height int64
width int64
rowsPrinted *int64
}

Expand All @@ -24,28 +25,44 @@ func main() {
out, _ := cmd.Output()
wh := strings.Split(string(out), " ")
hstr := strings.Trim(wh[0], "\n")
rows := int64(0)
wstr := strings.Trim(wh[1], "\n")
height, _ := strconv.ParseInt(hstr, 10, 64)
width, _ := strconv.ParseInt(wstr, 10, 64)

rows := int64(0)
fmt.Println("%v", width)

if len(os.Args) == 2 && os.Args[1] == "noraw" {
util.ConnectToStdIn(Renderer{false, &m, &cols, height, &rows})
util.ConnectToStdIn(Renderer{false, &m, &cols, height, width, &rows})
} else {
util.ConnectToStdIn(Renderer{true, &m, &cols, height, &rows})
util.ConnectToStdIn(Renderer{true, &m, &cols, height, width, &rows})
}
}

func (r Renderer) Process(inp map[string]interface{}) {
if util.IsPlus(inp) {
var printed = false
charsPrinted := int64(0)
colsWidth := render.Columns([]map[string]interface{}{inp})
colNames := render.ColumnNames(colsWidth)
*r.cols = colNames
*r.colWidths = colsWidth
for _, col := range colNames {
v, _ := inp[col]
vStr := fmt.Sprint(v)
spaces := strings.Repeat(" ", (len(col)+3+colsWidth[col])-len(vStr))
fmt.Printf("[%s=%v]%s", col, vStr, spaces)
spaces := strings.Repeat(" ", colsWidth[col]-len(vStr))
finalStr := fmt.Sprintf("[%s=%v]%s", col, vStr, spaces)
if charsPrinted+int64(len(finalStr)) > r.width {
availableChars := r.width - charsPrinted
if availableChars > 3 {
fmt.Printf(finalStr[:availableChars-3])
fmt.Printf("...")
charsPrinted = r.width
}
} else {
charsPrinted += int64(len(finalStr))
fmt.Printf(finalStr)
}
}
if printed {
fmt.Printf(";")
Expand Down

0 comments on commit 72dc4b1

Please sign in to comment.