{{/* Copyright © 2022 - 2025 The Hinode Team / Mark Dumay. All rights reserved. Use of this source code is governed by The MIT License (MIT) that can be found in the LICENSE file. Visit gethinode.com/license for more details. */}} {{ $symbols := dict "bash" (dict "prompt" "$" "contPrompt" ">" "contString" "\\") "powershell" (dict "prompt" "PS>" "contPrompt" ">>" "contString" "`") "sql" (dict "prompt" "sql>" "contPrompt" "->" "contString" "(con)") }} {{/* Initialize arguments */}} {{- $args := partial "utilities/InitArgs.html" (dict "structure" "command" "args" .Params "named" .IsNamedParams "group" "shortcode") -}} {{- if or $args.err $args.warnmsg -}} {{- partial (cond $args.err "utilities/LogErr.html" "utilities/LogWarn.html") (dict "partial" "shortcodes/command.html" "msg" "Invalid arguments" "details" ($args.errmsg | append $args.warnmsg) "file" page.File "position" .Position )}} {{- end -}} {{/* Initialize local arguments */}} {{- $prompt := $args.prompt | default (index (index $symbols $args.shell) "prompt") -}} {{- $contPrompt := index (index $symbols $args.shell) "contPrompt" -}} {{- $contString := index (index $symbols $args.shell) "contString" -}} {{- $filter := "(out)" -}} {{- $input := trim .Inner " \t\r\n" -}} {{- if (and (eq $args.shell "bash") $args.host $args.user) -}} {{- $prompt = printf "[%s@%s] %s" $args.user $args.host $prompt -}} {{- end -}} {{/* Main code */}} {{ if not $args.err }} {{- $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 $args.shell "sql" -}} {{- $line = printf "--%s" (strings.TrimPrefix $filter $line) -}} {{- else -}} {{- $line = printf "#%s" (strings.TrimPrefix $filter $line) -}} {{- end -}} {{- else if (strings.HasSuffix $prevLine $contString) -}} {{- $prefix = printf "%s" $prefix $contPrompt -}} {{- else -}} {{- $prefix = printf "%s" $prefix $prompt -}} {{- end -}} {{- $prevLine = $line -}} {{- if (and (eq $args.shell "sql") (strings.HasSuffix $line $contString)) -}} {{- $line = strings.TrimSuffix $contString $line -}} {{- end -}} {{- $refined = printf "%s\n%s" $refined $line -}} {{- end -}} {{- $refined := trim $refined "\r\n" -}} {{- $output := (transform.Highlight $refined $args.shell | safeHTML) -}} {{- $insert := printf "%s" $prefix -}} {{- $output := (replace $output ("" | safeHTML) $insert 1 | safeHTML) -}} {{- if eq $args.shell "sql" -}} {{- $output = (replace $output "--" "" | safeHTML) -}} {{- else -}} {{- $output = (replace $output "#" "" | safeHTML) -}} {{- $output = (replace $output "#" "" | safeHTML) -}} {{- end -}}
{{- $output -}}
{{ end }}