示例#1
0
文件: jqrepl.go 项目: ashb/jqrepl
func makeProgramArgs(history *jq.Jv) *jq.Jv {
	// Create this structure:
	// programArgs = [
	//		{"name": "out", "value": history },
	//    {"name": "_", "value": history[-1] },
	//    {"name": "__", "value": history[-2] },
	// ]

	arg := jq.JvObject().ObjectSet(jvStringName.Copy(), jvStringOut.Copy()).ObjectSet(jvStringValue.Copy(), history.Copy())
	res := jq.JvArray().ArrayAppend(arg)

	len := history.Copy().ArrayLength()

	if len >= 1 {
		arg = jq.JvObject().ObjectSet(jvStringName.Copy(), jvStringUnderscore.Copy()).ObjectSet(jvStringValue.Copy(), history.Copy().ArrayGet(len-1))
		res = res.ArrayAppend(arg)
	}
	if len >= 2 {
		arg = jq.JvObject().ObjectSet(jvStringName.Copy(), jvStringDunderscore.Copy()).ObjectSet(jvStringValue.Copy(), history.Copy().ArrayGet(len-2))
		res = res.ArrayAppend(arg)
	}

	return res
}
示例#2
0
文件: jqrepl.go 项目: ashb/jqrepl
func (repl *JqRepl) Output(o *jq.Jv) {
	fmt.Fprintf(repl.reader.Stdout(), outputTemplate, repl.programCounter, o.Dump(jq.JvPrintPretty|jq.JvPrintSpace1|jq.JvPrintColour))
}