def refresh(self): template = [ SingleTextRow("Buffer: " + self.buffer.display_name, maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), SingleTextRow(self.buffer.description, maps={"normal": "main_list_dg", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), SingleTextRow("Global Keybindings", maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template.extend(assemble_rows( [[SelectableText(key, maps=get_map("main_list_yellow")), SelectableText(command, maps=get_map("main_list_lg"))] for key, command in self.global_keybinds.items()], ignore_columns=[1], dividechars=3)) if self.buffer.keybinds: template += [ SingleTextRow(""), SingleTextRow("Buffer-specific Keybindings", maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template.extend(assemble_rows( [[SelectableText(key, maps=get_map("main_list_yellow")), SelectableText(command, maps=get_map("main_list_lg"))] for key, command in self.buffer.keybinds.items()], ignore_columns=[1], dividechars=3)) self.set_body(template) self.set_focus(0)
def _basic_data(self): data = [ [ SelectableText("Id", maps=get_map("main_list_green")), SelectableText(self.docker_container.container_id) ], [ SelectableText("Status", maps=get_map("main_list_green")), ContainerStatusWidget(self.docker_container, nice_status=False) ], [ SelectableText("Created", maps=get_map("main_list_green")), SelectableText("{0}, {1}".format( self.docker_container.display_formal_time_created(), self.docker_container.display_time_created())) ], [ SelectableText("Command", maps=get_map("main_list_green")), SelectableText(self.docker_container.command) ], ] # TODO: add exit code, created, started, finished, pid if self.docker_container.names: data.append([ SelectableText("Name", maps=get_map("main_list_green")), SelectableText("".join(self.docker_container.names)) ], ) self.view_widgets.extend(assemble_rows(data, ignore_columns=[1]))
def _basic_data(self): data = [ [ SelectableText("Id", maps=get_map("main_list_green")), SelectableText(self.docker_container.container_id) ], [ SelectableText("Status", maps=get_map("main_list_green")), ContainerStatusWidget(self.docker_container) ], [ SelectableText("Created", maps=get_map("main_list_green")), SelectableText("{0}, {1}".format( self.docker_container.display_formal_time_created(), self.docker_container.display_time_created())) ], [ SelectableText("Command", maps=get_map("main_list_green")), SelectableText(self.docker_container.command) ], ] if self.docker_container.names: data.append([ SelectableText("Name", maps=get_map("main_list_green")), SelectableText("".join(self.docker_container.names)) ], ) self.walker.extend(assemble_rows(data, ignore_columns=[1]))
def _labels(self): if not self.docker_container.labels: return [] data = [] self.walker.append(RowWidget([SelectableText("Labels", maps=get_map("main_list_white"))])) for label_key, label_value in self.docker_container.labels.items(): data.append([SelectableText(label_key, maps=get_map("main_list_green")), SelectableText(label_value)]) self.walker.extend(assemble_rows(data, ignore_columns=[1]))
def test_assemble_rows_long_text(): rows = [[get_random_text_widget(10), get_random_text_widget(300)] for _ in range(5)] assembled_rows = assemble_rows(rows, ignore_columns=[1]) lb = WidgetBase(MockUI(), SimpleListWalker(assembled_rows)) canvas = lb.render((80, 20), focus=False) text = [bytes().join([t for at, cs, t in ln]) for ln in canvas.content()] logging.info("%r", text) assert len(text) == 20 first_col, second_col = text[0].split(b" ", 1) assert first_col == rows[0][0].text.encode("utf-8") assert rows[0][1].text.encode("utf-8").startswith(second_col)
def refresh(self): invocation = ["[{}=value]".format(a.name) for a in self.command.options_definitions] + \ ["<{}>".format(o.name) for o in self.command.arguments_definitions] template = [ SingleTextRow("Command: {} {}".format(self.command.name, " ".join(invocation)), maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template += [SingleTextRow(s, maps={"normal": "main_list_dg", "focus": MAIN_LIST_FOCUS}) for s in self.command.description.split("\n")] template += [SingleTextRow("")] if self.command.arguments_definitions: template += [ SingleTextRow(""), SingleTextRow("Arguments", maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template.extend(assemble_rows( [[SelectableText(argument.name, maps=get_map("main_list_yellow")), SelectableText(argument.description, maps=get_map("main_list_lg"))] for argument in self.command.arguments_definitions], ignore_columns=[1], dividechars=3)) if self.command.options_definitions: template += [ SingleTextRow(""), SingleTextRow("Options", maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template.extend(assemble_rows( [[SelectableText(option.name, maps=get_map("main_list_yellow")), SelectableText(option.description, maps=get_map("main_list_lg"))] for option in self.command.options_definitions], ignore_columns=[1], dividechars=3)) self.set_body(template) self.set_focus(0)
def refresh(self): invocation = ["[{}=value]".format(a.name) for a in self.command.argument_definitions] + \ ["<{}>".format(o.name) for o in self.command.option_definitions] template = [ SingleTextRow("Command: {} {}".format(self.command.name, " ".join(invocation)), maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template += [SingleTextRow(s, maps={"normal": "main_list_dg", "focus": MAIN_LIST_FOCUS}) for s in self.command.description.split("\n")] template += [SingleTextRow("")] if self.command.option_definitions: template += [ SingleTextRow(""), SingleTextRow("Arguments", maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template.extend(assemble_rows( [[SelectableText(option.name, maps=get_map("main_list_yellow")), SelectableText(option.description, maps=get_map("main_list_lg"))] for option in self.command.option_definitions], ignore_columns=[1], dividechars=3)) if self.command.argument_definitions: template += [ SingleTextRow(""), SingleTextRow("Options", maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}), SingleTextRow(""), ] template.extend(assemble_rows( [[SelectableText(argument.name, maps=get_map("main_list_yellow")), SelectableText(argument.description, maps=get_map("main_list_lg"))] for argument in self.command.argument_definitions], ignore_columns=[1], dividechars=3)) self.set_body(template) self.set_focus(0)
def _basic_data(self): data = [ [SelectableText("Id", maps=get_map("main_list_green")), SelectableText(self.docker_image.image_id)], [SelectableText("Created", maps=get_map("main_list_green")), SelectableText("{0}, {1}".format(self.docker_image.display_formal_time_created(), self.docker_image.display_time_created()))], [SelectableText("Size", maps=get_map("main_list_green")), SelectableText(humanize_bytes(self.docker_image.size))], [SelectableText("Command", maps=get_map("main_list_green")), SelectableText(self.docker_image.container_command)], ] self.walker.extend(assemble_rows(data))
def _basic_data(self): data = [ [SelectableText("Id", maps=get_map("main_list_green")), SelectableText(self.docker_container.container_id)], [SelectableText("Status", maps=get_map("main_list_green")), ContainerStatusWidget(self.docker_container, nice_status=False)], [SelectableText("Created", maps=get_map("main_list_green")), SelectableText("{0}, {1}".format(self.docker_container.display_formal_time_created(), self.docker_container.display_time_created()))], [SelectableText("Command", maps=get_map("main_list_green")), SelectableText(self.docker_container.command)], ] # TODO: add exit code, created, started, finished, pid if self.docker_container.names: data.append( [SelectableText("Name", maps=get_map("main_list_green")), SelectableText("".join(self.docker_container.names))], ) self.walker.extend(assemble_rows(data, ignore_columns=[1]))
def _net(self): try: net = self.docker_container.net except NotAvailableAnymore: raise NotifyError("Container %s is not available anymore" % self.docker_container) ports = net.ports data = [] if ports: data.extend([[SelectableText("")], [ SelectableText("Host Port", maps=get_map("main_list_white")), SelectableText("Container Port", maps=get_map("main_list_white")) ]]) for container_port, host_port in ports.items(): if host_port and container_port: data.append([ SelectableText(host_port), SelectableText(container_port) ]) ips = net.ips logger.debug(ips) if ips: data.extend([[SelectableText("")], [ SelectableText("Network Name", maps=get_map("main_list_white")), SelectableText("IP Address", maps=get_map("main_list_white")) ]]) for net_name, net_data in ips.items(): a4 = net_data.get("ip_address4", "none") a6 = net_data.get("ip_address6", "") data.append([SelectableText(net_name), SelectableText(a4)]) if a6: data.append([SelectableText(net_name), SelectableText(a6)]) if data: self.view_widgets.extend( assemble_rows(data, dividechars=3, ignore_columns=[1]))
def _basic_data(self): data = [ [SelectableText("Id", maps=get_map("main_list_green")), SelectableText(self.docker_image.image_id)], [SelectableText("Created", maps=get_map("main_list_green")), SelectableText("{0}, {1}".format(self.docker_image.display_formal_time_created(), self.docker_image.display_time_created()))], [SelectableText("Size", maps=get_map("main_list_green")), SelectableText(humanize_bytes(self.docker_image.total_size))], ] if self.docker_image.unique_size: data.append( [SelectableText("Unique Size", maps=get_map("main_list_green")), SelectableText(humanize_bytes(self.docker_image.unique_size))]) if self.docker_image.shared_size: data.append( [SelectableText("Shared Size", maps=get_map("main_list_green")), SelectableText(humanize_bytes(self.docker_image.shared_size))]) data.append([SelectableText("Command", maps=get_map("main_list_green")), SelectableText(self.docker_image.container_command)]) self.walker.extend(assemble_rows(data, ignore_columns=[1]))
def _net(self): try: net = self.docker_container.net except NotAvailableAnymore: raise NotifyError("Container %s is not available anymore" % self.docker_container) ports = net.ports data = [] if ports: data.extend([[SelectableText("")], [ SelectableText("Host Port", maps=get_map("main_list_white")), SelectableText("Container Port", maps=get_map("main_list_white")) ]]) for container_port, host_port in ports.items(): if host_port and container_port: data.append([ SelectableText(host_port), SelectableText(container_port) ]) ips = net.ips logger.debug(ips) if ips: data.extend([[SelectableText("")], [ SelectableText("Network Name", maps=get_map("main_list_white")), SelectableText("IP Address", maps=get_map("main_list_white")) ]]) for net_name, net_data in ips.items(): a4 = net_data.get("ip_address4", "none") a6 = net_data.get("ip_address6", "") data.append([ SelectableText(net_name), SelectableText(a4) ]) if a6: data.append([ SelectableText(net_name), SelectableText(a6) ]) if data: self.walker.extend(assemble_rows(data, dividechars=3, ignore_columns=[1]))
def _net(self): ports = self.docker_container.net.ports data = [] if ports: data.extend([[SelectableText("")], [ SelectableText("Host Port", maps=get_map("main_list_white")), SelectableText("Container Port", maps=get_map("main_list_white")) ]]) for container_port, host_port in ports.items(): if host_port and container_port: data.append([ SelectableText(host_port), SelectableText(container_port) ]) ips = self.docker_container.net.ips logger.debug(ips) if ips: data.extend([[SelectableText("")], [ SelectableText("Network Name", maps=get_map("main_list_white")), SelectableText("IP Address", maps=get_map("main_list_white")) ]]) for net_name, net_data in ips.items(): a4 = net_data.get("ip_address4", "none") a6 = net_data.get("ip_address6", "") data.append([SelectableText(net_name), SelectableText(a4)]) if a6: data.append([SelectableText(net_name), SelectableText(a6)]) if data: self.walker.extend( assemble_rows(data, dividechars=3, ignore_columns=[1]))