1 Commits

Author SHA1 Message Date
65a5d026e1 WIP: Refactor for Nim 2.x 2025-12-16 15:13:00 -06:00
2 changed files with 21 additions and 9 deletions

View File

@@ -2,8 +2,9 @@
## ========= ## =========
## ##
## Little tool to extract expected information from log streams. ## Little tool to extract expected information from log streams.
import json, logging, ncurses, os, osproc, sequtils, streams, strutils, threadpool import std/[json, logging, os, osproc, sequtils, streams, strutils]
import nre except toSeq import std/nre except toSeq
import docopt, malebolgia, ncurses
import private/ncurses_ext import private/ncurses_ext
@@ -15,6 +16,16 @@ type
pattern: Regex pattern: Regex
expected, found: bool expected, found: bool
SourceKind = enum skStdIn, skFile, skCmd
InSource = object
case kind: SourceKind
of skStdIn:
discard
of skFile:
filename: string
of skCmd:
cmdInvocation: string
let expPattern = re"^-([eE])([^;]+);(.+)$" let expPattern = re"^-([eE])([^;]+);(.+)$"
var msgChannel: Channel[string] var msgChannel: Channel[string]
@@ -24,15 +35,16 @@ proc exitErr(msg: string): void =
quit(QuitFailure) quit(QuitFailure)
proc readStream(stream: Stream): void = proc readStream(stream: Stream): void =
var line = TaintedString"" var line: string
try: try:
while stream.readLine(line): msgChannel.send(line) while stream.readLine(line): msgChannel.send(line)
except: discard "" except: discard ""
when isMainModule: when isMainModule:
var cmdProc: Process var cmdProc: Process
var inStream: Stream var source = InSource(kind: skStdIn)
var outFile: File var outFile: File
var threadMaster = createMaster()
try: try:
let VERSION = "0.2.0" let VERSION = "0.2.0"
@@ -113,10 +125,10 @@ Expectations JSON definitions follow this format:
elif arg.startsWith("-i"): elif arg.startsWith("-i"):
let filename = arg[2..^1] let filename = arg[2..^1]
try: try:
if not existsFile(filename): if not fileExists(filename):
exitErr "no such file (" & filename & ")" exitErr "no such file (" & filename & ")"
inStream = newFileStream(filename) source = InSource(kind: skFile, filename: filename)
except: except:
exitErr "could not open file (" & filename & "):\t\n" & exitErr "could not open file (" & filename & "):\t\n" &
getCurrentExceptionMsg() getCurrentExceptionMsg()
@@ -157,7 +169,7 @@ Expectations JSON definitions follow this format:
inStream = cmdProc.outputStream inStream = cmdProc.outputStream
open(msgChannel) open(msgChannel)
spawn readStream(inStream) threadMaster.spawn readStream(inStream)
# Init ncurses # Init ncurses
let stdscr = initscr() let stdscr = initscr()
@@ -272,5 +284,6 @@ Expectations JSON definitions follow this format:
if not inStream.isNil: close(inStream) if not inStream.isNil: close(inStream)
if not outFile.isNil: close(outFile) if not outFile.isNil: close(outFile)
threadMaster.cancel()
close(msgChannel) close(msgChannel)
endwin() endwin()

View File

@@ -8,5 +8,4 @@ bin = @["log_happy"]
# Dependencies # Dependencies
requires @["nim >= 0.16.1", "docopt >= 0.6.4", "ncurses"] requires @["nim >= 0.16.1", "docopt >= 0.6.4", "ncurses", "malebolgia >= 1.3.2"]