Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import colorama as c
  2.  
  3. CMD = 1
  4. EQ = 2
  5. NUM = 3
  6. FONT = 4
  7.  
  8. RULES = [[CMD,EQ,NUM],
  9.          [FONT,EQ,NUM]]
  10. command = 0
  11. def font(f,cr):
  12.     return '\033[' + str(f) + ';' + str(cr) + ';40m'
  13.  
  14. def parse(txt):
  15.     command = 0
  16.     newTxt = txt.split(' ')
  17.     tokens = []
  18.     for i in newTxt:
  19.         if i == 'color': tokens.append(CMD); command = 1
  20.         elif i == 'font': tokens.append(FONT); command = 2
  21.         elif i == '=': tokens.append(EQ)
  22.         elif i.isdigit(): tokens.append(NUM)
  23.     return tokens,command
  24.  
  25. def syntax(tokens):
  26.     I = 0
  27.     i = 0
  28.     if tokens:
  29.         while I < len(tokens) and I < len(RULES[i]):
  30.             if tokens[I] == RULES[i][I]:
  31.                 I += 1
  32.             else:
  33.                 I = 0
  34.                 i += 1
  35.         print('String Accepted')
  36.         return True
  37.  
  38. play = True
  39. newColor = 0
  40. newFont = 0
  41. while play:
  42.     inp = input()
  43.     if inp == 'q': exit()
  44.     token,command = parse(inp)
  45.     if syntax(token):
  46.         newT = inp.split(' ')
  47.         if command == 2:
  48.             newFont = int(newT[len(newT) - 1])
  49.         elif command == 1:
  50.             newColor = int(newT[len(newT) - 1])
  51.        
  52.     if newFont > 1:
  53.         print(font(newFont,newColor)+inp+'\033[0;37;40m')
  54.     else:
  55.         print(font(newFont,newColor)+inp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement