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 Stockin1990N

Blob @ lognestmonster / parser / format.py

application/x-python2474 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# ANSI codes for output
22
23RESET = "\033[0m"
24BOLD = "\033[1m"
25UNDERLINED = "\033[4m"
26CONTRAST = "\033[7m"
27
28TEXT_RED = "\033[91m"
29TEXT_GREEN = "\033[92m"
30TEXT_YELLOW = "\033[93m"
31TEXT_MAGENTA = "\033[95m"
32TEXT_CYAN = "\033[96m"
33
34BACK_RED = "\033[101m"
35BACK_GREEN = "\033[102m"
36BACK_YELLOW = "\033[103m"
37BACK_MAGENTA = "\033[105m"
38BACK_CYAN = "\033[106m"
39
40POSITION = "\033[{0};{1}H"
41
42UP = "\x1b[A"
43DOWN = "\x1b[B"
44RIGHT = "\x1b[C"
45LEFT = "\x1b[D"
46CTRLC = "\x03"
47
48
49# wrap lines
50
51def wrap(string, width):
52 string_length = len(string)
53 if string_length <= width: return [string]
54 lines = []
55 line = ""
56 words = string.split()
57 for word in words:
58 line += " "
59 word_length = len(word)
60 if word_length == 0: continue
61 if word_length > width:
62 for char in word:
63 line += char
64 line = line.strip()
65 if len(line) == width:
66 lines.append(line)
67 line = ""
68 continue
69 if len(line) + word_length > width:
70 lines.append(line)
71 line = word
72 else:
73 line += word
74 line = line.strip()
75 line = line.strip()
76 if len(line) > 0:
77 lines.append(line)
78 return lines
79
80def columnize(items, max):
81 string = ""
82 for item in items:
83 length = item[0]
84 content = item[1].strip()[:length]
85 string += content.ljust(length, " ")
86 return string[:max]
87
88def pad(string, padding, width):
89 length = len(string)
90 if length >= width: return string[:length]
91 padding_length = (width-length)/2
92 return padding*padding_length + string + padding*padding_length
93
94def expand(string1, string2, width):
95 if len(string1) >= width: return string1[:width]
96 full = string1 + string2
97 if len(full) >= width: return full[:width]
98 left = width - len(full)
99 return (string1 + " "*left + string2)[:width]
100