diff --git a/src/gui_2.py b/src/gui_2.py index b278112..9ffc703 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -1422,9 +1422,8 @@ class App: pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?") matches, is_nerv = list(pattern.finditer(content)), theme.is_nerv_active() if not matches: - if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80)) - markdown_helper.render(content, context_id=f'disc_{index}') - if is_nerv: imgui.pop_style_color() + with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext(): + markdown_helper.render(content, context_id=f'disc_{index}') else: with imscope.child(f"read_content_{index}", size_y=150, flags=True): if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x) @@ -1432,24 +1431,21 @@ class App: for m_idx, match in enumerate(matches): before = content[last_idx:match.start()] if before: - if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80)) - markdown_helper.render(before, context_id=f'disc_{index}_b_{m_idx}') - if is_nerv: imgui.pop_style_color() + with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext(): + markdown_helper.render(before, context_id=f'disc_{index}_b_{m_idx}') header_text, path, code_block = match.group(0).split("\n")[0].strip(), match.group(2), match.group(4) if imgui.collapsing_header(header_text): if imgui.button(f"[Source]##{index}_{match.start()}"): res = mcp_client.read_file(path) if res: self.text_viewer_title, self.text_viewer_content, self.text_viewer_type, self.show_text_viewer = path, res, (Path(path).suffix.lstrip('.') if Path(path).suffix else 'text'), True if code_block: - if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80)) - markdown_helper.render(code_block, context_id=f'disc_{index}_c_{m_idx}') - if is_nerv: imgui.pop_style_color() + with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext(): + markdown_helper.render(code_block, context_id=f'disc_{index}_c_{m_idx}') last_idx = match.end() after = content[last_idx:] if after: - if is_nerv: imgui.push_style_color(imgui.Col_.text, vec4(80, 255, 80)) - markdown_helper.render(after, context_id=f'disc_{index}_a') - if is_nerv: imgui.pop_style_color() + with imscope.style_color(imgui.Col_.text, vec4(80, 255, 80)) if is_nerv else nullcontext(): + markdown_helper.render(after, context_id=f'disc_{index}_a') if self.ui_word_wrap: imgui.pop_text_wrap_pos() def _render_mma_focus_selector(self) -> None: