<commit_before>-- Displays the mouse (grid) coordinates when the mouse is clicked

local active
local last_msg
if active == nil then active = false end

function set_timeout()
    dfhack.timeout(1, 'frames', check_click)
end

function log(s, color)
    -- prevent duplicate output
    if s ~= last_msg then
        dfhack.color(color)
        print(s)
        last_msg = s
    end
end

function check_click()
    local s = ''
    local color = COLOR_RESET
    for _, attr in pairs({'mouse_lbut', 'mouse_rbut', 'mouse_lbut_down',
        'mouse_rbut_down', 'mouse_lbut_lift', 'mouse_rbut_lift'}) do
        if df.global.enabler[attr] ~= 0 then
            s = s .. '[' .. attr:sub(7) .. ']  '
        end
    end
    if s ~= '' then
        s = ('x = %2i, y = %2i  '):format(df.global.gps.mouse_x, df.global.gps.mouse_y) .. s
        if s:find('rbut') then
            color = (s:find('lbut') and COLOR_GREEN) or COLOR_BLUE
        end
        if df.global.gps.mouse_x == -1 then color = COLOR_RED end
        log(s, color)
    else
        last_msg = nil
    end
    if active then set_timeout() end
end

function usage()
    print [[
Usage:
    click-monitor start: Begin monitoring
    click-monitor stop: End monitoring
]]
end

args = {...}
if #args == 1 then
    if args[1] == 'start' then
        active = true
        set_timeout()
    elseif args[1] == 'stop' then
        active = false
    else
        usage()
    end
else
    usage()
end
<commit_msg>Prevent globals from being reset<commit_after>-- Displays the mouse (grid) coordinates when the mouse is clicked

if active == nil then active = false end

function set_timeout()
    dfhack.timeout(1, 'frames', check_click)
end

function log(s, color)
    -- prevent duplicate output
    if s ~= last_msg then
        dfhack.color(color)
        print(s)
        last_msg = s
    end
end

function check_click()
    local s = ''
    local color = COLOR_RESET
    for _, attr in pairs({'mouse_lbut', 'mouse_rbut', 'mouse_lbut_down',
        'mouse_rbut_down', 'mouse_lbut_lift', 'mouse_rbut_lift'}) do
        if df.global.enabler[attr] ~= 0 then
            s = s .. '[' .. attr:sub(7) .. ']  '
        end
    end
    if s ~= '' then
        s = ('x = %2i, y = %2i  '):format(df.global.gps.mouse_x, df.global.gps.mouse_y) .. s
        if s:find('rbut') then
            color = (s:find('lbut') and COLOR_GREEN) or COLOR_BLUE
        end
        if df.global.gps.mouse_x == -1 then color = COLOR_RED end
        log(s, color)
    else
        last_msg = nil
    end
    if active then set_timeout() end
end

function usage()
    print [[
Usage:
    click-monitor start: Begin monitoring
    click-monitor stop: End monitoring
]]
end

args = {...}
if #args == 1 then
    if args[1] == 'start' then
        active = true
        set_timeout()
    elseif args[1] == 'stop' then
        active = false
    else
        usage()
    end
else
    usage()
end

{'fraction_non_alphanumeric': 0.11946446961894953, 'fraction_numerical': 0.006179196704428424, 'mean_word_length': 2.2057205720572055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1629771', 'n_tokens_mistral': 997, 'n_tokens_neox': 992, 'n_words': 294}