multidiff
multidiff copied to clipboard
Consider making output as wide as the terminal
Possibly making it optional... I would have added --width=auto
and did max terminal width if that information is available ... here is code from tqdm
tqdm/_utils.py-def _environ_cols_linux(fp): # pragma: no cover
tqdm/_utils.py-
tqdm/_utils.py- try:
tqdm/_utils.py: from termios import TIOCGWINSZ
tqdm/_utils.py- from fcntl import ioctl
tqdm/_utils.py- from array import array
tqdm/_utils.py- except ImportError:
tqdm/_utils.py- return None
tqdm/_utils.py- else:
tqdm/_utils.py- try:
tqdm/_utils.py: return array('h', ioctl(fp, TIOCGWINSZ, '\0' * 8))[1]
tqdm/_utils.py- except:
tqdm/_utils.py- try:
tqdm/_utils.py- from os.environ import get
tqdm/_utils.py- except ImportError:
tqdm/_utils.py- return None
tqdm/_utils.py- else:
tqdm/_utils.py- return int(get('COLUMNS', 1)) - 1
Thanks for good input :)
I assume this relates to the hexdump view? Quite a lot of people have a strong inclination to use multiples of eight in hexdump widths, but this being configurable surely covers most cases. How about supporting:
- —width [number]
- —width max
yeah, that is what I had in mind ;) if auto -- go after full width, if specified -- that is the one to use
I suggest an alternate approach using the os module
rows, columns = os.popen('stty size', 'r').read().split()
where columns variable stores the width of the terminal
Then an additional argument can be made which asks for the number of bytes to be printed on each line
If the user calls --width max
then args.width would be equal to columns
@Utkarsh1308 I appreciate your efforts 👍
Thanks for the pull request but there might be a little misunderstanding in what feature was requested. The idea is that we want to either use all the screen area we have available, or to group our input to other than multiples of 16 (normal hexdump format). @yarikoptic suggested this but doesn't need it.
This feature is a little like the format string given in the -e
flag in the hexdump
utility:
-
multidiff --width 16
should produce hexdumps similar tohecdump -C
-
multidiff --width 25
should produce hexdumps similar tohexdump -e '"%06_ax: " 25/1 "%02x " " | " 25/1 "%_p" "\n"'
-
multidiff --width 6
should produce hexdumps similar tohexdump -e '"%06_ax: " 6/1 "%02x " " | " 6/1 "%_p" "\n"'
@Utkarsh1308 if you need the feature youve implemented (filling rows with characters), then I'm happy to merge it. But if this isn't needed by you, then I'd rather not add a feature which is likely not to be used.
I understand! Sorry for the misunderstanding. Please don't close my PR. I'll add a new attribute which does the desired behavior wanted by @yarikoptic :D
I do want the width attribute I've implemented. But I'd be happy to add an attribute which gives this behavior
For achieving this behavior I will have to create an argument. Then I'll have to replace 16 with that argument in render.py :) But the code runs really slow when I do this. Is there any other solution for this? I will have to replace the argument with 16 here:
https://github.com/juhakivekas/multidiff/blob/1e4f7b57fbcf7efb29e4b6df3b2fc6d0475e13d9/multidiff/Render.py#L78 https://github.com/juhakivekas/multidiff/blob/1e4f7b57fbcf7efb29e4b6df3b2fc6d0475e13d9/multidiff/Render.py#L80
https://github.com/juhakivekas/multidiff/blob/1e4f7b57fbcf7efb29e4b6df3b2fc6d0475e13d9/multidiff/Render.py#L114
https://github.com/juhakivekas/multidiff/blob/1e4f7b57fbcf7efb29e4b6df3b2fc6d0475e13d9/multidiff/Render.py#L127
https://github.com/juhakivekas/multidiff/blob/1e4f7b57fbcf7efb29e4b6df3b2fc6d0475e13d9/multidiff/Render.py#L128
I found an alternate approach to get the desired output. Please review my PR
Hey @juhakivekas Any changes you would want in my PR? I'm happy to help ;)