From 2a0761b0ce97015aa815fadd65d6c5d127049e02 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 29 May 2023 11:42:19 -0700 Subject: [PATCH] aider: Added MarkdownLexer to highlight user input with markdown syntax. # Context: USER: have `prompt_toolkit` highlight the user input with a markdown lexer ASSISTANT: To highlight the user input with a markdown lexer, we need to modify the `aider/io.py` file. We will import the `MarkdownLexer` from `pygments.lexers.markup` and use it as the lexer for the `PromptSession`. Here's the change you need to make: ```python aider/io.py <<<<<<< ORIGINAL from pygments.lexers import guess_lexer_for_filename ======= from pygments.lexers import guess_lexer_for_filename, MarkdownLexer >>>>>>> UPDATED ``` And update the `PromptSession` instantiation in the `get_input` method: ```python aider/io.py <<<<<<< ORIGINAL session_kwargs = { "message": show, "completer": completer_instance, "reserve_space_for_menu": 4, "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, } ======= session_kwargs = { "message": show, "completer": completer_instance, "reserve_space_for_menu": 4, "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, "lexer": MarkdownLexer(), } >>>>>>> UPDATED ``` These changes will import the `MarkdownLexer` and use it for the `PromptSession`, which will highlight the user input with markdown syntax. --- aider/io.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aider/io.py b/aider/io.py index 8e1d01192..f4de29a79 100644 --- a/aider/io.py +++ b/aider/io.py @@ -8,7 +8,7 @@ from prompt_toolkit.completion import Completer, Completion from prompt_toolkit.history import FileHistory from prompt_toolkit.shortcuts import CompleteStyle, PromptSession, prompt from prompt_toolkit.styles import Style -from pygments.lexers import guess_lexer_for_filename +from pygments.lexers import guess_lexer_for_filename, MarkdownLexer from pygments.token import Token from pygments.util import ClassNotFound from rich.console import Console @@ -148,6 +148,7 @@ class InputOutput: "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, + "lexer": MarkdownLexer(), } if style: session_kwargs["style"] = style