<commit_before>import logging
import os
import sys


def handle(term, context, cap_turple):
    light = False
    color_idx = 0

    cap_name, increase = cap_turple

    if increase:
        for idx in range(len(context.params)):
            context.params[idx] -= 1

    mode = -1
    f_color_idx = -2
    b_color_idx = -2
    
    for v in context.params:
        if v == 0:
            #reset
            term.origin_pair()
        elif v >= 1 and v <= 8:
            #mode
            if mode < 0:
                mode = 0

            if v == 1:
                mode |= 1
            else:
                mode |= (1 << v)
        elif (v >= 30 and v <= 37) or (v >= 90 and v <= 97):
            #foreground
            f_color_idx = v % 10 + (8 if v >= 90 else 0)
        elif (v >= 40 and v <= 47) or (v >= 100 and v <= 107):
            #background
            b_color_idx = v % 10 + (8 if v >= 100 else 0)
    logging.getLogger('set_attributes').debug('params={} mode={} f_color={} b_color={}'.format(context.params, mode, f_color_idx, b_color_idx))

    if not (mode == -1 and f_color_idx == -2 and b_color_idx == -2):
        term.set_attributes(mode, f_color_idx, b_color_idx)
<commit_msg>\e]39m and \e]49m should independently reset foreground and background to defaults, now fixed<commit_after>import logging
import os
import sys


def handle(term, context, cap_turple):
    light = False
    color_idx = 0

    cap_name, increase = cap_turple

    if increase:
        for idx in range(len(context.params)):
            context.params[idx] -= 1

    mode = -1
    f_color_idx = -2
    b_color_idx = -2
    
    for v in context.params:
        if v == 0:
            #reset
            term.origin_pair()
        elif v >= 1 and v <= 8:
            #mode
            if mode < 0:
                mode = 0

            if v == 1:
                mode |= 1
            else:
                mode |= (1 << v)
        elif v == 39:
            #reset foreground
            f_color_idx = -1
        elif v == 49:
            #reset background
            b_color_idx = -1
        elif (v >= 30 and v <= 37) or (v >= 90 and v <= 97):
            #foreground
            f_color_idx = v % 10 + (8 if v >= 90 else 0)
        elif (v >= 40 and v <= 47) or (v >= 100 and v <= 107):
            #background
            b_color_idx = v % 10 + (8 if v >= 100 else 0)
    logging.getLogger('set_attributes').debug('params={} mode={} f_color={} b_color={}'.format(context.params, mode, f_color_idx, b_color_idx))

    if not (mode == -1 and f_color_idx == -2 and b_color_idx == -2):
        term.set_attributes(mode, f_color_idx, b_color_idx)

{'fraction_non_alphanumeric': 0.11448427212874908, 'fraction_numerical': 0.038039502560351136, 'mean_word_length': 1.4841053587647592, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, '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': '6485890', 'n_tokens_mistral': 997, 'n_tokens_neox': 841, 'n_words': 276}