Menu

#153 Maxima should honor the number of columns provided by the terminal

None
open
nobody
display (4)
5
2022-09-26
2021-01-23
No

The default number of columns used by maxima in the terminal is 79. Though it can be changed manually, the number of columns to use should be retrieved automatically, as most text applications do.
Maxima should also be able to detect when the terminal is resized (thanks to the SIGWINCH signal) and update the number of columns.
Since the user may want to fix a number of columns, the linel option variable could use a special value for automatic handling (e.g. 0), or a new option variable could be added.

Discussion

  • Robert Dodier

    Robert Dodier - 2021-01-28

    Ticket moved from /p/maxima/bugs/3711/

     
  • Robert Dodier

    Robert Dodier - 2021-01-28

    This is an interesting idea, but it seems like a feature request instead of a bug, so I moved it.

     
  • Wolfgang Dautermann

    For Unix/Linux systems one might use the shell variable $COLUMNS (or interpret the output of stty -a), so e.g.

    maxima --run-string="linel:$COLUMNS $"
    

    would do the trick. You can set an alias with that command.

    We can integrate that in the maxima startup script, but the string occurs as a first output and the first prompt would be (%i2), so it might be better to read the environment variable from the lisp side and set linel.

    For Windows there might be simliar solutions possible (e.g. Powershell or small C programs, for example: https://superuser.com/questions/680746/is-it-possible-to-fetch-the-current-cmd-window-size-rows-and-columns-in-window).

    (This does cover only Maxima startup, not reacting on signals).

     
  • Gunter Königsmann

    This might be a low-hanging fruit, too: Only applications that want to immediately reformat the whole screen contents are supposed to listen to the WINCH signal =>

    • Just copying the contents of the COLUMNS environment variable to the maxima variable linel should fulfill the easy 90% of the functionality
    • Extra points for the one who checks the COLUMNS environment variable every time maxima outputs a new output label, changes the value of linel accordingly, if linel hasn't been user-modified since and changes linel's reset value to the new value of COLUMNS.
     
  • Robert Dodier

    Robert Dodier - 2022-09-24

    I agree that the easy, useful thing to do is to just look for COLUMNS and set linel accordingly. For extra credit, define a handler for SIGWINCHto detect changes. All that may be implementation-dependent but I think that's okay -- I think it's defensible to handle window size on a best-effort basis.

     
  • Vincent Lefevre

    Vincent Lefevre - 2022-09-24

    There is no COLUMNS environment variable in my shell (zsh); this is just a shell variable (despite the uppercase letters). The reason is that its value becomes incorrect whenever the window is resized (zsh updates it, but this would not be the case of the child processes in general), thus it must not be present in the environment.

    I don't know whether this can be used, but I've found this: Get the size of the terminal from Common Lisp.

     
  • Raymond Toy

    Raymond Toy - 2022-09-25

    I think it would be nice to set linel to the terminal width. I almost always run maxima instead an emacs shell window, so I'm not sure how that would work there.

    It seems like a lot to have to get cffi and osicat just to be able to get the terminal size for maxima. If maxima used cffi more, then I'd wouldn't object to add osicat to get the terminal size.

     
  • Gunter Königsmann

    I believe it is not the shell, but the terminal that should set the COLUMN variable. ...and there are so many terminals that there always will be ones that don't: mingrtty on a text console or any mingrtty replacement. tun/tap devices. Literally hundred of terminal window programs. Serial terminals. Emacs text buffers. Graphical Terminals. Serial lines. Pipes that end up in other programs.
    Not for all of these possibilities there is a good way to define a Allowed column number.

    The above lisp program That uses cffi seems to support only one of these cases: if maxima is run directly on a Linux text mode console. The chances that it is are near to zero Nowadays as virtually everybody is using windows, gnome, KDE, MacOS or a different graphical environment even to run text windows.

    Just reading the COLUMS variable would provide support for way more environments and if there is no such variable or if it holds a suspicious value (text, negative number or something below 10 or so) we should have a default value to fallback to.

    a!d we don't need to listen to any signal for that: The signal tells applications that immediately redraw the whole screen when the window resizes that they should do that now. We don't do that so reading COLUMNS once before running a new command is more than sufficient: If the terminal changes it's size all subsequent output uses the right value for COLUNMS, that way.

     
  • Vincent Lefevre

    Vincent Lefevre - 2022-09-26

    Under Unix, environment variables are not shared among processes, they are just inherited by new processes. So, if the parent changes the value of an environment variable, the child won't see it. The size of the terminal can be obtained at any time by using a system call (ioctl(..., TIOCGWINSZ, ...)) and languages like LISP may provide an interface for that (for a shell, one of the interfaces is the COLUMNS shell variable, which is not even an environment variable). It is true that listening to the signal is not needed, but this means that you will need to use this system call (via the corresponding interface) each time you need to know the terminal width. I do not think that this is an issue, though.

     
  • Gunter Königsmann

    The TIOCGWINSZ Ioctrl will only work if maxima is run in a text mode terminal, though, which means that it won't work in the typical case that someone is running it in a terminal window under gnome, KDE, xvfe or similar.

     
  • Vincent Lefevre

    Vincent Lefevre - 2022-09-26

    No, terminals like GNOME Terminal, Konsole and the Xfce terminal are text terminals, and the ioctl will work.

     

Log in to post a comment.