not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. print ('<h2>🐍 RapydScript ' + parent.RapydScript.rs_version + '</h2>', end='')
  2. print ('Javascript Programming in Python Activity <i>(Jappy)</i>')
  3. print ('<hr>', end='')
  4. callcount = 1
  5. callhistory = []
  6. backscroll = 1
  7. # Read
  8. editbox = inputAsync(interpret)
  9. editbox.addEventListener("keyup", scrollback)
  10. def scrollback(e):
  11. global backscroll, callcount
  12. if e.keyCode == 38: # Up arrow
  13. if backscroll < callcount:
  14. backscroll = backscroll + 1
  15. editbox.value = callhistory[callcount-backscroll]
  16. elif e.keyCode == 40: # Down arrow
  17. if backscroll > 1:
  18. backscroll = backscroll - 1
  19. editbox.value = callhistory[callcount-backscroll-1]
  20. # Evaluate
  21. def interpret(line):
  22. if not line:
  23. return False
  24. global callcount
  25. print (line)
  26. try:
  27. callhistory.push(line)
  28. line = parent.compile(line)
  29. result = window.eval(line)
  30. if result is not undefined:
  31. printout(result)
  32. except Exception as e:
  33. print (e)
  34. callcount = callcount + 1
  35. printin()
  36. editbox.value = ''
  37. return False
  38. # Print
  39. def printout(result):
  40. print ('Out[' + callcount + ']: ' + result)
  41. def printin():
  42. print ('<br><b>In [' + callcount + '] ⏩ </b>', end='')
  43. printin()