inline-sciter.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. import re
  3. def strip(s): return re.sub(r'\s+\n', '\n', re.sub(r'\n\s+', '\n', s))
  4. common_css = open('src/ui/common.css').read()
  5. common_tis = open('src/ui/common.tis', encoding='UTF8').read()
  6. index = open('src/ui/index.html').read() \
  7. .replace('@import url(index.css);', open('src/ui/index.css').read()) \
  8. .replace('include "index.tis";', open('src/ui/index.tis').read()) \
  9. .replace('include "msgbox.tis";', open('src/ui/msgbox.tis').read()) \
  10. .replace('include "ab.tis";', open('src/ui/ab.tis').read())
  11. remote = open('src/ui/remote.html').read() \
  12. .replace('@import url(remote.css);', open('src/ui/remote.css').read()) \
  13. .replace('@import url(header.css);', open('src/ui/header.css').read()) \
  14. .replace('@import url(file_transfer.css);', open('src/ui/file_transfer.css').read()) \
  15. .replace('include "remote.tis";', open('src/ui/remote.tis').read()) \
  16. .replace('include "msgbox.tis";', open('src/ui/msgbox.tis').read()) \
  17. .replace('include "grid.tis";', open('src/ui/grid.tis').read()) \
  18. .replace('include "header.tis";', open('src/ui/header.tis').read()) \
  19. .replace('include "file_transfer.tis";', open('src/ui/file_transfer.tis').read()) \
  20. .replace('include "port_forward.tis";', open('src/ui/port_forward.tis').read())
  21. chatbox = open('src/ui/chatbox.html').read()
  22. install = open('src/ui/install.html').read().replace('include "install.tis";', open('src/ui/install.tis').read())
  23. cm = open('src/ui/cm.html').read() \
  24. .replace('@import url(cm.css);', open('src/ui/cm.css').read()) \
  25. .replace('include "cm.tis";', open('src/ui/cm.tis').read())
  26. def compress(s):
  27. s = s.replace("\r\n", "\n")
  28. x = bytes(s, encoding='utf-8')
  29. return '&[u8; ' + str(len(x)) + '] = b"' + str(x)[2:-1].replace(r"\'", "'").replace(r'"',
  30. r'\"') + '"'
  31. with open('src/ui/inline.rs', 'wt') as fh:
  32. fh.write('const _COMMON_CSS: ' + compress(strip(common_css)) + ';\n')
  33. fh.write('const _COMMON_TIS: ' + compress(strip(common_tis)) + ';\n')
  34. fh.write('const _INDEX: ' + compress(strip(index)) + ';\n')
  35. fh.write('const _REMOTE: ' + compress(strip(remote)) + ';\n')
  36. fh.write('const _CHATBOX: ' + compress(strip(chatbox)) + ';\n')
  37. fh.write('const _INSTALL: ' + compress(strip(install)) + ';\n')
  38. fh.write('const _CONNECTION_MANAGER: ' + compress(strip(cm)) + ';\n')
  39. fh.write('''
  40. fn get(data: &[u8]) -> String {
  41. String::from_utf8_lossy(data).to_string()
  42. }
  43. fn replace(data: &[u8]) -> String {
  44. let css = get(&_COMMON_CSS[..]);
  45. let res = get(data).replace("@import url(common.css);", &css);
  46. let tis = get(&_COMMON_TIS[..]);
  47. res.replace("include \\\"common.tis\\\";", &tis)
  48. }
  49. #[inline]
  50. pub fn get_index() -> String {
  51. replace(&_INDEX[..])
  52. }
  53. #[inline]
  54. pub fn get_remote() -> String {
  55. replace(&_REMOTE[..])
  56. }
  57. #[inline]
  58. pub fn get_install() -> String {
  59. replace(&_INSTALL[..])
  60. }
  61. #[inline]
  62. pub fn get_chatbox() -> String {
  63. replace(&_CHATBOX[..])
  64. }
  65. #[inline]
  66. pub fn get_cm() -> String {
  67. replace(&_CONNECTION_MANAGER[..])
  68. }
  69. ''')