How to use render_highlighted method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

console.py

Source:console.py Github

copy

Full Screen

...59 check_label = "CHECK %s" % ("OK" if is_successful else "KO")60 else:61 check_label = "CHECK"62 return colored(check_label, color=outcome_to_color(is_successful), attrs=["bold"])63 def render_highlighted(self, content):64 if not self.highlight or not content:65 return content66 return self.highlight.sub(67 lambda m: colored(m.group(0), color="yellow", attrs=["bold", "underline"]), content68 )69 def render_step_log(self, log):70 if isinstance(log, Log):71 if log.level == "debug" and not self.show_debug_logs:72 return None73 else:74 return [75 colored(log.level.upper(), color=log_level_to_color(log.level), attrs=["bold"]),76 self.render_highlighted(self.wrap_description_col(log.message))77 ]78 if isinstance(log, Check):79 return [80 self.render_check_outcome(log.is_successful),81 self.render_highlighted(self.wrap_description_col(log.description)),82 self.render_highlighted(self.wrap_details_col(log.details))83 ]84 if isinstance(log, Url):85 if log.description == log.url:86 description = log.url87 else:88 description = "%s (%s)" % (log.url, log.description)89 return [90 colored("URL", color="cyan", attrs=["bold"]),91 self.render_highlighted(self.wrap_description_col(description))92 ]93 if isinstance(log, Attachment):94 return [95 colored("ATTACH", color="cyan", attrs=["bold"]),96 self.render_highlighted(self.wrap_description_col(log.description)),97 self.render_highlighted(log.filename)98 ]99 raise ValueError("Unknown step log class '%s'" % log.__class__.__name__)100 def render_steps(self, steps):101 rows = []102 for step in steps:103 step_log_rows = list(filter(bool, map(self.render_step_log, step.get_logs())))104 if step_log_rows:105 rows.append([106 "",107 colored(108 self.render_highlighted(self.wrap_description_col(step.description)),109 color=outcome_to_color(step.is_successful()),110 attrs=["bold"]111 ),112 colored(humanize_duration(step.duration, show_milliseconds=True), attrs=["bold"])113 if step.duration is not None else "-"114 ])115 rows.extend(step_log_rows)116 if not rows:117 return None118 table = AsciiTable(rows)119 table.inner_heading_row_border = False120 table.justify_columns[0] = "center"121 table.inner_row_border = True122 return table.table...

Full Screen

Full Screen

renderer.py

Source:renderer.py Github

copy

Full Screen

1# vim:fileencoding=utf-8:noet2from powerline.theme import Theme3from unicodedata import east_asian_width, combining4import os5try:6 NBSP = unicode(' ', 'utf-8')7except NameError:8 NBSP = ' '9def construct_returned_value(rendered_highlighted, segments, output_raw):10 if output_raw:11 return rendered_highlighted, ''.join((segment['_rendered_raw'] for segment in segments))12 else:13 return rendered_highlighted14class Renderer(object):15 segment_info = {16 'environ': os.environ,17 'getcwd': getattr(os, 'getcwdu', os.getcwd),18 'home': os.environ.get('HOME'),19 }20 def __init__(self,21 theme_config,22 local_themes,23 theme_kwargs,24 colorscheme,25 pl,26 **options):27 self.__dict__.update(options)28 self.theme_config = theme_config29 theme_kwargs['pl'] = pl30 self.pl = pl31 self.theme = Theme(theme_config=theme_config, **theme_kwargs)32 self.local_themes = local_themes33 self.theme_kwargs = theme_kwargs34 self.colorscheme = colorscheme35 self.width_data = {36 'N': 1, # Neutral37 'Na': 1, # Narrow38 'A': getattr(self, 'ambiwidth', 1), # Ambigious39 'H': 1, # Half-width40 'W': 2, # Wide41 'F': 2, # Fullwidth42 }43 def strwidth(self, string):44 return sum((0 if combining(symbol) else self.width_data[east_asian_width(symbol)] for symbol in string))45 def get_theme(self, matcher_info):46 return self.theme47 def shutdown(self):48 self.theme.shutdown()49 def get_highlighting(self, segment, mode):50 segment['highlight'] = self.colorscheme.get_highlighting(segment['highlight_group'], mode, segment.get('gradient_level'))51 if segment['divider_highlight_group']:52 segment['divider_highlight'] = self.colorscheme.get_highlighting(segment['divider_highlight_group'], mode)53 else:54 segment['divider_highlight'] = None55 return segment56 def get_segment_info(self, segment_info):57 r = self.segment_info.copy()58 if segment_info:59 r.update(segment_info)60 if 'PWD' in r['environ']:61 r['getcwd'] = lambda: r['environ']['PWD']62 return r63 def render(self, mode=None, width=None, side=None, output_raw=False, segment_info=None, matcher_info=None):64 '''Render all segments.65 When a width is provided, low-priority segments are dropped one at66 a time until the line is shorter than the width, or only segments67 with a negative priority are left. If one or more filler segments are68 provided they will fill the remaining space until the desired width is69 reached.70 '''71 theme = self.get_theme(matcher_info)72 segments = theme.get_segments(side, self.get_segment_info(segment_info))73 # Handle excluded/included segments for the current mode74 segments = [self.get_highlighting(segment, mode) for segment in segments75 if mode not in segment['exclude_modes'] or (segment['include_modes'] and segment in segment['include_modes'])]76 segments = [segment for segment in self._render_segments(theme, segments)]77 if not width:78 # No width specified, so we don't need to crop or pad anything79 return construct_returned_value(''.join([segment['_rendered_hl'] for segment in segments]) + self.hlstyle(), segments, output_raw)80 # Create an ordered list of segments that can be dropped81 segments_priority = [segment for segment in sorted(segments, key=lambda segment: segment['priority'], reverse=True) if segment['priority'] > 0]82 while sum([segment['_len'] for segment in segments]) > width and len(segments_priority):83 segments.remove(segments_priority[0])84 segments_priority.pop(0)85 # Distribute the remaining space on spacer segments86 segments_spacers = [segment for segment in segments if segment['width'] == 'auto']87 if segments_spacers:88 distribute_len, distribute_len_remainder = divmod(width - sum([segment['_len'] for segment in segments]), len(segments_spacers))89 for segment in segments_spacers:90 if segment['align'] == 'l':91 segment['_space_right'] += distribute_len92 elif segment['align'] == 'r':93 segment['_space_left'] += distribute_len94 elif segment['align'] == 'c':95 space_side, space_side_remainder = divmod(distribute_len, 2)96 segment['_space_left'] += space_side + space_side_remainder97 segment['_space_right'] += space_side98 segments_spacers[0]['_space_right'] += distribute_len_remainder99 rendered_highlighted = ''.join([segment['_rendered_hl'] for segment in self._render_segments(theme, segments)]) + self.hlstyle()100 return construct_returned_value(rendered_highlighted, segments, output_raw)101 def _render_segments(self, theme, segments, render_highlighted=True):102 '''Internal segment rendering method.103 This method loops through the segment array and compares the104 foreground/background colors and divider properties and returns the105 rendered statusline as a string.106 The method always renders the raw segment contents (i.e. without107 highlighting strings added), and only renders the highlighted108 statusline if render_highlighted is True.109 '''110 segments_len = len(segments)111 for index, segment in enumerate(segments):112 segment['_rendered_raw'] = ''113 segment['_rendered_hl'] = ''114 prev_segment = segments[index - 1] if index > 0 else theme.EMPTY_SEGMENT115 next_segment = segments[index + 1] if index < segments_len - 1 else theme.EMPTY_SEGMENT116 compare_segment = next_segment if segment['side'] == 'left' else prev_segment117 outer_padding = ' ' if (index == 0 and segment['side'] == 'left') or (index == segments_len - 1 and segment['side'] == 'right') else ''118 divider_type = 'soft' if compare_segment['highlight']['bg'] == segment['highlight']['bg'] else 'hard'119 divider_raw = theme.get_divider(segment['side'], divider_type)120 divider_spaces = theme.get_spaces()121 divider_highlighted = ''122 contents_raw = segment['contents']123 contents_highlighted = ''124 draw_divider = segment['draw_' + divider_type + '_divider']125 # Pad segments first126 if draw_divider:127 if segment['side'] == 'left':128 contents_raw = outer_padding + (segment['_space_left'] * ' ') + contents_raw + ((divider_spaces + segment['_space_right']) * ' ')129 else:130 contents_raw = ((divider_spaces + segment['_space_left']) * ' ') + contents_raw + (segment['_space_right'] * ' ') + outer_padding131 else:132 if segment['side'] == 'left':133 contents_raw = outer_padding + (segment['_space_left'] * ' ') + contents_raw + (segment['_space_right'] * ' ')134 else:135 contents_raw = (segment['_space_left'] * ' ') + contents_raw + (segment['_space_right'] * ' ') + outer_padding136 # Replace spaces with no-break spaces137 contents_raw = contents_raw.replace(' ', NBSP)138 divider_raw = divider_raw.replace(' ', NBSP)139 # Apply highlighting to padded dividers and contents140 if render_highlighted:141 if divider_type == 'soft':142 divider_highlight_group_key = 'highlight' if segment['divider_highlight_group'] is None else 'divider_highlight'143 divider_fg = segment[divider_highlight_group_key]['fg']144 divider_bg = segment[divider_highlight_group_key]['bg']145 else:146 divider_fg = segment['highlight']['bg']147 divider_bg = compare_segment['highlight']['bg']148 divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)149 contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])150 # Append padded raw and highlighted segments to the rendered segment variables151 if draw_divider:152 if segment['side'] == 'left':153 segment['_rendered_raw'] += contents_raw + divider_raw154 segment['_rendered_hl'] += contents_highlighted + divider_highlighted155 else:156 segment['_rendered_raw'] += divider_raw + contents_raw157 segment['_rendered_hl'] += divider_highlighted + contents_highlighted158 else:159 if segment['side'] == 'left':160 segment['_rendered_raw'] += contents_raw161 segment['_rendered_hl'] += contents_highlighted162 else:163 segment['_rendered_raw'] += contents_raw164 segment['_rendered_hl'] += contents_highlighted165 segment['_len'] = self.strwidth(segment['_rendered_raw'])166 yield segment167 @staticmethod168 def escape(string):169 return string170 def hlstyle(fg=None, bg=None, attr=None):171 raise NotImplementedError172 def hl(self, contents, fg=None, bg=None, attr=None):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful