gap icon indicating copy to clipboard operation
gap copied to clipboard

Spurious CR at start of output in quiet mode, caused by Browse package

Open eduardkareletc opened this issue 10 years ago • 18 comments

Running gap as:

$ echo 'Display("test");; quit;;' |gap -q |od -N 10 -t a
0000000   cr   t   e   s   t  nl 

This shows an initial CR character in the output. In my understanding, the -q flag should have suppressed any output before the output generated by the program (t e s t nl)". In further output from a gap program each line is terminated by NL, that's what I found inspecting the output of my program that lead to me running the test above to show this bug.

My gap version info is:

 ┌───────┐   GAP, Version 4.7.7 of 13-Feb-2015 (free software, GPL)
 │  GAP                │   http://www.gap-system.org
 └───────┘   Architecture: x86_64-apple-darwin13.4.0-gcc-default64

eduardkareletc avatar Dec 26 '15 22:12 eduardkareletc

I don't seem able to reproduce in 4.7.8, or the current git version. I don't have 4.7.7, could you try 4.7.8 (although I don't think it will fix it...)

~/r/g/r/gap4r7p8 $ echo 'Display("test");; quit;;' | bin/gap.sh -q | od -N 10 -t a
0000000    t   e   s   t  nl
0000005

ChrisJefferson avatar Dec 26 '15 23:12 ChrisJefferson

This is triggered by some package, because this does not happen with -A option:

$ echo 'Display("test");; quit;;' | bin/gap.sh -q -r| od -N 10 -t a
0000000   cr   t   e   s   t  nl                                        
0000006
$ echo 'Display("test");; quit;;' | bin/gap.sh -q -A -r| od -N 10 -t a
0000000    t   e   s   t  nl                                            
0000005
$ echo 'Print("test");; quit;;' | bin/gap.sh -q -r| od -N 10 -t a
0000000   cr   t   e   s   t                                            
0000005
$ echo 'Print("test");; quit;;' | bin/gap.sh -q -A -r| od -N 10 -t a
0000000    t   e   s   t                                                
0000004

(this is with GAP 4.7.9)

olexandr-konovalov avatar Dec 27 '15 12:12 olexandr-konovalov

Hello Christopher,

The bug no longer exists in 4.7.8, or 4.7.9. I should have checked that myself.

Likely the fact that MacOS uses the CR as end-of-line rather than NL mat be at the root of this.

Thanks for the help and a happy new year. Eduard

Christopher Jefferson mailto:[email protected] 27 december 2015 00:24

I don't seem able to reproduce in 4.7.8, or the current git version. I don't have 4.7.7, could you try 4.7.8 (although I don't think it will fix it...)

|~/r/g/r/gap4r7p8 $ echo 'Display("test");; quit;;' | bin/gap.sh -q | od -N 10 -t a 0000000 t e s t nl 0000005 |

— Reply to this email directly or view it on GitHub https://github.com/gap-system/gap/issues/430#issuecomment-167371220.

eduardkareletc avatar Dec 27 '15 13:12 eduardkareletc

@eduardkareletc @ChrisJefferson no it is still there and it happens when Browse package by @frankluebeck is loaded - if it's not compiled, you will not be able to reproduce this. See below:

$ echo 'Display("test");; quit;;' | bin/gap.sh -q -A -r| od -N 10 -t a
0000000    t   e   s   t  nl                                            
0000005
$ echo 'LoadPackage("browse":OnlyNeeded);;Display("test");; quit;;' | bin/gap.sh -q -A -r| od -N 10 -t a
0000000   cr   t   e   s   t  nl                                        
0000006

olexandr-konovalov avatar Dec 27 '15 17:12 olexandr-konovalov

Likely the fact that MacOS uses the CR as end-of-line rather than NL mat be at the root of this.

That's not true at all -- it held for MacOS 9 and older, but Mac OS X behaves like any other Unix in this regard.

fingolfin avatar Jan 14 '16 18:01 fingolfin

I think it is caused by Browse. If I start GAP with Browse, I get the \r, without, I don't. By the way, I am using Linux.

sebasguts avatar Jan 21 '16 14:01 sebasguts

@sebasguts exactly - see the comment I left 25 days ago.

olexandr-konovalov avatar Jan 21 '16 14:01 olexandr-konovalov

This is caused by the endwin() call in the PostRestore() function of the Browse kernel extension. If I comment it out, the spurious CR is gone.

fingolfin avatar Jan 21 '16 17:01 fingolfin

I missed this thread so far, sorry.

Indeed, when GAP is started and Browse is installed it will by default load Browse. In the example code Browse detects that the output is no terminal and so initializes itself for a "dumb" terminal. The CR which is returned upon the endwin() call is probably part of the definition of the dumb terminal.

Please, do not remove this endwin() call in PostRestore, it is needed to end the visual mode after initialization of ncurses. (If you start GAP normally, your terminal will be in a bad state - quit GAP and type reset<CR> to recover.)

The correct solution is to start GAP without Browse (which is not very useful anyway without an interactive terminal). For example, use the -A option and put explicit LoadPackage(...) call for the packages you really need into your code.

In particular, I don't think that there is any bug here, please change the label of this issue.

frankluebeck avatar Jan 21 '16 23:01 frankluebeck

Yeah, I didn't mean to suggest that one should remove the endwin() call, just wanted to express that I verified that it is responsible for printing the CR :).

And please feel free to change the label by yourself as you see fit :-).

fingolfin avatar Jan 21 '16 23:01 fingolfin

And please feel free to change the label by yourself as you see fit :-).

Ah, I wasn't aware that even I can understand how do that without reading pages and pages of documentation . . .

frankluebeck avatar Jan 21 '16 23:01 frankluebeck

I don't think we'll ever change anything about this. Workarounds were suggested (e.g. use -A).

fingolfin avatar Dec 29 '22 01:12 fingolfin

See here for the related discussion.

hongyi-zhao avatar Mar 18 '23 01:03 hongyi-zhao

The workaround -A does not help when packages are used which depend or suggest explicitly or implicitly through other the package browse. Packages I have identified so far are:

  • ctbllib
  • CAP
  • AtlasRep
  • Tomlib (implicitly through atlasrep (needed) and ctbllib (suggested))
  • HeLP (implicitly through CTblLib and atlasrep)

kiryph avatar Nov 01 '23 09:11 kiryph

I cannot see a problem here:

echo 'Display("test");;LoadPackage("ctbllib");; quit;;' |gap -q -A | od -N 10 -t a
0000000   t   e   s   t  nl  cr

Nevertheless, if you want to make sure that under all circumstances Browse is not loaded, you can disable it by putting the line

SetUserPreference( "PackagesToIgnore", [ "browse" ] );

in your gap.ini file. You could also use options -r and -l for using a specific gap.ini file in your scripts (instead of ~/.gap/gap.ini).

frankluebeck avatar Nov 01 '23 14:11 frankluebeck

@frankluebeck The order of your command is wrong. You have to print something after loading the package not before:

❯ echo 'LoadPackage("ctbllib");;Display("test");; quit;;' |\gap -q -A | od -N 10 -t a
0000000   cr   t   e   s   t  nl

kiryph avatar Nov 02 '23 07:11 kiryph

@kiryph Yes thanks, this way I can reproduce the cr.

(And confirm, that the solution works ...)

frankluebeck avatar Nov 02 '23 08:11 frankluebeck

@frankluebeck

Thanks for pointing the user setting out:

SetUserPreference( "PackagesToIgnore", [ "browse" ] );

I was not aware of it and helps to run gap even without -A and still not loading GAP package browse.

kiryph avatar Nov 02 '23 11:11 kiryph