Closed rabuchaim closed 3 months ago
Hello,
When argcomplete runs your program to collect completions, there is no terminal that the program is connected to. So if you run os.get_terminal_size()
(which raises OSError
in this situation) at startup time, you will have to catch and deal with the error.
You can reproduce this issue more easily by redirecting the output of your program to a file or device: ./argc.py > /dev/null
Thanks!!
I just changed the code and put a try: except and argcomplete is working as I expected!
##──── GET THE TERMINAL WIDTH
class terminal:
def __init__(self):
try:
self.width = os.get_terminal_size().columns - 1
except:
self.width = 120
##──── RETURNS A LINE FILLED WITH A CHAR
class line:
middot = "\xb7" * terminal().width
single = "─" * terminal().width
double = "═" * terminal().width
Hi there!
I rewrote my code twice... the third time (this weekend) I decided to add class by class, and I found the problem. A pretty stupid problem.
If you add the class below in your code with argcomplete, the argcomplete will stop working. This class just draw a line in your terminal. You don't even need to call the class, the code will stop working.
If you want to call to see the result:
This is the expected result:
····················································································································
The problem is the function
os.get_terminal_size().columns
. If you change this text by a number like '120', the argcomplete will work without problem. But the terminal size can change, the user can change the window size, this is why to get the current columns size every time I call the class "line".So my code is like this:
If you put a
__init__(self)
function in this class "line", the argcomplete works with no problems, but I don´t want to call the function line with parentheses (kkkk).If you set the environment variable
_ARC_DEBUG=1
you will see an errorexception <class 'SystemExit'> 2 while parsing args
without any useful information. BUT AT THE END YOU WILL SEE THE COMPLETION WORKING!!If you remove the environment variable, It will stop working.
Why does it happen? I didn't understand... (I gave up and my code is calling the line() function with parentheses)
I appreciate your time reading this, I spent a lot of time to discover this, I think the debug function could show more specific errors.
Thanks
Ricardo Abuchaim - ricardoabuchaim@gmail.com