Use system-native linebreaks.

This commit is contained in:
2025-07-14 10:33:13 -05:00
parent 8b0a684dab
commit 45db33bf9e
2 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "0.2.3"
version = "0.2.4"
author = "Jonathan Bernard"
description = "Small utility to pretty-print strucutured logs."
license = "MIT"

View File

@ -4,7 +4,7 @@ import docopt, timeutils, zero_functional
from std/logging import Level
from std/sequtils import toSeq
const VERSION = "0.2.3"
const VERSION = "0.2.4"
const USAGE = """Usage:
slfmt [options]
@ -64,11 +64,11 @@ proc fullFormatField(name: string, value: JsonNode): string =
let valLines = splitLines(strVal)
if name.len + strVal.len + 6 > terminalWidth() or valLines.len > 1:
result &= "\n" & valLines.mapIt(" " & it).join("\n") & "\n"
else: result &= strVal & "\n"
result &= "\p" & valLines.mapIt(" " & it).join("\p") & "\p"
else: result &= strVal & "\p"
proc fullFormat(logJson: JsonNode): string =
result = '-'.repeat(terminalWidth()) & "\n"
result = '-'.repeat(terminalWidth()) & "\p"
# Print the known fields in order first
for f in fieldDisplayOrder:
@ -79,7 +79,7 @@ proc fullFormat(logJson: JsonNode): string =
# Print the rest of the fields
for (key, val) in pairs(logJson): result &= fullFormatField(key, val)
result &= "\n"
result &= "\p"
proc compactFormat(logJson: JsonNode): string =
let ts = parseIso8601(logJson["ts"].getStr).local.formatIso8601
@ -114,10 +114,10 @@ proc compactFormat(logJson: JsonNode): string =
else: pretty(val)
let field = "$1: $2" % [decorate(key, fgCyan), fieldVal]
if line.len + field.len + 2 > terminalWidth():
result &= "\n " & line
result &= "\p " & line
line = " "
line &= field & " "
result &= "\n " & line
result &= "\p " & line
proc parseLogLine(logLine: string): JsonNode =
result = parseJson(logLine)