diff --git a/ecopilot_srcindex/repomap.py b/ecopilot_srcindex/repomap.py index 6cc4e7f49656e429025b4eaf328134d37900a9f9..d31a94cac36187bab0e3b1f9688b3fe925957eb9 100644 --- a/ecopilot_srcindex/repomap.py +++ b/ecopilot_srcindex/repomap.py @@ -28,6 +28,34 @@ Tag = namedtuple("Tag", "rel_fname fname line name kind".split()) SQLITE_ERRORS = (sqlite3.OperationalError, sqlite3.DatabaseError, OSError) +# Provide custom output styling. +class MyTreeContext(TreeContext): + + def format(self): + if not self.show_lines: + return "" + + # output = "```\n" + output = "" + + dots = not (0 in self.show_lines) + for i, line in enumerate(self.lines): + if i not in self.show_lines: + if dots: + output += "\n...\n\n" + dots = False + continue + + line_output = f"{self.output_lines.get(i, line)}" + output += line_output + "\n" + + dots = True + + # output += "```\n" + + return output + + class RepoMap: CACHE_VERSION = 3 TAGS_CACHE_DIR = f".ecopilot.tags.cache.v{CACHE_VERSION}" @@ -634,7 +662,7 @@ class RepoMap: if not code.endswith("\n"): code += "\n" - context = TreeContext( + context = MyTreeContext( rel_fname, code, color=False, @@ -691,7 +719,7 @@ class RepoMap: lois.append(tag.line) # truncate long lines, in case we get minified js or something else crazy - output = "\n".join([line[:100] for line in output.splitlines()]) + "\n" + output = "\n".join([line[:120] for line in output.splitlines()]) + "\n" return output