Update for Nim 1.x+.

This commit is contained in:
Jonathan Bernard 2021-06-07 21:57:46 -05:00
parent 3a745ac98f
commit 86bccbc81d
4 changed files with 28 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.*.sw?
log_happy
nimcache/

View File

@ -2,13 +2,11 @@
## =========
##
## Little tool to extract expected information from log streams.
import json, logging, ncurses, os, osproc, sequtils, streams, strutils, threadpool
import json, ncurses, os, osproc, sequtils, streams, strutils, threadpool
import nre except toSeq
import private/ncurses_ext
from posix import signal
type
Expectation* = ref object
label: string
@ -35,7 +33,7 @@ when isMainModule:
var outFile: File
try:
let VERSION = "0.2.0"
let VERSION = "0.2.1"
let usage = """
Usage:
log_happy [options]
@ -76,7 +74,7 @@ Expectations JSON definitions follow this format:
let args = commandLineParams()
var expectations: seq[Expectation] = @[]
var follow = false
var follow = false
var cmd = "NOCMD"
if args.len == 0:
@ -113,7 +111,7 @@ Expectations JSON definitions follow this format:
elif arg.startsWith("-i"):
let filename = arg[2..^1]
try:
if not existsFile(filename):
if not fileExists(filename):
exitErr "no such file (" & filename & ")"
inStream = newFileStream(filename)
@ -128,7 +126,7 @@ Expectations JSON definitions follow this format:
except:
exitErr "could not open output file in write mode (" & filename &
"):\n\t" & getCurrentExceptionMsg()
elif arg.match(expPattern).isSome:
var m = arg.match(expPattern).get().captures()
expectations.add(Expectation(
@ -148,7 +146,7 @@ Expectations JSON definitions follow this format:
elif arg == "-f": follow = true
elif arg == "--": cmd = ""
else: exitErr "unrecognized argument: " & arg
if cmd == "NOCMD" and inStream.isNil:
exitErr "no input file or command to execute."
@ -161,7 +159,7 @@ Expectations JSON definitions follow this format:
# Init ncurses
let stdscr = initscr()
var height, width: int
var height, width: cint
getmaxyx(stdscr, height, width)
startColor()
@ -230,7 +228,7 @@ Expectations JSON definitions follow this format:
dispwin.wrefresh()
firstPass = false
logwin.wprintw("\n" & line)
logwin.wrefresh()

View File

@ -1,6 +1,6 @@
# Package
version = "0.2.0"
version = "0.2.1"
author = "Jonathan Bernard"
description = "Scan logs for regex-defined events and report on what was found."
license = "MIT"
@ -9,4 +9,3 @@ bin = @["log_happy"]
# Dependencies
requires @["nim >= 0.16.1", "docopt >= 0.6.4", "ncurses"]

View File

@ -1,31 +1,31 @@
import ncurses
export ncurses
proc keypad*(win: ptr window, enable: bool): int {.cdecl, discardable, importc: "keypad", dynlib: libncurses.}
proc scrollok*(win: ptr window, enable: bool): int {.cdecl, discardable, importc: "scrollok", dynlib: libncurses.}
proc nodelay*(win: ptr window, enable: bool): int {.cdecl, discardable, importc: "nodelay", dynlib: libncurses.}
proc nonl*(): int {.cdecl, discardable, importc: "nonl", dynlib: libncurses.}
#proc keypad*(win: PWindow, enable: bool): int {.cdecl, discardable, importc: "keypad", dynlib: libncurses.}
#proc scrollok*(win: PWindow, enable: bool): int {.cdecl, discardable, importc: "scrollok", dynlib: libncurses.}
#proc nodelay*(win: PWindow, enable: bool): int {.cdecl, discardable, importc: "nodelay", dynlib: libncurses.}
#proc nonl*(): int {.cdecl, discardable, importc: "nonl", dynlib: libncurses.}
proc newwin*(num_rows, num_cols, begin_x, begin_y: int): ptr window {.cdecl, discardable, importc: "newwin", dynlib: libncurses.}
proc delwin*(win: ptr window): int {.cdecl, discardable, importc: "delwin", dynlib: libncurses.}
#proc newwin(num_rows, num_cols, begin_x, begin_y: int): ptr window {.cdecl, discardable, importc: "newwin", dynlib: libncurses.}
proc newwin*(num_rows, num_cols, begin_x, begin_y: int): PWindow {.cdecl, discardable, importc: "newwin", dynlib: libncurses.}
proc delwin*(win: PWindow): int {.cdecl, discardable, importc: "delwin", dynlib: libncurses.}
#proc newwin(num_rows, num_cols, begin_x, begin_y: int): PWindow {.cdecl, discardable, importc: "newwin", dynlib: libncurses.}
#proc wgetch*(win: ptr window): int {.cdecl, discardable, importc: "wgetch", dynlib: libncurses.}
proc wrefresh*(win: ptr window): int {.cdecl, discardable, importc: "wrefresh", dynlib: libncurses.}
proc wclear*(win: ptr window): int {.cdecl, discardable, importc: "wclear", dynlib: libncurses.}
proc mvwhline*(win: ptr window, rol, col: int, chType: char, n: int): int {.cdecl, discardable, importc: "whline", dynlib: libncurses.}
proc wmove*(win: ptr window, rol, col: int): int {.cdecl, discardable, importc: "wmove", dynlib: libncurses.}
proc wprintw*(win: ptr window, str: cstring): int {.cdecl, discardable, importc: "wprintw", dynlib: libncurses.}
#proc mvwprintw*(win: ptr window, row, col: int, str: cstring): int {.cdecl, discardable, importc: "mvwprintw", dynlib: libncurses.}
#proc wgetch*(win: PWindow): int {.cdecl, discardable, importc: "wgetch", dynlib: libncurses.}
#proc wrefresh*(win: PWindow): int {.cdecl, discardable, importc: "wrefresh", dynlib: libncurses.}
proc wclear*(win: PWindow): int {.cdecl, discardable, importc: "wclear", dynlib: libncurses.}
proc mvwhline*(win: PWindow, rol, col: int, chType: char, n: int): int {.cdecl, discardable, importc: "whline", dynlib: libncurses.}
proc wmove*(win: PWindow, rol, col: int): int {.cdecl, discardable, importc: "wmove", dynlib: libncurses.}
#proc wprintw*(win: PWindow, str: cstring): int {.cdecl, discardable, importc: "wprintw", dynlib: libncurses.}
#proc mvwprintw*(win: PWindow, row, col: int, str: cstring): int {.cdecl, discardable, importc: "mvwprintw", dynlib: libncurses.}
proc box*(win: ptr window, vert_border, horiz_border: char): int {.cdecl, discardable, importc: "box", dynlib: libncurses.}
proc wborder*(win: ptr window, ls,rs,ts,bs,tl,tr,bl,br: char): int {.cdecl, discardable, importc: "wborder", dynlib: libncurses.}
proc box*(win: PWindow, vert_border, horiz_border: char): int {.cdecl, discardable, importc: "box", dynlib: libncurses.}
proc wborder*(win: PWindow, ls,rs,ts,bs,tl,tr,bl,br: char): int {.cdecl, discardable, importc: "wborder", dynlib: libncurses.}
proc init_pair*(n, f, b: int): int {.cdecl, discardable, importc: "init_pair", dynlib: libncurses.}
proc COLOR_PAIR*(n: int): int {.cdecl, discardable, importc: "COLOR_PAIR", dynlib: libncurses.}
proc wattron*(win: ptr window, attrs: int): int {.cdecl, discardable, importc: "wattron", dynlib: libncurses.}
proc wattroff*(win: ptr window, attrs: int): int {.cdecl, discardable, importc: "wattron", dynlib: libncurses.}
proc wattron*(win: PWindow, attrs: int): int {.cdecl, discardable, importc: "wattron", dynlib: libncurses.}
proc wattroff*(win: PWindow, attrs: int): int {.cdecl, discardable, importc: "wattron", dynlib: libncurses.}
const BLACK* = 0
const RED* = 1
@ -35,5 +35,3 @@ const BLUE* = 4
const MAGENTA* = 5
const CYAN* = 6
const WHITE* = 7