MCPcopy
hub / github.com/Textualize/toolong / render_line

Method render_line

src/toolong/log_lines.py:596–665  ·  view source on GitHub ↗
(self, y: int)

Source from the content-addressed store, hash-verified

594 return super().render_lines(crop)
595
596 def render_line(self, y: int) -> Strip:
597 scroll_x, scroll_y = self.scroll_offset
598 index = y + scroll_y
599 style = self.rich_style
600 width, height = self.size
601 if index >= self.line_count:
602 return Strip.blank(width, style)
603
604 log_file_span = self.index_to_span(index)
605
606 is_pointer = self.pointer_line is not None and index == self.pointer_line
607 cache_key = (*log_file_span, is_pointer, self.find)
608
609 try:
610 strip = self._render_line_cache[cache_key]
611 except KeyError:
612 line, text, timestamp = self.get_text(index, abbreviate=True, block=True)
613 text.stylize_before(style)
614
615 if is_pointer:
616 pointer_style = self.get_component_rich_style(
617 "loglines--pointer-highlight"
618 )
619 text.stylize(Style(bgcolor=pointer_style.bgcolor, bold=True))
620
621 search_index = self._search_index
622
623 for word in re.split(SPLIT_REGEX, text.plain):
624 if len(word) <= 1:
625 continue
626 for offset in range(1, len(word) - 1):
627 sub_word = word[:offset]
628 if sub_word in search_index:
629 if len(search_index[sub_word]) < len(word):
630 search_index[sub_word.lower()] = word
631 else:
632 search_index[sub_word.lower()] = word
633
634 if self.find and self.show_find:
635 self.highlight_find(text)
636 strip = Strip(text.render(self.app.console), text.cell_len)
637 self._max_width = max(self._max_width, strip.cell_length)
638 self._render_line_cache[cache_key] = strip
639
640 if is_pointer:
641 pointer_style = self.get_component_rich_style("loglines--pointer-highlight")
642 strip = strip.crop_extend(scroll_x, scroll_x + width, pointer_style)
643 else:
644 strip = strip.crop_extend(scroll_x, scroll_x + width, None)
645
646 if self.show_gutter or self.show_line_numbers:
647 line_number_style = self.get_component_rich_style(
648 "loglines--line-numbers-active"
649 if index == self.pointer_line
650 else "loglines--line-numbers"
651 )
652 if self.pointer_line is not None and index == self.pointer_line:
653 icon = "👉"

Callers

nothing calls this directly

Calls 4

index_to_spanMethod · 0.95
get_textMethod · 0.95
highlight_findMethod · 0.95
renderMethod · 0.80

Tested by

no test coverage detected