<commit_before>import sys
import os
import subprocess
from enum import Enum

class Format:
    class Code(Enum):
        black   = 0
        red     = 1
        green   = 2
        yellow  = 3
        blue    = 4
        magenta = 5
        cyan    = 6
        white   = 7
        default = 9
    def __init__(self, fg, bg, fgbold=False, bgbold=False):
        self.fgval = self.Code[fg].value + 30
        self.bgval = self.Code[bg].value + 40
        if fgbold:
            self.fgval += 60
        if bgbold:
            self.bgval += 60
    def getEscapeSequence(self):
        return "%{\033["+str(self.fgval)+";"+str(self.bgval)+"m%}"


class Segment:
    def __init__(self, text, fmt):
        self.text = " " + text + " "
        self.fmt = fmt
    def getString(self, nextfmt):
        if nextfmt == None:
            if os.getenv('BACKGROUND') == 'light':
                bg = "107"
            else:
                bg = "100"
            return self.fmt.getEscapeSequence()+self.text+"%{\033["+str(self.fmt.bgval-10)+";"+bg+"m"+'\ue0b0'+"%}"
        else:
            return self.fmt.getEscapeSequence()+self.text+"%{\033["+str(self.fmt.bgval-10)+";"+str(nextfmt.bgval)+"m"+'\ue0b0'+"%}"

def resolve(segments):
    string = ""
    for i in range(len(segments)-1):
        string += segments[i].getString(segments[i+1].fmt)
    string += segments[-1].getString(None)
    return string + " "

segments = []
segments.append(Segment("%n@%m", Format('black', 'blue', False, True)))
segments.append(Segment("%2~", Format('black', 'blue', False, False)))

sys.stdout.write(resolve(segments))
<commit_msg>fixed a bug in the escape sequences<commit_after>import sys
import os
import subprocess
from enum import Enum

class Format:
    class Code(Enum):
        black   = 0
        red     = 1
        green   = 2
        yellow  = 3
        blue    = 4
        magenta = 5
        cyan    = 6
        white   = 7
        default = 9
    def __init__(self, fg, bg, fgbold=False, bgbold=False):
        self.fgval = self.Code[fg].value + 30
        self.bgval = self.Code[bg].value + 40
        if fgbold:
            self.fgval += 60
        if bgbold:
            self.bgval += 60
    def getEscapeSequence(self):
        return "%{\033["+str(self.fgval)+";"+str(self.bgval)+"m%}"


class Segment:
    def __init__(self, text, fmt):
        self.text = " " + text + " "
        self.fmt = fmt
    def getString(self, nextfmt):
        if nextfmt == None:
            if os.getenv('BACKGROUND') == 'light':
                bg = "107"
            else:
                bg = "100"
            return self.fmt.getEscapeSequence()+self.text+"%{\033["+str(self.fmt.bgval-10)+";"+bg+"m%}"+'\ue0b0'
        else:
            return self.fmt.getEscapeSequence()+self.text+"%{\033["+str(self.fmt.bgval-10)+";"+str(nextfmt.bgval)+"m%}"+'\ue0b0'

def resolve(segments):
    string = ""
    for i in range(len(segments)-1):
        string += segments[i].getString(segments[i+1].fmt)
    string += segments[-1].getString(None)
    return string + " "

segments = []
segments.append(Segment("%n@%m", Format('black', 'blue', False, True)))
segments.append(Segment("%2~", Format('black', 'blue', False, False)))

sys.stdout.write(resolve(segments))

{'fraction_non_alphanumeric': 0.16563658838071693, 'fraction_numerical': 0.027194066749072928, 'mean_word_length': 2.2081268582755205, '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': '3769322', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1084, 'n_words': 226}