Exemplo n.º 1
0
func mustSaveHistory(o *term.TextOutput, historyFilename string) {
	if verboseMode {
		fmt.Printf(o.LightBlue("Saving REPL history to %s... "), historyFilename)
	}
	if err := saveHistory(historyFilename); err != nil {
		if verboseMode {
			fmt.Println(o.DarkRed("failed: " + err.Error()))
		} else {
			fmt.Printf(o.DarkRed("Failed to store REPL history to %s: %s\n"), historyFilename, err)
		}
	} else if verboseMode {
		fmt.Println(o.LightGreen("ok"))
	}
}
Exemplo n.º 2
0
// Syntax highlight the given line
func highlight(o *term.TextOutput, line string) string {
	unprocessed := line
	unprocessed, comment := colorSplit(unprocessed, "//", nil, o.DarkGray, o.DarkGray, false)
	module, unprocessed := colorSplit(unprocessed, ":", o.LightGreen, o.DarkRed, nil, true)
	function := ""
	if unprocessed != "" {
		// Green function names
		if strings.Contains(unprocessed, "(") {
			fields := strings.SplitN(unprocessed, "(", 2)
			function = o.LightGreen(fields[0])
			unprocessed = "(" + fields[1]
		}
	}
	unprocessed, typed := colorSplit(unprocessed, "->", nil, o.LightBlue, o.DarkRed, false)
	unprocessed = strings.Replace(unprocessed, "string", o.LightBlue("string"), -1)
	unprocessed = strings.Replace(unprocessed, "number", o.LightYellow("number"), -1)
	unprocessed = strings.Replace(unprocessed, "function", o.LightCyan("function"), -1)
	return module + function + unprocessed + typed + comment
}