Example #1
0
func (p Parser) Process(inp map[string]interface{}) {
	if util.IsPlus(inp) {
		matches := p.regex.FindStringSubmatch(util.ExtractRaw(inp))
		if len(matches) == 1+len(p.extractions) {
			for i, match := range matches[1:] {
				inp[p.extractions[i]] = match
			}
			p.output.Write(inp)
		}
	}
}
Example #2
0
func (filt SumoFilter) Process(inp map[string]interface{}) {
	if strings.Contains(util.ExtractRaw(inp), filt.param) {
		filt.output.Write(inp)
	}
}
Example #3
0
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(" ", 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(";")
		}
		if r.showRaw {
			fmt.Printf(util.ExtractRaw(inp))
		}
		fmt.Print("\n")
	}
	if util.IsStartRelation(inp) {
		fmt.Println("======")
		for _, col := range *r.cols {
			width := (*r.colWidths)[col]
			spaces := strings.Repeat(" ", width-len(col))
			fmt.Printf("%v%s", col, spaces)
		}
		*r.rowsPrinted += 2
		fmt.Printf("\n")
	}
	if util.IsRelation(inp) {
		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(" ", colsWidth[col]-len(vStr))
			fmt.Printf("%v%s", vStr, spaces)
		}
		*r.rowsPrinted += 1
		fmt.Printf("\n")
	}

	if util.IsEndRelation(inp) {
		if *r.rowsPrinted < r.height-1 {
			for i := *r.rowsPrinted; i < r.height; i++ {
				fmt.Printf("\n")
			}
		}
		*r.rowsPrinted = 0
	}
}