Question
· Dec 18, 2017

Get Window Size from terminal

Hi,

Can I get "Window Size" from terminal? By command line.

Terminal > Edit > Window Size

I already tried to use 'do CURRENT^%IS', but without success. It does not return the change, for example, when the column is 132.

Is there any routine or method for this?

Discussion (6)1
Log in or sign up to continue

There is nothing built into Caché to get a updating virtual terminal window size like you would have with ncurses. You could...

(1) Write the terminal portions of you application in a language with ncurses support (like "C"), and then use either call-in or call-out to combine the ncurses portions of your application with the COS portions. Call-in would probably be easier.

(2) If you can live without an automated update, the traditional solution is to assign a key in your application to repaint the screen after modem line noise (remember that) messed-up the screen. Traditionally, that was <CTRL+R>. You could just add to the work done by <CTRL+R> to be.
    (a) Clear the screen.
    (b) Position the cursor at the lower right hand corner.
    (c) Clear the typeahead buffer.
    (d) Ask the terminal were its cursor is.
    (e) Read, and parse the Cursor Position Report.
    The position of the cursor is the window size.
    (f) Repaint the screen at its current size.
Step (a) could be moved later in the sequence if you like.
Steps (b) and (c) can be reversed.

If you only care about supporting modern terminal emulators, all of which emulate VT-100+ terminals, the code is

    ;(a) Clear the screen
    WRITE $CHAR(27),"[H"
    ;(b) Positions the cursor at the lower right hand corner.
    WRITE $CHAR(27)_"[255;255H"
    ;(c) Clear the typeahead buffer.
    WRITE *-1
    ;(d) Ask the terminal where its cursor is:
    ;Use this routine
FC()    NEW
    SET result=0 FOR j=1:1:4 DO  QUIT:result  ;             [10]
    . WRITE $CHAR(27)_"[6n" ;                               [20]
    . READ junk:j QUIT:'$TEST  QUIT:$ASCII($KEY)'=27  ;     [30]
    . QUIT:$EXTRACT($KEY,2)'="["  QUIT:$EXTRACT($KEY,*)'="R"
    . SET $Y=$EXTRACT($KEY,3,*)-1,$X=$PIECE($KEY,";",2)-1 ; [40]
    . SET result=1
    QUIT result
    ; ------------
    ; [10] Assume failure. Try four times (with increasing
    ;      timeout) to determine the location of the cursor.
    ;      Quit early on success.
    ; [20] Send where is the cursor (DSR Device Status Request).
    ; [30] Read result, CPR (Cursor Position Report). We must
    ;      get it, and it must be of form "<ESC>[#,#R".
    ; [40] Extract $Y and $X from the CPR (Cursor Position
    ;      Report), and call it a success.
    ;(e) Repaint the screen at its current size.
    ; That is up to you.