update_terminfo.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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$*\\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. //
  57. // Generated by scripts/update_terminfo.sh and $(tic -V)
  58. //
  59. #ifndef NVIM_TUI_TERMINFO_DEFS_H
  60. #define NVIM_TUI_TERMINFO_DEFS_H
  61. #include <stdint.h>
  62. EOF
  63. for term in $sorted_terms; do
  64. path="$(find "$db" -name "$term")"
  65. if [ -z "$path" ]; then
  66. >&2 echo "Not found: $term. Skipping."
  67. continue
  68. fi
  69. printf '\n'
  70. infocmp -L -1 -A "$db" "$term" | sed -e '1d' -e 's#^#// #' | tr '\t' ' '
  71. printf 'static const int8_t %s[] = {\n' "${entries[$term]}"
  72. printf ' '
  73. od -v -t d1 < "$path" | cut -c9- | xargs | tr ' ' ',' | tr -d '\n'
  74. printf ' // NOLINT\n};\n'
  75. done >> "$target"
  76. cat >> "$target" <<EOF
  77. #endif // NVIM_TUI_TERMINFO_DEFS_H
  78. EOF
  79. print_bold 'done\n'