92_picoterm.py 553 B

1234567891011121314151617181920212223
  1. import picoterm
  2. from vmath import rgb
  3. picoterm.enable_full_buffering_mode()
  4. bg = rgb(78, 118, 164)
  5. fg = rgb(200, 200, 0)
  6. text = "hello, \nworld"
  7. text = bg.ansi_bg(text)
  8. text = fg.ansi_fg(text)
  9. def ansi_italic(text: str):
  10. return f'\x1b[3m{text}\x1b[0m'
  11. text = ansi_italic(text) + '123'
  12. print(text)
  13. cpnts = picoterm.split_ansi_escaped_string(text)
  14. assert cpnts == ['\x1b[3m', '\x1b[38;2;200;200;0m', '\x1b[48;2;78;118;164m', 'hello, ', '\n', 'world', '\x1b[0m', '\x1b[0m', '\x1b[0m', '123']
  15. cpnts_join = ''.join(cpnts)
  16. assert cpnts_join == text