{{ $error := false -}} {{ if partial "utilities/IsInvalidArgs.html" (dict "structure" "command" "args" .Params) }} {{ errorf "Invalid arguments: %s" .Position -}} {{ $error = true }} {{ end }} {{- $host := .Get "host" | default "" -}} {{- $user := .Get "user" | default "" -}} {{- $prompt := .Get "prompt" | default "" -}} {{- $filter := "(out)" -}} {{- $input := trim .Inner " \t\r\n" -}} {{- $class := .Get "class" | default "" -}} {{- $shell := lower (.Get "shell") | default "bash" -}} {{- $continuationPrompt := ">" -}} {{- $continuationStr := "\\" -}} {{- if eq $shell "powershell" -}} {{- if not $prompt }}{{ $prompt = "PS>" }}{{ end -}} {{- $continuationPrompt = ">>" -}} {{- $continuationStr = "`" -}} {{- else if eq $shell "sql" -}} {{- if not $prompt }}{{ $prompt = "sql>" }}{{ end -}} {{- $continuationPrompt = "->" -}} {{- $continuationStr = "(con)" -}} {{- else -}} {{- $shell = "bash" -}} {{- if not $prompt }}{{ $prompt = "$" }}{{ end -}} {{- if (and ($host) ($user)) -}} {{- $prompt = printf "[%s@%s] %s" $user $host $prompt -}} {{- end -}} {{- end -}} {{ if not $error }} {{- $lines := split $input "\n" -}} {{- $prefix := "" -}} {{- $prevLine := "" -}} {{- $refined := "" -}} {{- range $line := $lines -}} {{- $line = trim $line " \t\r\n" -}} {{- if hasPrefix $line $filter -}} {{- $prefix = printf "%s" $prefix -}} {{- if eq $shell "sql" -}} {{- $line = printf "--%s" (strings.TrimPrefix $filter $line) -}} {{- else -}} {{- $line = printf "#%s" (strings.TrimPrefix $filter $line) -}} {{- end -}} {{- else if (strings.HasSuffix $prevLine $continuationStr) -}} {{- $prefix = printf "%s" $prefix $continuationPrompt -}} {{- else -}} {{- $prefix = printf "%s" $prefix $prompt -}} {{- end -}} {{- $prevLine = $line -}} {{- if (and (eq $shell "sql") (strings.HasSuffix $line $continuationStr)) -}} {{- $line = strings.TrimSuffix $continuationStr $line -}} {{- end -}} {{- $refined = printf "%s\n%s" $refined $line -}} {{- end -}} {{- $refined := trim $refined "\r\n" -}} {{- $output := (transform.Highlight $refined $shell | safeHTML) -}} {{- $insert := printf "%s" $prefix -}} {{- $output := (replace $output ("" | safeHTML) $insert 1 | safeHTML) -}} {{- if eq $shell "sql" -}} {{- $output = (replace $output "--" "" | safeHTML) -}} {{- else -}} {{- $output = (replace $output "#" "" | safeHTML) -}} {{- $output = (replace $output "#" "" | safeHTML) -}} {{- end -}}
{{- $output -}}
{{ end }}