update_terminfo.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env bash
  2. #
  3. # usage: ./scripts/update_terminfo.sh
  4. #
  5. # This script does:
  6. #
  7. # 1. Download Dickey's terminfo.src
  8. # 2. Compile temporary terminfo database from terminfo.src
  9. # 3. Use database to generate src/nvim/tui/terminfo_defs.h
  10. #
  11. set -e
  12. url='https://invisible-island.net/datafiles/current/terminfo.src.gz'
  13. target='src/nvim/tui/terminfo_defs.h'
  14. readonly -A entries=(
  15. [ansi]=ansi_terminfo
  16. [interix]=interix_8colour_terminfo
  17. [iterm2]=iterm_256colour_terminfo
  18. [linux]=linux_16colour_terminfo
  19. [putty-256color]=putty_256colour_terminfo
  20. [rxvt-256color]=rxvt_256colour_terminfo
  21. [screen-256color]=screen_256colour_terminfo
  22. [st-256color]=st_256colour_terminfo
  23. [tmux-256color]=tmux_256colour_terminfo
  24. [vte-256color]=vte_256colour_terminfo
  25. [xterm-256color]=xterm_256colour_terminfo
  26. [cygwin]=cygwin_terminfo
  27. [win32con]=win32con_terminfo
  28. [conemu]=conemu_terminfo
  29. [vtpcon]=vtpcon_terminfo
  30. )
  31. db="$(mktemp -du)"
  32. print_bold() {
  33. printf "\\e[1m%b\\e[0m" "$*"
  34. }
  35. cd "$(git rev-parse --show-toplevel)"
  36. #
  37. # Get terminfo.src
  38. #
  39. print_bold '[*] Get terminfo.src\n'
  40. curl -O "$url"
  41. gunzip -f terminfo.src.gz
  42. #
  43. # Build terminfo database
  44. #
  45. print_bold '[*] Build terminfo database\n'
  46. cat terminfo.src scripts/windows.ti | tic -x -o "$db" -
  47. rm -f terminfo.src
  48. #
  49. # Write src/nvim/tui/terminfo_defs.h
  50. #
  51. print_bold "[*] Writing $target... "
  52. sorted_terms="$(echo "${!entries[@]}" | tr ' ' '\n' | sort | xargs)"
  53. cat > "$target" <<EOF
  54. // This is an open source non-commercial project. Dear PVS-Studio, please check
  55. // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
  56. // uncrustify:off
  57. //
  58. // Generated by scripts/update_terminfo.sh and $(tic -V)
  59. //
  60. #ifndef NVIM_TUI_TERMINFO_DEFS_H
  61. #define NVIM_TUI_TERMINFO_DEFS_H
  62. #include <stdint.h>
  63. EOF
  64. for term in $sorted_terms; do
  65. path="$(find "$db" -name "$term")"
  66. if [ -z "$path" ]; then
  67. >&2 echo "Not found: $term. Skipping."
  68. continue
  69. fi
  70. printf '\n'
  71. infocmp -L -1 -A "$db" "$term" | sed -e '1d' -e 's#^#// #' | tr '\t' ' '
  72. printf 'static const int8_t %s[] = {\n' "${entries[$term]}"
  73. printf ' '
  74. od -v -t d1 < "$path" | cut -c9- | xargs | tr ' ' ','
  75. printf '};\n'
  76. done >> "$target"
  77. cat >> "$target" <<EOF
  78. #endif // NVIM_TUI_TERMINFO_DEFS_H
  79. EOF
  80. print_bold 'done\n'