forked from mcprtk/tty_color_chooser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttycolor.py
executable file
·72 lines (58 loc) · 2.52 KB
/
ttycolor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# Copyright 2018-2020, Pratik Mullick.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import random
import os
import sys
import subprocess
import argparse
import tempfile
import converter
class Program:
def __init__(self):
self.name = "ttycolor"
self.description = "A program to change colors for TTY console in Linux."
self.parser = argparse.ArgumentParser(prog=self.name, description=self.description, allow_abbrev=False)
self.parser.add_argument("-s", "--setup", action="store_true", help="Sets up console colors")
self.parser.add_argument("-v", "--version", action="version", version="%(prog)s 0.8 beta")
self.parser.add_argument("-o", "--output", type=str, metavar="OUTFILE", help="Output file name")
self.parser.add_argument("filename", metavar="FILE", type=str, help="Input file in YAML format")
self.args = self.parser.parse_args()
self.filename = self.args.filename
def main(self):
if not os.path.isfile(self.filename):
print("File not found.")
self.parser.print_usage()
sys.exit()
line_array = converter.Operations(self.filename).dict2svr()
if self.args.setup:
with tempfile.NamedTemporaryFile(mode="w+t") as dummy:
for line in line_array:
dummy.write(line)
dummy.seek(0)
subprocess.run(["setvtrgb", dummy.name])
subprocess.run(["clear"])
elif self.args.output:
with open(self.args.output,"w") as outfile:
for line in line_array:
outfile.write(line)
print("You can use setvtrgb command on {}".format(self.args.output))
else:
for line in line_array:
line = line.strip('\n')
print(line)
# Running the program when invoked.
if __name__ == "__main__":
prog = Program()
prog.main()