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 | curses_clear(self.screen) |
44 | l = 0 |
45 | for line in self.lines: |
46 | if l == self.clines: break |
47 | self.screen.move(l, 0) |
48 | s = "" |
49 | for string in line: |
50 | content = string[0] |
51 | s += content |
52 |
|
53 | self.screen.attrset(0) |
54 |
|
55 | try: |
56 | attr = string[1] |
57 | except: |
58 | attr = "" |
59 |
|
60 | if "RESET" in attr: |
61 | self.screen.attron(curses.color_pair(0)) |
62 | else: |
63 | if "BLACK" in attr: |
64 | self.screen.attron(curses.color_pair(1)) |
65 | if "BLUE" in attr: |
66 | self.screen.attron(curses.color_pair(2)) |
67 | if "CYAN" in attr: |
68 | self.screen.attron(curses.color_pair(3)) |
69 | if "GREEN" in attr: |
70 | self.screen.attron(curses.color_pair(4)) |
71 | if "MAGENTA" in attr: |
72 | self.screen.attron(curses.color_pair(5)) |
73 | if "RED" in attr: |
74 | self.screen.attron(curses.color_pair(6)) |
75 | if "WHITE" in attr: |
76 | self.screen.attron(curses.color_pair(7)) |
77 | if "YELLOW" in attr: |
78 | self.screen.attron(curses.color_pair(8)) |
79 | if "BOLD" in attr: |
80 | self.screen.attron(curses.A_BOLD) |
81 | if "STANDOUT" in attr: |
82 | self.screen.attron(curses.A_STANDOUT) |
83 | if "UNDERLINE" in attr: |
84 | self.screen.attron(curses.A_UNDERLINE) |
85 |
|
86 | self.screen.addstr(content[:self.ccols - len(s)]) |
87 | self.screen.attrset(0) |
88 | l += 1 |
89 | curses_refresh(self.screen) |
90 |
|
91 | def get_input(self): |
92 | input = getch() |
93 | if input == UP: input = "up" |
94 | elif input == DOWN: input = "down" |
95 | elif input == LEFT: input = "left" |
96 | elif input == RIGHT: input = "right" |
97 | elif input == CTRLC: input = "exit" |
98 | else: input = str(input).lower() |
99 | return input |
100 |
|
101 | folder_name = "log_1565561768719" |
102 | divider = " | " |
103 | title = TITLE |
104 |
|
105 | def loop(self): |
106 | def tab(string, count=1): |
107 | return " "*count + string |
108 | input = None |
109 | try: |
110 | while True: |
111 | self.get_size() |
112 | screen_width = self.ccols - 2 |
113 |
|
114 | self.lines = [ |
115 | [(self.title + " - ", "RESET"), (self.folder_name, "BOLD YELLOW")], |
116 | "Size: 235 bytes | Timestamp: 1565561768719", |
117 | [("7 Statements | 2 Events | 0 Unsaved Data Trees", "")], |
118 | pad(" STATEMENT 5 ", ":", screen_width), |
119 | "v 7 ITEMS", |
120 | tab("1565561768752 - INFO - INIT - HELLO"), |
121 | tab("1565561768752 - INFO - INIT - HELLO"), |
122 | tab("v 4 ITEMS"), |
123 | tab("1565561768752 - INFO - INIT - HELLO", 2), |
124 | tab("1565561768752 - INFO - INIT - HELLO", 2), |
125 | "", |
126 | [(tab("", 2), "RESET"), ("1565561768752 - INFO - INIT - HELLO", "BOLD")], |
127 | "", |
128 | tab("1565561768752 - INFO - INIT - HELLO", 2), |
129 | tab("1565561768752 - INFO - INIT - HELLO"), |
130 | "", |
131 | str(input), |
132 | "", |
133 | "", |
134 | "", |
135 | "", |
136 | "", |
137 | "", |
138 | pad(margin(CONTROLS_MESSAGE), ":", screen_width) |
139 | ] |
140 | self.redraw() |
141 |
|
142 | input = self.get_input() |
143 |
|
144 | if input == "exit" or input == "q": # exit program on Ctrl + C or `q` |
145 | break; |
146 | finally: |
147 | curses_reset() |
148 |
|
149 | def main(): |
150 | options = []#argument_parse(sys.argv) |
151 |
|
152 | display_help = "help" in options |
153 | display_version = True#"version" in options |
154 | is_status = "status" in options |
155 |
|
156 | screen_size = term_size() |
157 | clines = screen_size[0] |
158 | ccols = screen_size[1] - 2 |
159 |
|
160 | if display_help: |
161 | output_lines(VERSION_SHORT) |
162 |
|
163 | usage = [] |
164 | line = "usage: lognestmonster " |
165 | x = len(line) |
166 | width = ccols - x |
167 | wrapped = wrap(USAGE_MESSAGE, width, "&") |
168 | for l in wrapped: |
169 | line += l |
170 | usage.append(line) |
171 | line = (" "*x) |
172 | output_lines(usage) |
173 |
|
174 | output() |
175 |
|
176 | for paragraph in COMMAND_INFO.split("\n\n"): |
177 | output_lines(wrap(paragraph, ccols)) |
178 |
|
179 | output() |
180 |
|
181 | args = [] |
182 |
|
183 | div1 = ccols/3 |
184 | div2 = ccols/3*2 |
185 | for arg in ARGUMENT_OPTIONS: |
186 | arg_lines = [] |
187 | indicators = wrap(", ".join(ARGUMENT_OPTIONS[arg]["indicators"]), div1) |
188 | description = wrap(ARGUMENT_OPTIONS[arg]["description"], div2) |
189 | l1 = indicators[0] |
190 | z = 0 |
191 | for line in description: |
192 | try: |
193 | l1 = indicators[z] |
194 | except: |
195 | l1 = "" |
196 | z += 1 |
197 | l = columnize([(div1, l1), (div2, line)], ccols) |
198 | arg_lines.append(l) |
199 | args += arg_lines |
200 |
|
201 | output_lines(args) |
202 | output() |
203 | return |
204 | elif display_version: |
205 | output(VERSION_MESSAGE) |
206 | else: |
207 | output(VERSION_SHORT) |
208 | output(HELP_MESSAGE) |
209 |
|
210 | if __name__ == "__main__": |
211 | main() |
212 |
|