1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Roll your own internal variables

Discussion in 'T&T - Miscellaneous' started by MaartenG, Feb 8, 2017.

  1. MaartenG

    Joined:
    Aug 3, 2016
    Messages:
    358
    Likes Received:
    8
    This one was so obvious that I overlooked it. In the case I'm not the only one: here you go ...

    Best illustrated with an example.
    For a .btm script to resize/reposition the current TCC window, I had to calculate the visible number of rows and columns in the current window. That can be done like this:

    set VISIBLE_WIDTH=%@eval[%@word[",",1,%@winclientsize[=%_pid]] / %@font[1]]

    Never mind this specific command. The formula itself isn't important.
    As this had to do be done multiple times, it became (eventually :-):

    set _VISIBLE_WIDTH=%%@eval[%%@word[",",1,%%@winclientsize[=%%_pid]] / %%@font[1]]

    The important difference: %'s are converted to %%.

    Now you can echo %_VISIBLE_WIDTH and and it will be calculated "just in time".
    That can be illustrated with the command SET _VISIBLE_WIDTH
    It gives you the "formula" and not the "answer".


    Another example, now with an external program (from the same btm)

    You can get the current screen buffer size with something like:

    mode con | ffind /km /t"Columns" | echo %@trim[ %@word[":",1,%@line[con,0]] ]

    Again, the formula itself isn't that important.
    Turned into an "internal variable":

    set _BUFFER_WIDTH=%%@execstr[( mode con ^| ffind /km /t"Columns" ^| echo %%@trim[ %%@word[":",1,%%@line[con,0]] ] )]
     
    #1 MaartenG, Feb 8, 2017
    Last edited: Feb 8, 2017
    Joe Caverly likes this.

Share This Page