scandum / tintin

TinTin++, aka tt++, is an extensible console MUD client.
https://tintin.mudhalla.net
GNU General Public License v3.0
199 stars 56 forks source link

Feature request: #info config save by key name #171

Closed rigrig closed 1 year ago

rigrig commented 1 year ago

Currently #info configs save stores configs as a numbered list:

#info configs save
#INFO: DATA WRITTEN TO {info[CONFIGS]}
#var info
#VARIABLE {info}
{
    {CONFIGS} 
    {
        {1} 
        {
            {arg1} {AUTO TAB}
            {arg2} {5000}
            {arg3} {}
            {arg4} {}
            {class} {}
            {nest} {0}
            {shots} {0}
        }
        {2} 
        {
            {arg1} {BUFFER SIZE}
            {arg2} {10000}
            {arg3} {}

Could it maybe work just like #info system save?

#info system save
#INFO: DATA WRITTEN TO {info[SYSTEM]}
#var info
#VARIABLE {info}
{
    {SYSTEM} 
    {
        {ATTACH_FILE} {}
        {CLIENT_NAME} {TinTin++}
        {CLIENT_VERSION} {2.02.30 }
        {CWD} {/home/richard/.dw}
        {DETACH_FILE} {}
        {EXEC} {tt++}
        {HOME} {/home/richard}
        {LANG} {en_US.UTF-8}
        {OS} {UNKNOWN}
        {PID} {3439340}
        {TERM} {xterm-256color}
        {TINTIN} {/home/richard/.tintin}
    }
}

I'd like to check if SCREEN READER is enabled. I can loop over $info[CONFIGS], but it would be easier if $info[CONFIGS][SCREEN READER] just worked.

scandum commented 1 year ago

That's not possible since I handle the default lists in a generic manner. One option is:

#info configs save
#list info[CONFIGS] indexate arg1
#list info[CONFIGS] filter {SCREEN READER}
#var screen_reader $info[CONFIGS][1][arg2]

I've updated the beta to save the MTTS bitvector with #info session save.

https://tintin.mudhalla.net/protocols/mtts/

#info session save
#math screen_reader $info[SESSION][MTTS] & 64

Will set $screen_reader to 0 if disabled, 64 if enabled.

rigrig commented 1 year ago

Thanks, I'm handling it in the script now, just figured it'd be easier if TinTin++ stored it in that format right away, but no need to mess up generic code for it ;-)

I'm not sure why I'd want the MTTS bitvector? It's really to check if the user of my script has enabled screenreader mode, so I can disable e.g. updating some status counters every second (as the screenreader would announce every update)

In case anybody else stumbles on this, I'm doing this now:

#info configs save;
#local configs {};
#foreach {*info[CONFIGS][]} num {
    #local config $info[CONFIGS][$num];
    #local key {$config[arg1]};
    #local val {$config[arg2]};
    #var configs[$key] {$val};
};
#var info[CONFIGS] $configs;
#unvar configs;

Giving

#var info;
#VARIABLE {info}
{
    {CONFIGS} 
    {
        {AUTO TAB} {5000}
        {BUFFER SIZE} {10000}
        {CHARSET} {UTF-8}
        {COLOR MODE} {TRUE}
        {COLOR PATCH} {OFF}
        {COMMAND COLOR} {\e[0;37m}
        {COMMAND ECHO} {ON}
        {CONNECT RETRY} {0.0}
        {HISTORY SIZE} {1000}
        {LOG MODE} {RAW}
        {MOUSE} {OFF}
        {PACKET PATCH} {AUTO OFF}
        {RANDOM SEED} {459926859}
        {REPEAT CHAR} {!}
        {REPEAT ENTER} {OFF}
        {SCREEN READER} {OFF}
        {SCROLL LOCK} {ON}
        {SPEEDWALK} {OFF}
        {TAB WIDTH} {8}
        {TELNET} {ON}
        {TINTIN CHAR} {#}
        {VERBATIM} {OFF}
        {VERBATIM CHAR} {\}
        {VERBOSE} {OFF}
        {WORDWRAP} {ON}
    }
}
scandum commented 1 year ago

Alternatively:

#info configs save
#loop 1 &info[CONFIGS][] index #var info[CONFIGS][$info[CONFIGS][$index][arg1]] $info[CONFIGS][$index][arg2]
#unvar info[CONFIGS][%+1..d]

As for the MTTS bitvector, it contains whether #config screen_reader is on or off, as well as a few other things. I may add an event for #config calls so it's possible to maintain an up to date table.