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.

55 lines
1.5 KiB

  1. from pythonize import strings
  2. strings()
  3. def input(*args):
  4. return prompt(args)
  5. def clearScreen(color=None):
  6. def clearScreenAsync():
  7. element = document.getElementById('__terminal__')
  8. if element:
  9. element.innerHTML = ''
  10. if color:
  11. document.body.style.backgroundColor = color
  12. setTimeout(clearScreenAsync)
  13. def onKeyUp(e):
  14. if e.keyCode == 13:
  15. e.target.dispatchEvent(new Event('submit'))
  16. def inputAsync(cb=None):
  17. el = document.createElement('input')
  18. el.className = '__terminal__'
  19. el.onsubmit = def(e):
  20. if cb:
  21. if cb(el.value) in [undefined, True]:
  22. e.target.parentNode.removeChild(el)
  23. def scrolldown():
  24. document.body.scrollTop = document.body.scrollHeight
  25. setTimeout(scrolldown)
  26. el.onkeyup = onKeyUp
  27. document.body.appendChild(el)
  28. el.focus()
  29. return el
  30. def ρσ_print(*args, **kwargs):
  31. end = "\n"
  32. sep = " "
  33. if 'end' in kwargs:
  34. end = kwargs['end']
  35. def printAsync():
  36. element = document.getElementById('__terminal__')
  37. if element:
  38. addition = sep.join([arg for arg in args]) + end
  39. previous = element.innerHTML
  40. element.innerHTML = previous + addition.replace('\n', '<br>')
  41. element.scrollTop = element.scrollHeight
  42. else:
  43. console.log (sep.join([str (arg) for arg in args]))
  44. setTimeout(printAsync)
  45. window.onerror = def(e):
  46. print(e)