Commit graph

335 commits

Author SHA1 Message Date
Paul Gauthier
579fc39d61 rename 2023-06-05 11:32:26 -07:00
Paul Gauthier
6b4c54d117 Merge branch 'main' into call-graph 2023-05-30 11:45:39 -07:00
Paul Gauthier
b359134f86 reverted a4e57e17b5 2023-05-30 07:58:31 -07:00
Paul Gauthier
a4e57e17b5 aider: Added completions_height parameter to InputOutput class and passed it from aider/main.py.
# Context:
USER: pass it to `InputOutput` and store as a self. var
ASSISTANT: I will modify the `InputOutput` class in `aider/io.py` to accept the `completions_height` parameter and store it as an instance variable.

Here's the change to add the `completions_height` parameter to the `InputOutput` class:

```python
aider/io.py

^C KeyboardInterrupt
USER: `aider/io.py`
ASSISTANT: I will modify the `InputOutput` class in `aider/io.py` to accept the `completions_height` parameter and store it as an instance variable.

Here's the change to add the `completions_height` parameter to the `InputOutput` class:

```python
aider/io.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
=======
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
        completions_height=10,
    ):
        self.completions_height = completions_height
>>>>>>> UPDATED
```

Now, you need to pass the `completions_height` value from `aider/main.py` to the `InputOutput` class when creating an instance:

```python
aider/main.py
<<<<<<< ORIGINAL
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
        user_input_color=args.user_input_color,
        tool_output_color=args.tool_output_color,
        tool_error_color=args.tool_error_color,
    )
=======
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
        user_input_color=args.user_input_color,
        tool_output_color=args.tool_output_color,
        tool_error_color=args.tool_error_color,
        completions_height=args.completions_height,
    )
>>>>>>> UPDATED
```

Now, the `completions_height` value is passed to the `InputOutput` class and stored as an instance variable.
2023-05-29 17:33:39 -07:00
Paul Gauthier
2ff24a51dd bold italic 2023-05-29 12:13:28 -07:00
Paul Gauthier
fbb14b2823 aider: Changed pygments.literal.string to appear in inverse colors.
# Context:
USER: no. let's make pygments.literal.string be in inverse colors
ASSISTANT: To make `pygments.literal.string` appear in inverse colors, we need to modify the `aider/io.py` file. Update the `style` dictionary in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": f"underline {self.user_input_color}"})
=======
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": f"reverse {self.user_input_color}"})
>>>>>>> UPDATED
```

This change will apply the inverse color style to ticked words in the `PromptSession`.
2023-05-29 11:49:50 -07:00
Paul Gauthier
8f40f08636 aider: Updated the style dictionary in get_input method to apply underline style and self.user_input_color to ticked words.
# Context:
USER: underlined and self.user_input_color
ASSISTANT: To underline ticked words and apply the `self.user_input_color`, we need to modify the `aider/io.py` file. Update the `style` dictionary in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": "underline"})
=======
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": f"underline {self.user_input_color}"})
>>>>>>> UPDATED
```

This change will apply the underline style and the `self.user_input_color` to ticked words in the `PromptSession`.
2023-05-29 11:48:22 -07:00
Paul Gauthier
507442da3f aider: Added underline style to ticked words in PromptSession.
# Context:
USER: can we override the style for `ticked` words to just underline them, not change the color?
ASSISTANT: Yes, we can override the style for ticked words to underline them without changing the color. We need to modify the `aider/io.py` file. Update the `style` dictionary in the `InputOutput` class's `__init__` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict
^C KeyboardInterrupt
USER: no, just for the markdown highlighting in the `PromptSession`
ASSISTANT: I apologize for the misunderstanding. To override the style for ticked words in the `PromptSession`, we need to modify the `aider/io.py` file. Update the `style` dictionary in the `get_input` method:

```python
aider/io.py
<<<<<<< ORIGINAL
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color})
=======
        if self.user_input_color:
            style = Style.from_dict({"": self.user_input_color, "pygments.literal.string": "underline"})
>>>>>>> UPDATED
```

This change will apply the underline style to ticked words in the `PromptSession` without changing their color.
2023-05-29 11:46:57 -07:00
Paul Gauthier
4a4d0efe89 aider: Replaced MarkdownLexer with PygmentsLexer to correctly highlight user input with markdown syntax.
# Context:
USER: AttributeError: 'MarkdownLexer' object has no attribute 'lex_document'
ASSISTANT: I apologize for the confusion. It seems I misunderstood the usage of `MarkdownLexer` with `prompt_toolkit`. Instead, we should use `PygmentsLexer` from `prompt_toolkit.lexers` to wrap the `MarkdownLexer`. Here's the updated change:

First, import `PygmentsLexer` from `prompt_toolkit.lexers`:

```python
aider/io.py
<<<<<<< ORIGINAL
from prompt_toolkit.completion import Completer, Completion
=======
from prompt_toolkit.completion import Completer, Completion
from prompt_toolkit.lexers import PygmentsLexer
>>>>>>> UPDATED
```

Then, 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,
                "lexer": MarkdownLexer(),
            }
=======
            session_kwargs = {
                "message": show,
                "completer": completer_instance,
                "reserve_space_for_menu": 4,
                "complete_style": CompleteStyle.MULTI_COLUMN,
                "input": self.input,
                "output": self.output,
                "lexer": PygmentsLexer(MarkdownLexer),
            }
>>>>>>> UPDATED
```

These changes will correctly use the `MarkdownLexer` with `prompt_toolkit` to highlight the user input with markdown syntax.
2023-05-29 11:43:50 -07:00
Paul Gauthier
2a0761b0ce 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.
2023-05-29 11:42:19 -07:00
Paul Gauthier
e4805490f5 quote autocompletions 2023-05-29 11:32:50 -07:00
Paul Gauthier
27bd993cab Merge branch 'main' into call-graph 2023-05-29 11:18:30 -07:00
Paul Gauthier
92cd2f3ce6 isort 2023-05-28 22:47:38 -07:00
Paul Gauthier
d2284447c3 Only no_color, not force_term 2023-05-28 06:12:06 -07:00
Paul Gauthier
321824299a aider: Added check for NO_COLOR environment variable to disable ANSI color.
# Context:
USER: Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.
ASSISTANT: To implement this feature, we need to modify the `aider/io.py` file. Please make it *read-write* so I can provide the necessary changes.
USER: I added these *read-write* files: aider/io.py
ASSISTANT: Great! Now, I will make the necessary changes to check for the `NO_COLOR` environment variable and disable ANSI color when it is present and not an empty string.

```python
aider/io.py
<<<<<<< ORIGINAL
import os
=======
import os
import os.path
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        self.user_input_color = user_input_color
        self.tool_output_color = tool_output_color
        self.tool_error_color = tool_error_color
        self.input = input
        self.output = output
        self.pretty = pretty
        self.yes = yes
        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=True, no_color=True)
=======
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None
        self.input = input
        self.output = output
        self.pretty = pretty
        self.yes = yes
        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        self.console = Console(force_terminal=not pretty, no_color=not pretty)
>>>>>>> UPDATED
```

These changes will make the software check for the `NO_COLOR` environment variable and disable ANSI color when it is present and not an empty string.
2023-05-27 17:57:32 -07:00
Paul Gauthier
0fa660066f color the hrule 2023-05-27 15:19:53 -07:00
Paul Gauthier
70b912250a rename 2023-05-27 15:18:31 -07:00
Paul Gauthier
b8e480d699 rename 2023-05-27 15:18:13 -07:00
Paul Gauthier
cc9b21df06 renamed io.tool() -> io.tool_output() 2023-05-27 15:17:33 -07:00
Paul Gauthier
f6d07d9849 Accept colors for various prompts 2023-05-27 15:14:56 -07:00
Paul Gauthier
03cc679a5b aider: Added tool_color and tool_error_color properties to InputOutput class and updated style and console print accordingly.
# Context:
USER: move the red and green colors for tool and tool_error into self. properties. add args to init with red and green defaults.
ASSISTANT: To make the changes, I will modify the `aider/io.py` file. Here are the changes:

```python
aider/io.py
<<<<<<< ORIGINAL
class InputOutput:
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
    ):
=======
class InputOutput:
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        tool_color="green",
        tool_error_color="red",
    ):
        self.tool_color = tool_color
        self.tool_error_color = tool_error_color
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        style = Style.from_dict({"": "green"})
=======
        style = Style.from_dict({"": self.tool_color})
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        self.console.print(message, style="red")
=======
        self.console.print(message, style=self.tool_error_color)
>>>>>>> UPDATED
```
2023-05-27 14:54:04 -07:00
Paul Gauthier
db4fc2fe23 autocomplete file paths by (unique) basenames 2023-05-27 09:09:33 -07:00
Paul Gauthier
5ba084edec auto-complete filenames 2023-05-27 08:54:10 -07:00
Paul Gauthier
487040203e aider: Updated get_input to take a root param and receive rel_fnames not abs fnames, and updated FileContentCompleter to work with them.
# Context:
USER: change get_input to take a root param and receive rel_fnames not abs fnames. don't compute short_fnames, just use rel_fnames. also update FileContentCompleter to take root and rel_fnames and work with them.
ASSISTANT: To make the requested changes, I need you to provide me with *read-write* access to the following files:

1. `aider/io.py`
2. `aider/prompts.py`

Once you've granted me access to these files, I can provide you with the necessary code modifications.
USER: I added these *read-write* files: aider/io.py
ASSISTANT: Great! I will now make the changes to the `get_input` function and the `FileContentCompleter` class in the `aider/io.py` file.

```python
aider/io.py
<<<<<<< ORIGINAL
class FileContentCompleter(Completer):
    def __init__(self, fnames, commands):
        self.commands = commands

        self.words = set()
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
=======
class FileContentCompleter(Completer):
    def __init__(self, root, rel_fnames, commands):
        self.commands = commands

        self.words = set()
        for rel_fname in rel_fnames:
            fname = os.path.join(root, rel_fname)
            with open(fname, "r") as f:
                content = f.read()
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
    def get_input(self, fnames, commands):
        if self.pretty:
            self.console.rule()
        else:
            print()

        fnames = list(fnames)
        if len(fnames) > 1:
            common_prefix = os.path.commonpath(fnames)
            if not common_prefix.endswith(os.path.sep):
                common_prefix += os.path.sep
            short_fnames = [fname.replace(common_prefix, "", 1) for fname in fnames]
        elif len(fnames):
            short_fnames = [os.path.basename(fnames[0])]
        else:
            short_fnames = []

        show = " ".join(short_fnames)
=======
    def get_input(self, root, rel_fnames, commands):
        if self.pretty:
            self.console.rule()
        else:
            print()

        rel_fnames = list(rel_fnames)
        show = " ".join(rel_fnames)
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
            completer_instance = FileContentCompleter(fnames, commands)
=======
            completer_instance = FileContentCompleter(root, rel_fnames, commands)
>>>>>>> UPDATED
```

These changes will update the `get_input` function to take a `root` parameter and receive `rel_fnames` instead of absolute file names. The `FileContentCompleter` class is also updated to take the `root` and `rel_fnames` parameters and work with them.
2023-05-27 08:46:06 -07:00
Paul Gauthier
43b79b0c2d refac 2023-05-24 21:39:36 -07:00
Paul Gauthier
560e427684 aider: Updated default values of pretty and yes to True and False respectively in the InputOutput class constructor.
# Context:
USER: give inputoutput defaults of pretty=true and yes=false
ASSISTANT: To update the default values of `pretty` and `yes` in the `InputOutput` class, I will modify the `__init__` method in the `io.py` file.

```python
aider/io.py
<<<<<<< ORIGINAL
    def __init__(self, pretty, yes, input_history_file=None, chat_history_file=None, input=None, output=None):
=======
    def __init__(self, pretty=True, yes=False, input_history_file=None, chat_history_file=None, input=None, output=None):
>>>>>>> UPDATED
```
2023-05-23 06:05:48 -07:00
Paul Gauthier
01778be259 fixed indent 2023-05-18 17:33:11 -07:00
Paul Gauthier
1814638c1a aider: Fixed indentation error in aider/io.py.
# Context:
USER: I ran this command:

 pytest tests/test_commands.py

Which produced this output:

============================= test session starts ==============================
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
rootdir: /Users/gauthier/Projects/aider
collected 0 items / 1 error

==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_commands.py ____________________
.venv/lib/python3.11/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.venv/lib/python3.11/site-packages/_pytest/pathlib.py:564: in import_path
    importlib.import_module(module_name)
/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1206: in _gcd_import
    ???
<frozen importlib._bootstrap>:1178: in _find_and_load
    ???
<frozen importlib._bootstrap>:1149: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
.venv/lib/python3.11/site-packages/_pytest/assertion/rewrite.py:172: in exec_module
    exec(co, module.__dict__)
tests/test_commands.py:6: in <module>
    from aider.io import InputOutput as IO
E     File "/Users/gauthier/Projects/aider/aider/io.py", line 117
E       line = session.prompt()
E   IndentationError: unexpected indent
=========================== short test summary info ============================
ERROR tests/test_commands.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.32s ===============================

ASSISTANT: It seems there is an indentation error in the `aider/io.py` file. Please provide the content of the `aider/io.py` file so I can identify the issue and suggest a fix.
USER: Please note that I shared content of these additional files: aider/io.py
ASSISTANT: Apologies for the oversight. I see the indentation error in the `aider/io.py` file. Here's the fix:

```python
aider/io.py
<<<<<<< ORIGINAL
        session_kwargs = {
            "message": show,
            "completer": completer_instance,
            "style": style,
            "reserve_space_for_menu": 4,
            "complete_style": CompleteStyle.MULTI_COLUMN,
            "input": self.input,
            "output": self.output,
        }
        if self.input_history_file is not None:
            session_kwargs["history"] = FileHistory(self.input_history_file)
        session = PromptSession(**session_kwargs)
            line = session.prompt()
=======
        session_kwargs = {
            "message": show,
            "completer": completer_instance,
            "style": style,
            "reserve_space_for_menu": 4,
            "complete_style": CompleteStyle.MULTI_COLUMN,
            "input": self.input,
            "output": self.output,
        }
        if self.input_history_file is not None:
            session_kwargs["history"] = FileHistory(self.input_history_file)
        session = PromptSession(**session_kwargs)
        line = session.prompt()
>>>>>>> UPDATED
```

This should fix the indentation error. Please apply the change and run the tests again.
2023-05-18 17:32:33 -07:00
Paul Gauthier
aa8ead2f2e aider: Made the two history files optional.
# Context:
USER: make the two history files optional
ASSISTANT: To make the two history files optional, we will modify the `__init__` method of the `InputOutput` class in the `aider/io.py` file. We will set the default values of `input_history_file` and `chat_history_file` to `None`. Then, we will add conditions to check if these variables are not `None` before using them.

```python
aider/io.py
<<<<<<< ORIGINAL
    def __init__(self, pretty, yes, input_history_file, chat_history_file, input=None, output=None):
=======
    def __init__(self, pretty, yes, input_history_file=None, chat_history_file=None, input=None, output=None):
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        session = PromptSession(
            message=show,
            completer=completer_instance,
            history=FileHistory(self.input_history_file),
            style=style,
            reserve_space_for_menu=4,
            complete_style=CompleteStyle.MULTI_COLUMN,
            input=self.input,
            output=self.output,
        )
=======
        session_kwargs = {
            "message": show,
            "completer": completer_instance,
            "style": style,
            "reserve_space_for_menu": 4,
            "complete_style": CompleteStyle.MULTI_COLUMN,
            "input": self.input,
            "output": self.output,
        }
        if self.input_history_file is not None:
            session_kwargs["history"] = FileHistory(self.input_history_file)
        session = PromptSession(**session_kwargs)
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        self.chat_history_file = Path(chat_history_file)
=======
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        with self.chat_history_file.open("a") as f:
            f.write(text)
=======
        if self.chat_history_file is not None:
            with self.chat_history_file.open("a") as f:
                f.write(text)
>>>>>>> UPDATED
```

These changes will make the history files optional.
2023-05-18 17:30:34 -07:00
Paul Gauthier
943084fba2 aider: Removed unused imports in aider/io.py.
# Context:
USER: aider/io.py:12:1: F401 'time' imported but unused
import time
^
aider/io.py:13:1: F401 'random' imported but unused
import random
^

ASSISTANT: I see that there are unused imports in the `aider/io.py` file. I will remove them.

```python
aider/io.py
<<<<<<< ORIGINAL
import time
import random
=======
>>>>>>> UPDATED
```
2023-05-17 18:26:15 -07:00
Paul Gauthier
4ce6e279d3 Removed the canned_input method and commented out related code. 2023-05-17 15:24:40 -07:00
Paul Gauthier
7dc406d0b4 Print aider in lowercase 2023-05-17 15:22:34 -07:00
Paul Gauthier
bca4674e07 aider: Added a log_only parameter to tool() to allow emitting only to the log.
# Context:
USER: add a log_only=False param to tool() which only emits to the log, not to the scren
ASSISTANT: ```python
aider/io.py
<<<<<<< ORIGINAL
    def tool(self, *messages):
        if messages:
            hist = " ".join(messages)
            hist = f"{hist.strip()}"
            self.append_chat_history(hist, linebreak=True, blockquote=True)

        messages = list(map(Text, messages))
        self.console.print(*messages)
=======
    def tool(self, *messages, log_only=False):
        if messages:
            hist = " ".join(messages)
            hist = f"{hist.strip()}"
            self.append_chat_history(hist, linebreak=True, blockquote=True)

        if not log_only:
            messages = list(map(Text, messages))
            self.console.print(*messages)
>>>>>>> UPDATED
```
2023-05-17 15:20:52 -07:00
Paul Gauthier
6ea9085eec updated md chat log format 2023-05-17 13:45:27 -07:00
Paul Gauthier
11c0dd89d9 Renamed getinput -> io 2023-05-17 13:41:58 -07:00
Renamed from aider/getinput.py (Browse further)