From 83dae4a87a78190262317eca15cbb5d25989d41b Mon Sep 17 00:00:00 2001 From: bptato Date: Fri, 26 Apr 2024 19:20:52 +0200 Subject: adapter: update code style --- adapter/format/ansi2html.nim | 36 +++++++++++++----------------------- adapter/format/md2html.nim | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 34 deletions(-) (limited to 'adapter/format') diff --git a/adapter/format/ansi2html.nim b/adapter/format/ansi2html.nim index 49f24d87..dcbc4210 100644 --- a/adapter/format/ansi2html.nim +++ b/adapter/format/ansi2html.nim @@ -31,7 +31,7 @@ type state: AnsiCodeParseState params: string -proc getParam(parser: AnsiCodeParser, i: var int, colon = false): string = +proc getParam(parser: AnsiCodeParser; i: var int; colon = false): string = while i < parser.params.len and not (parser.params[i] == ';' or colon and parser.params[i] == ':'): result &= parser.params[i] @@ -39,8 +39,7 @@ proc getParam(parser: AnsiCodeParser, i: var int, colon = false): string = if i < parser.params.len: inc i -template getParamU8(parser: AnsiCodeParser, i: var int, - colon = false): uint8 = +template getParamU8(parser: AnsiCodeParser; i: var int; colon = false): uint8 = if i >= parser.params.len: return false let u = parseUInt8(parser.getParam(i), allowSign = false) @@ -48,8 +47,8 @@ template getParamU8(parser: AnsiCodeParser, i: var int, return false u.get -proc parseSGRDefColor(parser: AnsiCodeParser, format: var Format, - i: var int, isfg: bool): bool = +proc parseSGRDefColor(parser: AnsiCodeParser; format: var Format; + i: var int; isfg: bool): bool = let u = parser.getParamU8(i, colon = true) template set_color(c: CellColor) = if isfg: @@ -74,8 +73,8 @@ proc parseSGRDefColor(parser: AnsiCodeParser, format: var Format, else: return false -proc parseSGRColor(parser: AnsiCodeParser, format: var Format, - i: var int, u: uint8): bool = +proc parseSGRColor(parser: AnsiCodeParser; format: var Format; + i: var int; u: uint8): bool = if u in 30u8..37u8: format.fgcolor = cellColor(ANSIColor(u - 30)) elif u == 38: @@ -106,7 +105,7 @@ const FormatCodes: array[FormatFlag, tuple[s, e: uint8]] = [ ffBlink: (5u8, 25u8), ] -proc parseSGRAspect(parser: AnsiCodeParser, format: var Format, +proc parseSGRAspect(parser: AnsiCodeParser; format: var Format; i: var int): bool = let u = parser.getParamU8(i) for flag, (s, e) in FormatCodes: @@ -122,7 +121,7 @@ proc parseSGRAspect(parser: AnsiCodeParser, format: var Format, else: return parser.parseSGRColor(format, i, u) -proc parseSGR(parser: AnsiCodeParser, format: var Format) = +proc parseSGR(parser: AnsiCodeParser; format: var Format) = if parser.params.len == 0: format = Format() else: @@ -131,7 +130,7 @@ proc parseSGR(parser: AnsiCodeParser, format: var Format) = if not parser.parseSGRAspect(format, i): break -proc parseControlFunction(parser: var AnsiCodeParser, format: var Format, +proc parseControlFunction(parser: var AnsiCodeParser; format: var Format; f: char) = if f == 'm': parser.parseSGR(format) @@ -161,26 +160,17 @@ proc flushOutbuf(state: var State) = discard write(STDOUT_FILENO, addr state.outbuf[0], state.outbufIdx) state.outbufIdx = 0 -proc putc(state: var State, c: char) {.inline.} = +proc putc(state: var State; c: char) {.inline.} = if state.outbufIdx + 4 >= state.outbuf.len: # max utf-8 char length state.flushOutbuf() state.outbuf[state.outbufIdx] = c inc state.outbufIdx -proc puts(state: var State, s: string) = +proc puts(state: var State; s: openArray[char]) {.inline.} = #TODO this is slower than it could be for c in s: state.putc(c) -proc puts(state: var State, s: openArray[char]) = - #TODO this is slower than it could be - for c in s: - state.putc(c) - -proc puts(state: var State, s: static string) {.inline.} = - for c in s: - state.putc(c) - proc flushFmt(state: var State) = if state.pendingFmt != state.currentFmt: if state.spanOpen: @@ -232,7 +222,7 @@ proc flushFmt(state: var State) = type ParseAnsiCodeResult = enum pacrProcess, pacrSkip -proc parseAnsiCode(state: var State, format: var Format, c: char): +proc parseAnsiCode(state: var State; format: var Format; c: char): ParseAnsiCodeResult = case state.parser.state of acpsStart: @@ -338,7 +328,7 @@ proc parseAnsiCode(state: var State, format: var Format, c: char): state.flushFmt() pacrSkip -proc processData(state: var State, buf: openArray[char]) = +proc processData(state: var State; buf: openArray[char]) = for c in buf: if state.parser.state != acpsDone: case state.parseAnsiCode(state.pendingFmt, c) diff --git a/adapter/format/md2html.nim b/adapter/format/md2html.nim index b14de97d..dcc0d495 100644 --- a/adapter/format/md2html.nim +++ b/adapter/format/md2html.nim @@ -217,7 +217,7 @@ proc parseHash(line: openArray[char]): bool = type ListType = enum ltOl, ltUl -proc getListDepth(line: string): tuple[depth, len: int, ol: ListType] = +proc getListDepth(line: string): tuple[depth, len: int; ol: ListType] = var depth = 0 for i, c in line: if c == '\t': @@ -286,7 +286,7 @@ type reprocess: bool numPreLines: int -proc pushList(state: var ParseState, t: ListType) = +proc pushList(state: var ParseState; t: ListType) = case t of ltOl: stdout.write("
    \n
  1. ") of ltUl: stdout.write("
      \n
    • ") @@ -297,7 +297,7 @@ proc popList(state: var ParseState) = of ltOl: stdout.write("
\n") of ltUl: stdout.write("\n") -proc parseNone(state: var ParseState, line: string) = +proc parseNone(state: var ParseState; line: string) = if line == "": discard elif line[0] == '#' and line.toOpenArray(1, line.high).parseHash(): @@ -337,14 +337,14 @@ proc parseNone(state: var ParseState, line: string) = stdout.write("

\n") state.reprocess = true -proc parsePre(state: var ParseState, line: string) = +proc parsePre(state: var ParseState; line: string) = if line.startsWith("```"): state.blockType = btNone stdout.write("\n") else: stdout.write(line & "\n") -proc parseList(state: var ParseState, line: string) = +proc parseList(state: var ParseState; line: string) = if line == "": state.blockData.parseInline() state.blockData = "" @@ -367,7 +367,7 @@ proc parseList(state: var ParseState, line: string) = else: state.blockData &= line & "\n" -proc parsePar(state: var ParseState, line: string) = +proc parsePar(state: var ParseState; line: string) = if line == "": state.blockData.parseInline() state.blockData = "" @@ -389,7 +389,7 @@ proc parsePar(state: var ParseState, line: string) = else: state.blockData &= line & "\n" -proc parseHTML(state: var ParseState, line: string) = +proc parseHTML(state: var ParseState; line: string) = if state.hasp: state.hasp = false stdout.write("

\n") @@ -400,7 +400,7 @@ proc parseHTML(state: var ParseState, line: string) = else: state.blockData &= line & "\n" -proc parseHTMLPre(state: var ParseState, line: string) = +proc parseHTMLPre(state: var ParseState; line: string) = if state.hasp: state.hasp = false stdout.write("

\n") @@ -411,7 +411,7 @@ proc parseHTMLPre(state: var ParseState, line: string) = else: state.blockData &= line & "\n" -proc parseTabPre(state: var ParseState, line: string) = +proc parseTabPre(state: var ParseState; line: string) = if line.len == 0: inc state.numPreLines elif line[0] != '\t': @@ -427,7 +427,7 @@ proc parseTabPre(state: var ParseState, line: string) = dec state.numPreLines state.blockData &= line.substr(1) & "\n" -proc parseSpacePre(state: var ParseState, line: string) = +proc parseSpacePre(state: var ParseState; line: string) = if line.len == 0: inc state.numPreLines elif not line.startsWith(" "): @@ -443,7 +443,7 @@ proc parseSpacePre(state: var ParseState, line: string) = dec state.numPreLines state.blockData &= line.substr(4) & "\n" -proc parseComment(state: var ParseState, line: string) = +proc parseComment(state: var ParseState; line: string) = let i = line.find("-->") if i != -1: stdout.write(line.substr(0, i + 2)) -- cgit 1.4.1-2-gfad0