TheR1D / shell_gpt

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.
MIT License
9.43k stars 746 forks source link

Disable newlines when a sentence "touches" the frame #423

Closed vanyauhalin closed 7 months ago

vanyauhalin commented 9 months ago

Hi Farkhod! Thank you for creating such an awesome app.

I've a question regarding the auto-insertion of newlines when a sentence "touches" the frame of the terminal window. How can I disable this feature?

One of my main use cases is language learning. I write sentences in Google Translate, copy them to the terminal to have GPT check the punctuation, and then copy the result back to Google Translate. I repeat this process until I get the desired output.

In the previous version, I didn't have to worry about removing newlines manually, but in the new version, I've to do it every time, which is quite inconvenient. Is there a way to disable this behavior?

jeanlucthumm commented 8 months ago

Can confirm that piped output is (incorrectly) dependent on terminal size, i.e. new lines are being inserted when sentences reaches end of terminal.

Running the following command: sgpt "output a paragraph" | wl-copy, which pipes into my clipboard, and pasting here we the difference:

Small terminal width:

Certainly! Here's a sample paragraph:          

Lorem ipsum dolor sit amet, consectetur        
adipiscing elit. Sed do eiusmod tempor         
incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo  
consequat. Duis aute irure dolor in            
reprehenderit in voluptate velit esse cillum   
dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa 
qui officia deserunt mollit anim id est        
laborum.

versus a larger terminal width:

Certainly! Here's a sample paragraph:                                                                                                                   

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,    
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.         

This probably has something to do with the recent markdown change (#400)

Also related: #438

jeanlucthumm commented 8 months ago

Fix would be disabling markdown output if we are piping / redirecting. Apparently detecting that is possible with:

if sys.stdout.isatty():
    # You're running in a real terminal
else:
    # You're being piped or redirected
TheR1D commented 8 months ago

I think we can add --no-markdown option and config variable to disable markdown formatting (includng role changes). In this particular case when we want to copy the output of sgpt from terminal to the clipboard we will still have new lines even if we add some magic with sys.stdout.isatty().

@vanyauhalin quick workaround for the issue is to use custom role:

sgpt --create-role punctuation_check
# <- Enter role description: Review and edit provided text, check punctuation and spelling. Provide only edited text as output in original language.
sgpt --role punctuation_check "Ahoj jmenuji se Farkhod a jsem vývojář"
# -> Ahoj, jmenuji se Farkhod a jsem vývojář.

Since custom roles doesn't format the output using markdown, it should be without new lines.

TheR1D commented 7 months ago

In the latest ShellGPT release 1.3.0 there is an option to disable makrdown output. Please follow steps in release description to disable markdown formatting. Given that I'm closing this issue, but feel free to reopen it.