Commit 37b65dc6 authored by Yannick Kirschhoffer's avatar Yannick Kirschhoffer

#6: Add color control command line parameters.

parent 9b8fed3f
......@@ -5,7 +5,7 @@ from docker_ascii_map.widget import *
from docker_ascii_map.docker_config import Configuration, Container
def build_container_widget(container: Container, encoding: str) -> Widget:
def build_container_widget(container: Container, encoding: str, color: bool) -> Widget:
lines = []
if encoding == 'UTF-8':
statuschar = u"\u2713" if container.status == 'running' else u"\u274c"
......@@ -57,7 +57,7 @@ class Renderer:
def __init__(self):
pass
def render(self, config: Configuration, encoding: str = 'UTF-8'):
def render(self, config: Configuration, encoding: str = 'UTF-8', color: bool = False):
network_widgets = []
networks = build_ordered_network_list(config)
......@@ -72,7 +72,7 @@ class Renderer:
for container in config.containers:
if [net] == container.networks:
container_widget = build_container_widget(container, encoding)
container_widget = build_container_widget(container, encoding, color)
cnt_widgets_map[container] = container_widget
net_widgets.append(build_container_wrapper(container, container_widget))
......@@ -87,7 +87,7 @@ class Renderer:
for container in config.containers:
if len(container.networks) > 1:
c = Padding(build_container_widget(container, encoding), Size(1, 0))
c = Padding(build_container_widget(container, encoding, color), Size(1, 0))
cnt_widgets_map[container] = c
padded = Padding(c, Size(12, 2))
bridge_widgets.append(padded)
......
......@@ -9,14 +9,17 @@ from docker_ascii_map.ascii_render import Renderer
parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
parser.add_argument('--version', action='version', version='%(prog)s ' + __version__)
parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
if __name__ == '__main__':
args = parser.parse_args()
color_mode = args.color and not args.mono
parser = ConfigParser()
config_parser = ConfigParser()
renderer = Renderer()
config = parser.get_configuration()
config = config_parser.get_configuration()
# print(config)
text = renderer.render(config, sys.stdout.encoding)
text = renderer.render(config, sys.stdout.encoding, color_mode)
print(text)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment