test.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from tornado import gen
  2. from tornado.ioloop import IOLoop
  3. from tornado import websocket
  4. import json
  5. from wsrepl.ioloop import start_ioloop
  6. from wsrepl.interact import *
  7. from wsrepl.output import *
  8. from tornado.gen import sleep
  9. # 业务逻辑 协程
  10. async def say_hello():
  11. """
  12. 有返回值的交互函数需要yield from
  13. :return:
  14. """
  15. set_title("This is title")
  16. # 向用户输出文字
  17. text_print("Welcome!!!")
  18. put_table([[str(i)] * 4 for i in range(5)])
  19. res = await textarea('Text area', value='value',codemirror={
  20. 'mode': "python",
  21. 'theme': 'darcula', # 使用monokai模版 ,darcula:IDEA,
  22. })
  23. text_print(res)
  24. res = await actions('Action button', [
  25. {'value': '1', 'label': 'One', 'disabled': False},
  26. {'value': '2', 'label': 'Two', 'disabled': False},
  27. {'value': '3', 'label': 'Three', 'disabled': True},
  28. ])
  29. text_print('Your input:%s' % res)
  30. res = await select('This is select input', [
  31. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  32. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  33. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  34. ], type=SELECT, multiple=False)
  35. text_print('Your input:%s' % res)
  36. res = await select('This is multiple select input', [
  37. {'value': 1, 'label': 'one', 'selected': True, 'disabled': False},
  38. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  39. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  40. ], type=SELECT, multiple=True)
  41. text_print('Your input:%s' % res)
  42. res = await select('This is RADIO input', [
  43. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  44. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  45. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  46. ], type=RADIO)
  47. text_print('Your input:%s' % res)
  48. res = await select('This is CHECKBOX input', [
  49. {'value': 1, 'label': 'one', 'selected': False, 'disabled': False},
  50. {'value': 2, 'label': 'two', 'selected': True, 'disabled': False},
  51. {'value': 2, 'label': 'three disabled', 'selected': False, 'disabled': True},
  52. ], type=CHECKBOX)
  53. text_print('Your input:%s' % res)
  54. res = await input('This is single input')
  55. text_print('Your input:%s' % res)
  56. res = await input('This is another single input')
  57. text_print('Your input:%s' % res)
  58. res = await input_group('Group input', [
  59. input('Input 1', name='one'),
  60. input('Input 2', name='two'),
  61. select('Input 2', options=['A', 'B', 'C'], type=CHECKBOX, name='three')
  62. ])
  63. text_print('Your input:')
  64. json_print(res)
  65. start_ioloop(say_hello)