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 Stockin11036N

Blob @ lognestmonster / parser / parse.py

application/x-python2833 bytesdownload raw
1#!/usr/bin/env python3
2
3# lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
4# <https://github.com/JoshuaS3/lognestmonster/>.
5
6
7# This file is part of lognestmonster.
8
9# lognestmonster is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13
14# lognestmonster is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18
19# You should have received a copy of the GNU General Public License
20# along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.
21
22from utils import *
23from format import *
24from text import *
25
26class Parser:
27 screen = None
28 clines = None
29 ccols = None
30 lines = None
31 def __init__(self):
32 self.screen = curses_window()
33 self.get_size()
34
35 def get_size(self):
36 size = term_size()
37 self.clines = size[0]
38 self.ccols = size[1]
39
40 def redraw(self):
41 self.get_size()
42 self.lines = self.lines[:self.clines] # limit output line count to screen line count
43 curses_clear(self.screen)
44 for line_index in range(0, len(self.lines)):
45 self.lines[line_index] = str(self.lines[line_index])[:self.ccols]
46 output = "\n".join(self.lines)
47 self.screen.addstr(output)
48 curses_refresh(self.screen)
49
50 def get_input(self):
51 input = getch()
52 if input == UP: input = "up"
53 elif input == DOWN: input = "down"
54 elif input == LEFT: input = "left"
55 elif input == RIGHT: input = "right"
56 else: input = str(input).lower()
57 return input
58
59 def loop(self):
60 input = None
61 while True:
62 self.get_size()
63
64 screen_width = self.ccols - 1
65 self.lines = [
66 "lognestmonster - log_folder/",
67 "Size: 9,608,560 bytes | Timestamp: 1565561768719",
68 "192,000 Statements | 4,820 Events | 18 Unsaved Data Trees",
69 pad(" STATEMENT 17 ", ":", screen_width),
70 "v 4 ITEMS",
71 " 1565561768752 - INFO - INIT - HELLO",
72 " 1565561768752 - INFO - INIT - HELLO",
73 " v 4 ITEMS",
74 " 1565561768752 - INFO - INIT - HELLO",
75 " 1565561768752 - INFO - INIT - HELLO",
76 "",
77 " 1565561768752 - INFO - INIT - HELLO",
78 "",
79 " 1565561768752 - INFO - INIT - HELLO",
80 " 1565561768752 - INFO - INIT - HELLO",
81 "",
82 "",
83 "",
84 "",
85 "",
86 pad(CONTROLS_MESSAGE, ":", screen_width)
87 ]
88 self.redraw()
89
90 input = self.get_input()
91
92 if input == CTRLC or input == "q": # exit program on Ctrl + C or `q`
93 break;
94
95
96def argument_parse(argv):
97 pass
98
99def main():
100 try:
101 args = sys.argv
102 if ("-v" in args):
103 output(VERSION_MESSAGE)
104 else:
105 Parser().loop()
106 finally:
107 curses_reset()
108
109if __name__ == "__main__":
110 main()
111