Move get_input function into utils.py and update the call to get_input in coder.py to use the new utils.get_input function.

# Context:
USER: move get_input into utils. pass in history_file and fnames as params rather than referencing them with self.
ASSISTANT: To move the `get_input` function into `utils.py`, we will remove it from the `Coder` class in `coder.py` and add it to `utils.py`. We will also update the function to accept `history_file` and `fnames` as parameters.

```python
coder.py
<<<<<<< ORIGINAL
    def get_input(self):
        inp = ""
        multiline_input = False

        style = Style.from_dict({'': 'green'})

        while True:
            completer_instance = FileContentCompleter(self.fnames)
            if multiline_input:
                show = ". "
            else:
                show = "> "

            try:
                line = prompt(
                    show,
                    completer=completer_instance,
                    history=FileHistory(self.history_file),
                    style=style,
                )
            except EOFError:
                return
            if line.strip() == "{" and not multiline_input:
                multiline_input = True
                continue
            elif line.strip() == "}" and multiline_input:
                break
            elif multiline_input:
                inp += line + "\n"
            else:
                inp = line
                break

        print()
        return inp
=======
>>>>>>> UPDATED
```

```python
utils.py
<<<<<<< ORIGINAL
=======
def get_input(history_file, fnames):
    inp = ""
    multiline_input = False

    style = Style.from_dict({'': 'green'})

    while True:
        completer_instance = FileContentCompleter(fnames)
        if multiline_input:
            show = ". "
        else:
            show = "> "

        try:
            line = prompt(
                show,
                completer=completer_instance,
                history=FileHistory(history_file),
                style=style,
            )
        except EOFError:
            return
        if line.strip() == "{" and not multiline_input:
            multiline_input = True
            continue
        elif line.strip() == "}" and multiline_input:
            break
        elif multiline_input:
            inp += line + "\n"
        else:
            inp = line
            break

    print()
    return inp
>>>>>>> UPDATED
```

Now, update the call to `get_input` in `coder.py` to use the new `utils.get_input` function:

```python
coder.py
<<<<<<< ORIGINAL
        inp = self.get_input()
=======
        inp = utils.get_input(self.history_file, self.fnames)
>>>>>>> UPDATED
```
This commit is contained in:
Paul Gauthier 2023-05-09 10:09:42 -07:00
parent 64c3af37df
commit 6419e6c390
2 changed files with 36 additions and 37 deletions

View file

@ -107,3 +107,38 @@ def do_replace(fname, before_text, after_text):
fname.write_text(new_content)
return True
def get_input(history_file, fnames):
inp = ""
multiline_input = False
style = Style.from_dict({'': 'green'})
while True:
completer_instance = FileContentCompleter(fnames)
if multiline_input:
show = ". "
else:
show = "> "
try:
line = prompt(
show,
completer=completer_instance,
history=FileHistory(history_file),
style=style,
)
except EOFError:
return
if line.strip() == "{" and not multiline_input:
multiline_input = True
continue
elif line.strip() == "}" and multiline_input:
break
elif multiline_input:
inp += line + "\n"
else:
inp = line
break
print()
return inp