Index

lognestmonster / 0218510

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
6915 Aug 2019 19:440218510Parsing updatesJosh Stockin19219N

Blob @ lognestmonster / parser / utils.py

application/x-python2490 bytesdownload raw
1# lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
2# <https://github.com/JoshuaS3/lognestmonster/>.
3
4
5# This file is part of lognestmonster.
6
7# lognestmonster is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11
12# lognestmonster is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.
19
20
21# get character from stdin
22
23import termios, sys, tty
24def getch():
25 fd = sys.stdin.fileno()
26 old_settings = termios.tcgetattr(fd)
27 try:
28 tty.setraw(fd)
29 buf = sys.stdin.read(1)
30 if buf == b"\x1b": # if escaped
31 while True:
32 ch = sys.stdin.read(1)
33 buf += ch
34 if ch.isalpha():
35 break
36 finally:
37 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
38 return buf
39
40# command
41
42import subprocess
43def command(*args):
44 cmd_string = ""
45 for i in args:
46 cmd_string += i + " "
47 cmd_string.rstrip()
48 cmd_array = cmd_string.split(" ")
49 readable = subprocess.Popen(cmd_array, stdout=subprocess.PIPE)
50 return readable.stdout.read().decode("latin-1").strip()
51
52# array to string
53
54def array_stringify(array):
55 index = 0
56 for i in array:
57 array[index] = str(i)
58 index += 1
59 return array
60
61# echo output
62
63import sys
64def output(*array):
65 array = array_stringify(list(array))
66 s = "".join(array)
67 sys.stdout.write(s.rstrip() + "\n")
68
69def output_lines(array):
70 for line in array:
71 output(line)
72
73# terminfo stuff
74
75def term_size():
76 lines = int(command("tput lines"))
77 cols = int(command("tput cols"))
78 return (lines, cols)
79
80# drawing
81
82import curses
83def curses_window():
84 # init curses
85 curses.initscr()
86 curses.start_color()
87
88 # get screen size and create new window
89 screen_size = term_size()
90 screen = curses.newwin(screen_size[0], screen_size[1], 0, 0)
91
92 # set cursor visibility to 0
93 curses.curs_set(0)
94
95 # set new window to current
96 curses_refresh(screen)
97
98 return screen
99
100def curses_clear(screen):
101 screen.clear()
102 screen.touchwin()
103 curses_refresh(screen)
104
105def curses_refresh(screen):
106 screen.refresh()
107
108def curses_reset():
109 try:
110 if not curses.isendwin():
111 curses.endwin()
112 except:
113 pass
114