update_terminfo.sh 2.0 KB

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