 
QMKCodeDic = {
    #BASICKEYCODES
    "KC_NO":"Null",
    "XXXXXXX":"Null",
    "_______":"",
    "KC_TRNS":"",
    "KC_A":"A",
    "KC_B":"B",
    "KC_C":"C",
    "KC_D":"D",
    "KC_E":"E",
    "KC_F":"F",
    "KC_G":"G",
    "KC_H":"H",
    "KC_I":"I",
    "KC_J":"J",
    "KC_K":"K",
    "KC_L":"L",
    "KC_M":"M",
    "KC_N":"N",
    "KC_O":"O",
    "KC_P":"P",
    "KC_Q":"Q",
    "KC_R":"R",
    "KC_S":"S",
    "KC_T":"T",
    "KC_U":"U",
    "KC_V":"V",
    "KC_W":"W",
    "KC_X":"X",
    "KC_Y":"Y",
    "KC_Z":"Z",
    "KC_1":"1",
    "KC_2":"2",
    "KC_3":"3",
    "KC_4":"4",
    "KC_5":"5",
    "KC_6":"6",
    "KC_7":"7",
    "KC_8":"8",
    "KC_9":"9",
    "KC_0":"0",
    "KC_ENTER":"Enter",
    "KC_ENT":"Enter",
    "KC_ESC":"Esc",
    "KC_ESCAPE":"Esc",
    "KC_BSPACE":"Bksp",
    "KC_BSPC":"Bksp",
    "KC_TAB":"Tab",
    "KC_SPACE":"Space",
    "KC_SPC":"Space",
    "KC_MINUS":"-",
    "KC_MINS":"-",
    "KC_EQL":"=",
    "KC_EQUAL":"=",
    "KC_LBRACKET":"[",
    "KC_LBRC":"[",
    "KC_RBRACKET":"]",
    "KC_RBRC":"]",
    "KC_BSLASH":"",
    "KC_BSLS":"",
    "KC_NONUS_HASH":"#",
    "KC_NUHS":"#",
    "KC_SCOLON":";",
    "KC_SCLN":";",
    "KC_QUOTE":"'",
    "KC_QUOT":"'",
    "KC_GRAVE":"`",
    "KC_GRV":"`",
    "KC_COMMA":",",
    "KC_COMM":",",
    "KC_DOT":".",
    "KC_SLASH":"/",
    "KC_SLSH":"/",
    "KC_CAPSLOCK":"Caps",
    "KC_CLCK":"Caps",
    "KC_CAPS":"Caps",
    "KC_F1":"F1",
    "KC_F2":"F2",
    "KC_F3":"F3",
    "KC_F4":"F4",
    "KC_F5":"F5",
    "KC_F6":"F6",
    "KC_F7":"F7",
    "KC_F8":"F8",
    "KC_F9":"F9",
    "KC_F10":"F10",
    "KC_F11":"F11",
    "KC_F12":"F12",
    "KC_PSCREEN":"PrtScn",
    "KC_PSCR":"PrtScn",
    "KC_SCROLLLOCK":"SclLk",
    "KC_SLCK":"ScrLk",
    "KC_PAUSE":"Paus",
    "KC_PAUS":"Paus",
    "KC_BRK":"Break",
    "KC_INSERT":"Break",
    "KC_INS":"Ins",
    "KC_HOME":"Home",
    "KC_PGUP":"PgUp",
    "KC_PGDN":"PgDn",
    "KC_DELETE":"Del",
    "KC_DEL":"Del",
    "KC_END":"End",
    "KC_PGDOWN":"PgUp",
    "KC_RIGHT":"Right",
    "KC_RGHT":"Right",
    "KC_LEFT":"Left",
    "KC_UP":"Up",
    "KC_DOWN":"Down",
    "KC_NUMLOCK":"#Lk",
    "KC_NLCK":"#Lk",
    "KC_KP_SLASH":"/",
    "KC_PSLS":"/",
    "KC_KP_ASTERISK":"*",
    "KC_PAST":"*",
    "KC_KP_MINUS":"-",
    "KC_PMNS":"-",
    "KC_KP_PLUS":"+",
    "KC_PPLS":"+",
    "KC_KP_ENTER":"Entr",
    "KC_PENT":"Entr",
    "KC_KP_1":"1",
    "KC_P1":"1",
    "KC_KP_2":"2",
    "KC_P2":"2",
    "KC_KP_3":"3",
    "KC_P3":"3",
    "KC_KP_4":"4",
    "KC_P4":"4",
    "KC_KP_5":"5",
    "KC_P5":"5",
    "KC_KP_6":"6",
    "KC_P6":"6",
    "KC_KP_7":"7",
    "KC_P7":"7",
    "KC_KP_8":"8",
    "KC_P8":"8",
    "KC_KP_9":"9",
    "KC_P9":"9",
    "KC_KP_0":"0",
    "KC_P0":"0",
    "KC_KP_DOT":".",
    "KC_PDOT":".",
    "KC_NONUS_BSLASH":"",
    "KC_NUBS":"",
    "KC_APPLICATION":"App",
    "KC_APP":"App",
    "KC_POWER":"Pwr",
    "KC_KP_EQUAL":"=",
    "KC_PEQL":"=",
    "KC_F13":"F13",
    "KC_F14":"F14",
    "KC_F15":"F15",
    "KC_F16":"F16",
    "KC_F17":"F17",
    "KC_F18":"F18",
    "KC_F19":"F19",
    "KC_F20":"F20",
    "KC_F21":"F21",
    "KC_F22":"F22",
    "KC_F23":"F23",
    "KC_F24":"F24",
    "KC_EXECUTE":"Exec",
    "KC_EXEC":"Exec",
    "KC_HELP":"Help",
    "KC_MENU":"Menu",
    "KC_SELECT":"Slct",
    "KC_SLCT":"Slct",
    "KC_STOP":"Stop",
    "KC_AGAIN":"Again",
    "KC_AGIN":"Again",
    "KC_UNDO":"Undo",
    "KC_CUT":"Cut",
    "KC_COPY":"Copy",
    "KC_PASTE":"Paste",
    "KC_PSTE":"Paste",
    "KC_FIND":"Find",
    "KC__MUTE":"Mute",
    "KC__VOLUP":"Vol+",
    "KC__VOLDOWN":"Vol-",
    "KC_LOCKING_CAPS":"Caps",
    "KC_LCAP":"Caps",
    "KC_LOCKING_NUM":"#Lk",
    "KC_LNUM":"#Lk",
    "KC_LOCKING_SCROLL":"LkScr",
    "KC_LSCR":"LkScr",
    "KC_KP_COMMA":"KP_Com",
    "KC_PCMM":"REPLACE",
    "KC_KP_EQUAL_AS400":"=",
    "KC_INT1":"",
    "KC_RO":"",
    "KC_INT2":"Kata",
    "KC_KANA":"Kata",
    "KC_INT3":"¥",
    "KC_JYEN":"¥",
    "KC_INT4":"Henk",
    "KC_HENK":"Henk",
    "KC_INT5":"Muhn",
    "KC_MHEN":"Muhn",
    "KC_INT6":"",
    "KC_INT7":"Int7",
    "KC_INT8":"Int8",
    "KC_INT9":"Int9",
    "KC_LANG1":"En/Ha",
    "KC_HAEN":"En/Ha",
    "KC_LANG2":"Hanja",
    "KC_HANJ":"Hanja",
    "KC_LANG3":"Kata",
    "KC_LANG4":"Hira",
    "KC_LANG5":"Zenk",
    "KC_LANG6":"Lang6",
    "KC_LANG7":"Lang7",
    "KC_LANG8":"Lang8",
    "KC_LANG9":"Lang9",
    "KC_ALT_ERASE":"Erase",
    "KC_ERAS":"Erase",
    "KC_SYSREQ":"Attn",
    "KC_CANCEL":"Cncl",
    "KC_CLEAR":"Clr",
    "KC_CLR":"Clr",
    "KC_PRIOR":"Prior",
    "KC_RETURN":"Rtrn",
    "KC_SEPARATOR":"Sep",
    "KC_OUT":"Out",
    "KC_OPER":"Oper",
    "KC_CLEAR_AGAIN":"ClAg",
    "KC_EXSEL":"ExSel",
    "KC_LCTRL":"Ctrl",
    "KC_LCTL":"Ctrl",
    "KC_LSHIFT":"Shft",
    "KC_LSFT":"Shft",
    "KC_LALT":"Alt",
    "KC_LGUI":"Gui",
    "KC_LCMD":"Cmd",
    "KC_LWIN":"Win",
    "KC_RCTRL":"Ctrl",
    "KC_RCTL":"Ctrl",
    "KC_RSHIFT":"Shft",
    "KC_RSFT":"Shft",
    "KC_RALT":"Alt",
    "KC_ALGR":"Alt",
    "KC_RGUI":"Gui",
    "KC_RCMD":"Cmd",
    "KC_RWIN":"Win",
    "KC_SYSTEM_POWER":"Pwr",
    "KC_PWR":"Pwr",
    "KC_SYSTEM_SLEEP":"Sleep",
    "KC_SLEP":"Sleep",
    "KC_SYSTEM_WAKE":"Wake",
    "KC_WAKE":"Wake",
    "KC_AUDIO_MUTE":"Mute",
    "KC_MUTE":"Mute",
    "KC_AUDIO_VOL_UP":"Vol+",
    "KC_VOLU":"Vol+",
    "KC_AUDIO_VOL_DOWN":"Vol-",
    "KC_VOLD":"Vol-",
    "KC_MEDIA_NEXT_TRACK":"Next",
    "KC_MNXT":"Next",
    "KC_MEDIA_PREV_TRACK":"Prev",
    "KC_MPRV":"Prev",
    "KC_MEDIA_STOP":"Stop",
    "KC_MSTP":"Stop",
    "KC_MEDIA_PLAY_PAUSE":"Play",
    "KC_MPLY":"Play",
    "KC_MEDIA_SELECT":"Slct",
    "KC_MSEL":"Slct",
    "KC_MEDIA_EJECT":"Ejct",
    "KC_EJCT":"Ejct",
    "KC_MAIL":"Mail",
    "KC_CALCULATOR":"Calc",
    "KC_CALC":"Calc",
    "KC_MY_COMPUTER":"MyPC",
    "KC_MYCM":"MyPC",
    "KC_WWW_SEARCH":"Srch",
    "KC_WSCH":"Srch",
    "KC_WWW_HOME":"Home",
    "KC_WHOM":"Home",
    "KC_WWW_BACK":"Back",
    "KC_WBAK":"Back",
    "KC_WWW_FORWARD":"Frwd",
    "KC_WFWD":"Frwd",
    "KC_WWW_STOP":"Stop",
    "KC_WSTOP":"Stop",
    "KC_WWW_REFRESH":"Rfsh",
    "KC_WREF":"Rfsh",
    "KC_WWW_FAVORITES":"Fav",
    "KC_WFAV":"Fav",
    "KC_MEDIA_FAST_FORWARD":">>",
    "KC_MFFD":">>",
    "KC_MEDIA_REWIND":"<<",
    "KC_MRWD":"<<",
    "KC_BRIGHTNESS_UP":"Brt+",
    "KC_BRIU":"Brt+",
    "KC_BRIGHTNESS_DOWN":"Brt-",
    "KC_BRID":"Brt-",

    #QUANTUMKEYCODES
    "RESET":"Reset",
    "DEBUG":"Debug",
    "EEPROM_RESET":"EepRst",
    "EEP_RST":"EepRst",
    "KC_GESC":"`/Esc",
    "GRAVE_ESC":"`/Esc",
    "KC_LSPO":"Shf/(",
    "KC_RSPC":"Shf/)",
    "KC_LEAD":"Lead",
    "KC_LOCK":"Lock",

    #cantdothesern(M,MACROTAP),

    #AUDIOKEYS
    "AU_ON":"AuOn",
    "AU_OFF":"AuOff",
    "AU_TOG":"AuTog",
    "CLICKY_TOGGLE":"CkTog",
    "CK_TOGG":"CkTog",
    "CLICKY_UP":"CkUp",
    "CK_UP":"CkUp",
    "CLICKY_RESET":"CkRst",
    "CK_RST":"CkRst",
    "MU_ON":"MuOn",
    "MU_OFF":"MuOff",
    "MU_TOG":"MuTog",
    "MU_MOD":"MuMod",
    "MI_ON":"MiOn",
    "MI_OFF":"MiOff",
    "MUV_DE":"Voice-",
    "MUV_IN":"Voice+",

    #BACKLIGHTING
    "BL_TOGG":"BLTog",
    "BL_STEP":"BLStp",
    "BL_ON":"BLOn",
    "BL_OFF":"BLOff",
    "BL_INC":"BL+",
    "BL_DEC":"BL-",
    "BL_BRTG":"BLBrt",

    #BOOTMAGICNOTSUPPORTED

    #BLUETOOTH
    "OUT_AUTO":"Auto",
    "OUT_USB":"FUSB",
    "OUT_BT":"FBT",

    #LAYERSWITCHINGNOTSUPPORTED

    #MOUSEKEYS
    "KC_MS_UP":"MSUp",
    "KC_MS_U":"MSUp",
    "KC_MS_DOWN":"MSDw",
    "KC_MS_D":"MSDw",
    "KC_MS_LEFT":"MSLft",
    "KC_MS_L":"MSLf",
    "KC_MS_RIGHT":"MSRgt",
    "KC_MS_R":"MSRgt",
    "KC_MS_BTN1":"MSB1",
    "KC_BTN1":"MSB1",
    "KC_MS_BTN2":"MSB2",
    "KC_BTN2":"MSB2",
    "KC_MS_BTN3":"MSB3",
    "KC_BTN3":"MSB3",
    "KC_MS_BTN4":"MsB4",
    "KC_BTN4":"MSB4",
    "KC_MS_BTN5":"MSB5",
    "KC_BTN5":"MSB5",
    "KC_MS_WH_UP":"WHUp",
    "KC_WH_U":"WHUp",
    "KC_MS_WH_DOWN":"WHDw",
    "KC_WH_D":"WHDw",
    "KC_MS_WH_LEFT":"WHLft",
    "KC_WH_L":"WHLft",
    "KC_MS_WH_RIGHT":"WHRgt",
    "KC_WH_R":"WHLft",
    "KC_MS_ACCEL0":"Acl0",
    "KC_ACL0":"Acl0",
    "KC_MS_ACCEL1":"Acl1",
    "KC_ACL1":"Acl1",
    "KC_MS_ACCEL2":"Acl2",
    "KC_ACL2":"Acl2",

    #MODIFIERSNOTSUPPORTED

    #MOD-TAPKEYSNOTSUPPORTED

    #USANSISHIFTEDSYMBOLS
    "KC_TILDE":"~",
    "KC_TILD":"~",
    "KC_EXCLAIM":"!",
    "KC_EXLM":"!",
    "KC_AT":"@",
    "KC_HASH":"#",
    "KC_DOLLAR":"$",
    "KC_DLR":"$",
    "KC_PERCENT":"%",
    "KC_PERC":"%",
    "KC_CIRCUMFLEX":"^",
    "KC_CIRC":"^",
    "KC_AMPERSAND":"&",
    "KC_AMPR":"&",
    "KC_ASTERISK":"*",
    "KC_ASTR":"*",
    "KC_LEFT_PAREN":"(",
    "KC_LPRN":"(",
    "KC_RIGHT_PAREN":")",
    "KC_RPRN":")",
    "KC_UNDERSCORE":"_",
    "KC_UNDS":"_",
    "KC_PLUS":"+",
    "KC_LEFT_CURLY_BRACE":"{",
    "KC_LCBR":"{",
    "KC_RIGHT_CURLY_BRACE":"}",
    "KC_RCBR":"}",
    "KC_PIPE":"|",
    "KC_COLON":"",
    "KC_COLN":"",
    "KC_DOUBLE_QUOTE":"",
    "KC_DQUO":"",
    "KC_DQT":"",
    "KC_LEFT_ANGLE_BRACKET":"<",
    "KC_LABK":"<",
    "KC_LT":"<",
    "KC_RIGHT_ANGLE_BRACKET":">",
    "KC_RABK":">",
    "KC_GT":">",
    "KC_QUESTION":"?",
    "KC_QUES":"?",

    #ONESHOTKEYSNOTSUPPORTED

    #SWAPHANDS(SH_T(),NOTSUPPORTED),
    "SW_ON":"SWOn",
    "SW_OFF":"SWOff",
    "SH_MON":"SHMmt",
    "SH_MOFF":"SHMof",
    "SH_TG":"SHTog",
    "SH_TT":"SHTgM",

    #RGBCodes
    "RGB_TOG":"LdTog",
    "RGB_MODE_FORWARD":"LdM+",
    "RGB_MOD":"LdM+",
    "RGB_MODE_REVERSE":"LdM-",
    "RGB_RMOD":"LdM-",
    "RGB_HUI":"LdH+",
    "RGB_HUD":"LdH-",
    "RGB_SAI":"LdS+",
    "RGB_SAD":"LdS-",
    "RGB_VAI":"LdV+",
    "RGB_VAD":"LdV-",
    "RGB_SPI":"LdSp+",
    "RGB_SPD":"LdSp-",
    "RGB_MODE_PLAIN":"LdSt",
    "RGB_M_P":"LdSt",
    "RGB_MODE_BREATHE":"LdBr",
    "RGB_M_B":"LdBr",
    "RGB_MODE_RAINBOW":"LdRb",
    "RGB_M_R":"LdRb",
    "RGB_MODE_SWIRL":"LdSw",
    "RGB_M_SW":"LdSw",
    "RGB_MODE_SHAKE":"LdSh",
    "RGB_M_SH":"LdSh",
    "RGB_MODE_KNIGHT":"LdKn",
    "RGB_M_K":"LdKn",
    "RGB_MODE_XMAS":"LdXm",
    "RGB_M_X":"LdXm",
    "RGB_MODE_GRADIENT":"LdGd",
    "RGB_M_G":"LdGd",
    "RGB_MODE_RGBTEST":"LdTs",
    "RGB_M_T":"LdTs",
    "RGB_M_SN":"LdSn",

    #SPECIAL
    "BACKLIT":"Light",
    "MO(":"",
    "RAISE":"Raise",
    "LOWER":"Lower",
    "LT(_SPACEFN KC_SPC)":"SpcFN",
    "TG(7)":"Tg7",
    "TO(8)":"To8",
    "TO(0)":"To0",

    #THERMALPRINTER
    "PRINT_ON":"PrtOn",
    "PRINT_OFF":"PrtOff",

    #PLOVER
    "EXT_PLV":"Exit",

    #BOOTMAGIC?
    "AG_NORM":"AGNrm",
    "AG_SWAP":"AGSwp",
    "TERM_ON":"TermOn",
    "TERM_OFF":"TermOf",

    #UNICODETEMPSOLUTION
    "UC":"",

    #commonlayers
    "QWERTY":"Qwerty",
    "COLEMAK":"Colmak",
    "DVORAK":"Dvorak",
    "PLOVER":"Plover",

    #NONUSHASHANDSLASH
    "S(KC_NUHS)":"ISO#",
    "S(KC_NUBS)":"ISO/",
    "KC_CTCP":"Ctr/Cp",
    "KC_RSSH":"Shf/",

    #ENDINGREPLACEMENTS
    ")":"",
    "":"",
    "":"│",
    "REPLACE│":"",
    "Space│Space│":"Space│",
    "_":""
}

import json
import re

try:
    fileInput = open("keymap.c","r")
    fileInput = fileInput.readlines()

    

    layerStarts = False
    keymapStarts = False

    layers = []
    keymaps = []
    keymapTemp = []

    Btop='┬'      #top fill lines 
    Bmid='┼'     #middle row fill lines
    Blow='┴'


    file=open('comment.txt','w+',encoding='utf-8')
    file.write('\n')
    keycodesSpecial = []
    keycodesSpecialUnique = []

    for line in fileInput:
        line = line.replace('\n', '')
        line = line.replace('\\', '')
        line = line.replace(' ', '')
        if 0 >= len(line):
            continue
        if line[0] == '*' or line[0] == '/':
            continue
        
        if layerStarts == True and line.count('};'):
            layerStarts = False

        if layerStarts:
            line = line.replace(',', '')
            line = line.replace('_', '')
            layers.append(line)

        if line.count('layers{'):
            layerStarts = True

        if keymapStarts and line[0] == ')':
            print("Layer '{0}' have been added".format(keymapStarts),file=file)
            keymaps.append(keymapTemp)
            keymapStarts = False
            keymapTemp = []
            keycodesSpecialTemp = []

        if keymapStarts:
            if line[len(line)-1] == ',':
                line = line[:-1]
            keycodesSpecialTemp = re.findall("[A-Z]*\([^\)]*\)", line)
            line = re.sub("(?<=\([0-9]{1}),(?=[A-Z]*\_[A-Z]*\))", " ", line)
            line = re.sub("(?<=\([0-9]{2}),(?=[A-Z]*\_[A-Z]*\))", " ", line)
            #line = line.replace('1,KC_SPC', '1 KC_SPC')
            line = line.split(',')
            keymapTemp.append(line)
            keycodesSpecial.extend(keycodesSpecialTemp)
            keycodesSpecialUnique = list(set(keycodesSpecial))

            
        if len(layers) > 0 and layerStarts == False:
            for layer in layers:
                if line.count("[_{0}]".format(layer)):
                    keymapTemp.append(layer)
                    keymapStarts = layer
    
    for i in range(len(keycodesSpecialUnique)):
        keycodesSpecialUnique[i] = keycodesSpecialUnique[i].replace(",", " ")
        QMKCodeDic[keycodesSpecialUnique[i]] = keycodesSpecialUnique[i]
    
    assert len(layers) > 0, "No Layer Found"
    assert len(keymaps) > 0, "No Keymap Found"

    print('',file=file)


    try:
        with open("KeyboardLayout.json", "r+") as jsonfile:
            pass
    except:
        print('Generating layout file')
        with open("KeyboardLayout.json", "w") as jsonfile:
            print("{", file= jsonfile)
            KeymapLayout = keymaps[0][1:]
            rowIndex = 0
            for row in KeymapLayout:
                print("\"{0}\": ".format(rowIndex),file=jsonfile)
                print("{",file=jsonfile)
                keyIndex = 0
                for key in row:
                    print("\"{0}\": 1".format(keyIndex),file=jsonfile, end='')
                    if keyIndex != len(row)-1:
                        print(',',file=jsonfile, end='')
                    print(file=jsonfile)
                    keyIndex += 1
                print("}",file=jsonfile, end='')
                if rowIndex != len(keymaps[0])-2:
                    print(',',file=jsonfile, end='')
                print(file=jsonfile)
                rowIndex += 1
            print("}", file= jsonfile)
            jsonfile.close()
        print('Layout file generated, Modify KeyboardLayout.json, and re-run this script. \nRemeber this script does not supports keys sized in decimals USE INT NUMBER ONLY')

        
    with open("KeyboardLayout.json", "r") as jsonfile:
        layout = json.load(jsonfile)
        for keymap in keymaps:
            keysize = 2
            print("/* {0}".format(keymap[0]),file=file)

            print('',file=file)
            print(" * ┌", end='',file=file)  
            for i in range(len(keymap[1])-1): 
                for _ in range(7 * layout["{0}".format(0)]["{0}".format(i)] - 1):
                    print('─', end='', file=file)
                print(Btop, end='',file=file)  
            for _ in range(7 * layout["{0}".format(0)]["{0}".format(len(keymap[1])-1)] - 1):
                print('─', end='', file=file)
            print("┐", end='',file=file)

            
            for i in range(len(keymap)-1):
                keysize = 2
                print('',file=file)
                print(" * ", end='',file=file)
                print("│", end='',file=file)
                itemIndex = 0
                for item in keymap[i+1]:
                    spaces = int(((7 * layout["{0}".format(i)]["{0}".format(itemIndex)]  - 1 - len(QMKCodeDic[item]))) /2) + (len(QMKCodeDic[item]) - 1 + layout["{0}".format(i)]["{0}".format(itemIndex)])%2
                    for _ in range(spaces):
                        print(' ', end='', file=file) 
                    print(QMKCodeDic[item], end='',file=file) 
                    for _ in range(spaces - (len(QMKCodeDic[item]) - 1 + layout["{0}".format(i)]["{0}".format(itemIndex)])%2):
                        print(' ', end='', file=file)
                    print('│', end='',file=file) 
                    itemIndex += 1
                    
                
                print('',file=file)
                print(" * ", end='',file=file)
                print("", end='',file=file)
                itemIndex = 0
                for j in range(len(keymap[i+1])):
                    #print(j,len(keymap[i+1]), end='')
                    if j == 0 and i == len(keymap)-2:
                        print("└", end='',file=file)

                    elif j == 0:
                        print("├", end='',file=file)

                    elif j == len(keymap[i+1])-1 and i != len(keymap)-2:
                        for _ in range(7 * layout["{0}".format(i)]["{0}".format(itemIndex)] - 1):
                            print('─', end='', file=file)
                        print("┤", end='',file=file)
                        break

                    if  not i == 0 and (j == len(keymap[i+1])-1 and (j > len(keymap[i])-1 or i == len(keymap)-2)):
                        for _ in range(7 * layout["{0}".format(i)]["{0}".format(itemIndex)] - 1):
                            print('─', end='', file=file)
                        print("┘", end='',file=file)
                    elif i == len(keymap)-2 or j > len(keymap[i+2])-1:
                        for _ in range(7 * layout["{0}".format(i)]["{0}".format(itemIndex)] - 1):
                            print('─', end='', file=file)
                        print(Blow, end='',file=file)
                    else:
                        for _ in range(7 * layout["{0}".format(i)]["{0}".format(itemIndex)] - 1):
                            print('─', end='', file=file)
                        print(Bmid, end='',file=file)
                    itemIndex += 1

                if i == len(keymap)-2:
                    break

            print('',file=file)
            print(" */",file=file)
            print('',file=file)

        file.close()

except:
    print("You should execute this script the same directory where you keymap.c file is.")



