-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the Ability to edit the code before running it. #935
Conversation
Now the user can edit the code before running it. OI does not keep track of previous code (before it was edited).
I also think it would be a good idea to give the user the ability to choose their favorite editor by asking them once the first time they want to edit a code. |
temp_file.write(code) | ||
temp_filename = temp_file.name | ||
|
||
subprocess.run(['code', temp_filename], check=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use something like this to open it in default editor. Check language and add extention to the tmp file. python = .py etc..
import os
import subprocess
import platform
def open_file_default_editor(file_path):
try:
if platform.system() == 'Windows':
os.startfile(file_path)
elif platform.system() == 'Darwin': # macOS
subprocess.call(('open', file_path))
elif platform.system() == 'Linux':
subprocess.call(('xdg-open', file_path))
else:
print(f"Unsupported OS: {platform.system()}")
except Exception as e:
print(f"Error opening file: {e}")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback!
For checking the language, does OI already know what language the code he wrote is in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but if language is None it defaults to python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please give me the name of the variable that holds that value?
One more thing, I noticed that whatever changes I made to the code, when I run interpreter in the terminal, it just runs the first version. Why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a look at contributors.md
I added a comment, to show where you can get the language
#830 |
Hi @Eliaskhal! This is going to be such a useful feature. I think this is close, but I want to approach it in a slightly different place. My main edit: I think it's too much to ask the user if they want to edit every code block, especially to insert it into a familiar (y/n) ask. I think I'm happy to merge if it can be converted to a magic command with the flow outlined here, otherwise I'll merge once this feature becomes my priority, then I'll convert it into a magic command. Also it's worth noting that we do store the file extension for the code, so if you Great work on building the feature. I'm personally very excited to use this, and your PR works incredibly well. |
Hey @KillianLucas, I did not notice your comment and I ended up adding what @Notnaton suggested. I would be more than happy to use your idea. My only problem is that I am still having issues understanding how everything is architected in the project. I understand OI has a message history and magic commands. If you don't mind, could you please explain a bit about how those messages are stored? and where does the user type the magic command exactly? |
I think I was able to figure it out. I added the magic command and it works now. I will close this request and start a new one. Thank you! |
Now the user can edit the code before running it.
OI does not keep track of previous code (before it was edited).
What I did exactly:
Possible Improvements:
NOTE:
I haven't been able to test the code since I had problems running it even though I have followed the documentation.
Check List:
docs/CONTRIBUTING.md
docs/ROADMAP.md
Tests: