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 |
|
22 | from utils import * |
23 | from format import * |
24 | from text import * |
25 | from args import * |
26 |
|
27 | class Parser: |
28 | screen = None |
29 | clines = None |
30 | ccols = None |
31 | lines = None |
32 | def __init__(self): |
33 | self.screen = curses_window() |
34 | self.get_size() |
35 |
|
36 | def get_size(self): |
37 | size = term_size() |
38 | self.clines = size[0] |
39 | self.ccols = size[1] |
40 |
|
41 | def redraw(self): |
42 | self.get_size() |
43 | self.lines = self.lines[:self.clines] # limit output line count to screen line count |
44 | curses_clear(self.screen) |
45 | for line_index in range(0, len(self.lines)): |
46 | self.lines[line_index] = str(self.lines[line_index])[:self.ccols] |
47 | output = "\n".join(self.lines) |
48 | self.screen.addstr(output) |
49 | curses_refresh(self.screen) |
50 |
|
51 | def get_input(self): |
52 | input = getch() |
53 | if input == UP: input = "up" |
54 | elif input == DOWN: input = "down" |
55 | elif input == LEFT: input = "left" |
56 | elif input == RIGHT: input = "right" |
57 | else: input = str(input).lower() |
58 | return input |
59 |
|
60 | def loop(self): |
61 | input = None |
62 | while True: |
63 | self.get_size() |
64 | |
65 | screen_width = self.ccols - 1 |
66 | self.lines = [ |
67 | "lognestmonster - log_folder/", |
68 | "Size: 235 bytes | Timestamp: 1565561768719", |
69 | "7 Statements | 2 Events | 0 Unsaved Data Trees", |
70 | pad(" STATEMENT 5 ", ":", screen_width), |
71 | "v 7 ITEMS", |
72 | " 1565561768752 - INFO - INIT - HELLO", |
73 | " 1565561768752 - INFO - INIT - HELLO", |
74 | " v 4 ITEMS", |
75 | " 1565561768752 - INFO - INIT - HELLO", |
76 | " 1565561768752 - INFO - INIT - HELLO", |
77 | "", |
78 | " 1565561768752 - INFO - INIT - HELLO", |
79 | "", |
80 | " 1565561768752 - INFO - INIT - HELLO", |
81 | " 1565561768752 - INFO - INIT - HELLO", |
82 | "", |
83 | "", |
84 | "", |
85 | "", |
86 | "", |
87 | "", |
88 | "", |
89 | "", |
90 | pad(CONTROLS_MESSAGE, ":", screen_width) |
91 | ] |
92 | self.redraw() |
93 |
|
94 | input = self.get_input() |
95 |
|
96 | if input == CTRLC or input == "q": # exit program on Ctrl + C or `q` |
97 | break; |
98 |
|
99 |
|
100 | def argument_parse(argv): |
101 | options = {} |
102 | for key in ARGUMENT_OPTIONS: |
103 | data = ARGUMENT_OPTIONS[key] |
104 | for indicator in data["indicators"]: |
105 | if indicator in argv: |
106 | print(data["description"]) |
107 | return options |
108 |
|
109 | def main(): |
110 | try: |
111 | args = sys.argv |
112 | argument_parse(args) |
113 | #output(VERSION_MESSAGE) |
114 | finally: |
115 | curses_reset() |
116 |
|
117 | if __name__ == "__main__": |
118 | main() |
119 |
|