nali icon indicating copy to clipboard operation
nali copied to clipboard

Compatible with mtr and possibly other tui programs

Open zu1k opened this issue 1 year ago • 1 comments

This was previously discussed at https://github.com/zu1k/nali/pull/133, we still have some problems with mtr compatibility.

The following content is copied from #133 posted by @mzz2017 :


After the fix PR https://github.com/zu1k/nali/pull/132, we found that in different mtr display modes, nali still has exceptions.

To reproduce it, try:

> mtr baidu.com | nali
# and then press d to switch the display mode

At the beginning, we fixed it by scanning control runes (rune<0x20). Although it fixed the most problems, we found there was also some abnormal cursor jitter.

Finally, we think we shouldn't use bufio because it uses cache to delay reads. We should unblock as soon as the write finish on the other side of the pipe ends, and return the read result, process it and print it on the screen, which is what our PR does.


Currently we have the following problems:

  • If we use io.Copy to replace bufio, there will be potential IP truncation and the IP will not be recognized. https://github.com/zu1k/nali/pull/133#issuecomment-1216061342 @mzz2017 mentioned that some kind of cache could be added to solve this. https://github.com/zu1k/nali/pull/133#issuecomment-1216066702

  • If we continue to use bufio, we may need to add additional control character scans to solve the cursor jitter problem in tui. https://github.com/zu1k/nali/pull/133#issuecomment-1216067498

  • Maybe we can add an arg like --mode tui to specifically be compatible with tui programs like mtr. https://github.com/zu1k/nali/pull/133#issuecomment-1216076370

  • The current scanning method is to splite text by \n and \r characters, but when encountering super-long input without newline characters, nali will freeze. https://github.com/zu1k/nali/pull/133#issuecomment-1216071360

zu1k avatar Aug 16 '22 03:08 zu1k

Additional info: We can see linux pipe size by command ulimit -a. By default, it is 8*512byte=4k.

mzz2017 avatar Sep 05 '22 07:09 mzz2017