示例#1
0
func (m Merger) Process(inp map[string]interface{}) {
	m.mu.Lock()
	defer m.mu.Unlock()
	if !util.IsStartRelation(inp) && !util.IsEndRelation(inp) {
		m.aggregate[ExtractId(inp)] = inp
	}
}
示例#2
0
func (state RenderState) Process(inp map[string]interface{}) {
	if util.IsStartRelation(inp) {
		newmap := make([]map[string]interface{}, 0)
		*state.Messages = newmap
	} else if util.IsEndRelation(inp) {
		state.Flush()
	} else if util.IsRelation(inp) {
		*state.Messages = append(*state.Messages, inp)
	} else if util.IsMeta(inp) {
		*state.Meta = inp
	} else if util.IsPlus(inp) {
		*state.Messages = append(*state.Messages, inp)
		state.Flush()
	} else {
		// :-( no type information
	}
}
示例#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
	}
}