nimbox.nimble 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # vim: ft=nim
  2. import strutils
  3. version = "0.1.0"
  4. author = "Samadi van Koten"
  5. description = "A Rustbox-inspired termbox wrapper"
  6. license = "MIT"
  7. skipDirs = @["examples"]
  8. skipFiles = @["nimbox/.keep"]
  9. requires "nim >= 0.14.3"
  10. task wrap, "Create low-level termbox wrapper":
  11. when defined(windows):
  12. echo "\x1B[33mNimbox doesn't work on Windows, sorry!\x1B[0m"
  13. quit 1
  14. elif not defined(linux):
  15. echo "\x1B[31mNimbox has not been tested on " & hostOS & ". Proceed with caution!\x1B[0m"
  16. # Fix integer types
  17. var buf = """#ifdef C2NIM
  18. #mangle uint8_t uint8
  19. #mangle uint16_t uint16
  20. #mangle uint32_t uint32
  21. #mangle int8_t int8
  22. #mangle int16_t int16
  23. #mangle int32_t int32
  24. #endif
  25. """
  26. var skip = false
  27. var termbox = readFile("/usr/include/termbox.h")
  28. for line in termbox.splitLines():
  29. if skip:
  30. if line.startsWith("#endif"):
  31. skip = false
  32. elif line.startsWith("#if __GNUC__"):
  33. skip = true
  34. else:
  35. if line.startsWith("SO_IMPORT "):
  36. buf &= line.substr(10)
  37. else:
  38. buf &= line
  39. buf &= "\n"
  40. writeFile("/tmp/termbox.h", buf)
  41. exec "c2nim --header --skipcomments --ref --nep1 /tmp/termbox.h -o:nimbox/termbox.nim"
  42. var nimbuf = "{.passl: \"-Wl,-Bstatic -ltermbox -Wl,-Bdynamic\", emit: \"typedef struct tb_event tb_event;\".}\n"
  43. nimbuf &= readFile("nimbox/termbox.nim")
  44. writeFile("nimbox/termbox.nim", nimbuf)