Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import colorama as c
- CMD = 1
- EQ = 2
- NUM = 3
- FONT = 4
- RULES = [[CMD,EQ,NUM],
- [FONT,EQ,NUM]]
- command = 0
- def font(f,cr):
- return '\033[' + str(f) + ';' + str(cr) + ';40m'
- def parse(txt):
- command = 0
- newTxt = txt.split(' ')
- tokens = []
- for i in newTxt:
- if i == 'color': tokens.append(CMD); command = 1
- elif i == 'font': tokens.append(FONT); command = 2
- elif i == '=': tokens.append(EQ)
- elif i.isdigit(): tokens.append(NUM)
- return tokens,command
- def syntax(tokens):
- I = 0
- i = 0
- if tokens:
- while I < len(tokens) and I < len(RULES[i]):
- if tokens[I] == RULES[i][I]:
- I += 1
- else:
- I = 0
- i += 1
- print('String Accepted')
- return True
- play = True
- newColor = 0
- newFont = 0
- while play:
- inp = input()
- if inp == 'q': exit()
- token,command = parse(inp)
- if syntax(token):
- newT = inp.split(' ')
- if command == 2:
- newFont = int(newT[len(newT) - 1])
- elif command == 1:
- newColor = int(newT[len(newT) - 1])
- if newFont > 1:
- print(font(newFont,newColor)+inp+'\033[0;37;40m')
- else:
- print(font(newFont,newColor)+inp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement