• Reliable way to get term size

    From Alpha@21:4/158.1 to All on Saturday, April 03, 2021 08:51:06
    Hey all,

    Looking for a way to consistently get a user's screen/term size/mode that
    works across Syncterm, netRunner, MagiTerm, etc.

    Working on a little ansi art door and i'd like to be able to serve the 80
    or 132 columns version automatically.

    For Talisman, and maybe other BBS types I *could* possibly grab from
    the user preferences (e.g. talisman sqlite), but that seems pretty
    fraught.

    Would be awesome if there was a standard (ha) for door drop files that
    include the user's current size...

    cheers,




    |08---
    |15++ |13Alpha |15++
    |03TheDrunkenGamer.com|08:|078888
    |08A Talisman BBS


    --- Talisman v0.16-dev (Linux/x86_64)
    * Origin: The Drunken Gamer BBS (21:4/158.1)
  • From NuSkooler@21:1/121 to Alpha on Saturday, April 03, 2021 10:35:36

    Twas Saturday, April 3rd when Alpha said...
    Looking for a way to consistently get a user's screen/term size/mode that works across Syncterm, netRunner, MagiTerm, etc.

    It's complicated :)

    For Telnet connections, you can ask for NAWS which some support. You can also ask for environment variables, which works for some terminals as well. There is also a trick that works for some: Move the cursor to a very large bottom right coordinate (I use 999,999) then issue a ANSI query for cursor position. Not all respond so you have to time out if you get nothing back.

    If the connection is over SSL there are similar ways to ask -- and the ANSI ESC trick can still be used.

    ENiGMA offers ways to ask the system itself what the user currently has and I imagine many others do as well -- but of course if you've left to a door already that could be lost.

    Older door.sys formats and some others included some of this information. Not present in door32 or dorinfo#.def though =) Perhaps querying the system and passing it at the command line.

    ...so again, it's complicated :D




    --
    |08 ■ |12NuSkooler |06// |12Xibalba |08- |07"|06The place of fear|07"
    |08 ■ |03xibalba|08.|03l33t|08.|03codes |08(|0344510|08/|03telnet|08, |0344511|08/|03ssh|08)
    |08 ■ |03ENiGMA 1/2 WHQ |08| |03Phenom |08| |0367 |08| |03iMPURE |08| |03ACiDic
    --- ENiGMA 1/2 v0.0.12-beta (linux; x64; 14.15.4)
    * Origin: Xibalba -+- xibalba.l33t.codes:44510 (21:1/121)
  • From fusion@21:1/616 to Alpha on Saturday, April 03, 2021 12:54:38
    On 03 Apr 2021, Alpha said the following...

    Working on a little ansi art door and i'd like to be able to serve the 80 or 132 columns version automatically.

    set the cursor position to 999999 999999 and then ask where the cursor is :)

    --- Mystic BBS v1.12 A46 2020/08/26 (Windows/32)
    * Origin: cold fusion - cfbbs.net - grand rapids, mi (21:1/616)
  • From Alpha@21:4/158.1 to NuSkooler on Saturday, April 03, 2021 10:07:24
    For Telnet connections, you can ask for NAWS which some support. You
    can also ask for environment variables, which works for some terminals
    as well. There is also a trick that works for some: Move the cursor to
    a very large bottom right coordinate (I use 999,999) then issue a ANSI
    query for cursor position. Not all respond so you have to time out if
    you get nothing back.

    Super helpful. Thanks. Going to try both of these.

    ENiGMA offers ways to ask the system itself what the user currently
    has and I imagine many others do as well -- but of course if you've
    left to a door already that could be lost.

    Yeah, I was thinking there could be a system-by-system way to do this,
    whetehr it's a query or literally checking a preference setting/db.

    Older door.sys formats and some others included some of this
    information. Not present in door32 or dorinfo#.def though =) Perhaps querying the system and passing it at the command line.

    Right, and then it would still be up to each BBS author to make sure this
    info is dumped into the file.

    ...so again, it's complicated :D

    I worried this would be the case. I may just add a toggle at launch for
    the user: e.g. "select 80 or 132" but feels like an extra step for the
    user if that info already exisits somwhere.

    I know in some cases, like menus, the system chooses automatically. But
    given this is a door, I might be outta luck in terms of elegance :)

    Thank you!



    |08---
    |15++ |13Alpha |15++
    |03TheDrunkenGamer.com|08:|078888
    |08A Talisman BBS


    --- Talisman v0.16-dev (Linux/x86_64)
    * Origin: The Drunken Gamer BBS (21:4/158.1)
  • From echicken@21:1/164 to Alpha on Monday, April 05, 2021 15:55:15
    Re: Reliable way to get term size
    By: Alpha to All on Sat Apr 03 2021 08:51:06

    Looking for a way to consistently get a user's screen/term size/mode that works across Syncterm, netRunner, MagiTerm, etc.

    The normal way would be to send the cursor to row 255, column 255 (esc[255;255H), then request the cursor position from the terminal (esc[6n) and parse the response (esc[row;columnR).

    Some terminals may not handle values > 255 gracefully. I don't think many people are using a 255x255 terminal (or larger) anyway.

    If the terminal is smaller than the requested position, the expected behaviour is that the cursor would go to the very bottom right.

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    * Origin: electronic chicken bbs - bbs.electronicchicken.com (21:1/164)
  • From NuSkooler@21:1/121 to echicken on Monday, April 05, 2021 16:29:37

    On Monday, April 5th echicken was heard saying...
    The normal way would be to send the cursor to row 255, column 255 (esc[255;255H), then request the cursor position from the terminal (esc[6n) and parse the response (esc[row;columnR).

    At one point I was using 255,255 for ENiG then switched it to 999,999 and I can't remember at all why. I _think_ I may have run into it with a full screen Linux telnet session where 255 wasn't big enough?

    But I do imagine some software isn't too happy with it if they try to store the value in a byte :)



    --
    |08 ■ |12NuSkooler |06// |12Xibalba |08- |07"|06The place of fear|07"
    |08 ■ |03xibalba|08.|03l33t|08.|03codes |08(|0344510|08/|03telnet|08, |0344511|08/|03ssh|08)
    |08 ■ |03ENiGMA 1/2 WHQ |08| |03Phenom |08| |0367 |08| |03iMPURE |08| |03ACiDic
    --- ENiGMA 1/2 v0.0.12-beta (linux; x64; 14.15.4)
    * Origin: Xibalba -+- xibalba.l33t.codes:44510 (21:1/121)
  • From Alpha@21:4/158 to echicken on Tuesday, April 06, 2021 02:14:50
    Some terminals may not handle values > 255 gracefully. I don't think many people are using a 255x255 terminal (or larger) anyway.

    If the terminal is smaller than the requested position, the expected behaviour is that the cursor would go to the very bottom right.

    thanks, echicken... Will give it a go.

    -+-+-
    Alpha
    -+-+-
    --- SBBSecho 3.13-Linux
    * Origin: ALPHACOMPLEX.US (21:4/158)
  • From echicken@21:1/164 to NuSkooler on Tuesday, April 06, 2021 02:47:20
    Re: RE: Reliable way to get term size
    By: NuSkooler to echicken on Mon Apr 05 2021 16:29:37

    At one point I was using 255,255 for ENiG then switched it to 999,999 and I can't remember at all why. I _think_ I may have run into it with a full screen Linux telnet session where 255 wasn't big enough?

    I could've sworn I'd seen it specified somewhere that 255 was the max for those parameters, but now I'm unable to find that. 999 is better, if still a guess, and if it doesn't break anything.

    I'm now imagining the "best" way to find width and height without relying on some hard-coded value. Send the cursor to 255;255, get a position report. If the row is reported as 255, tell the cursor to go down another 255 rows, and repeat until the reported row stops changing. Same goes for column.

    All of this because "cursor home" is a thing but "cursor end" is not. :|

    ---
    echicken
    electronic chicken bbs - bbs.electronicchicken.com
    * Origin: electronic chicken bbs - bbs.electronicchicken.com (21:1/164)
  • From NuSkooler@21:1/121 to echicken on Wednesday, April 07, 2021 17:03:50

    On Tuesday, April 6th echicken muttered...
    All of this because "cursor home" is a thing but "cursor end" is not. :|

    FWIW there is also an unofficial ESC that at least some terminals support (e.g. SyncTERM) to report the size directly:

    ESC[255n

    ENiG will try that one as a fallback to NAWS before the 999,999 trick. From cterm.txt:

    255 - NON-STANDARD EXTENSION (BCDSR)
    Replies as though a CSI 6 n was received with the cursor in
    the bottom right corner. i.e.: Returns the terminal size as
    a position report.



    --
    |08 ■ |12NuSkooler |06// |12Xibalba |08- |07"|06The place of fear|07"
    |08 ■ |03xibalba|08.|03l33t|08.|03codes |08(|0344510|08/|03telnet|08, |0344511|08/|03ssh|08)
    |08 ■ |03ENiGMA 1/2 WHQ |08| |03Phenom |08| |0367 |08| |03iMPURE |08| |03ACiDic
    --- ENiGMA 1/2 v0.0.12-beta (linux; x64; 14.15.4)
    * Origin: Xibalba -+- xibalba.l33t.codes:44510 (21:1/121)