aboutsummaryrefslogtreecommitdiff
path: root/scripts/update_terminfo.sh
blob: e12365ba8fd86b092765529bd09cf05e5a456919 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
#
# usage: ./scripts/update_terminfo.sh
#
# This script does:
#
#   1. Download Dickey's terminfo.src
#   2. Compile temporary terminfo database from terminfo.src
#   3. Use database to generate src/nvim/tui/terminfo_defs.h
#

set -e

url='https://invisible-island.net/datafiles/current/terminfo.src.gz'
target='src/nvim/tui/terminfo_defs.h'

readonly -A entries=(
  [ansi]=ansi_terminfo
  [interix]=interix_8colour_terminfo
  [iterm2]=iterm_256colour_terminfo
  [linux]=linux_16colour_terminfo
  [putty-256color]=putty_256colour_terminfo
  [rxvt-256color]=rxvt_256colour_terminfo
  [screen-256color]=screen_256colour_terminfo
  [st-256color]=st_256colour_terminfo
  [tmux-256color]=tmux_256colour_terminfo
  [vte-256color]=vte_256colour_terminfo
  [xterm-256color]=xterm_256colour_terminfo
  [cygwin]=cygwin_terminfo
  [win32con]=win32con_terminfo
  [conemu]=conemu_terminfo
  [vtpcon]=vtpcon_terminfo
)

db="$(mktemp -du)"

print_bold() {
  printf "\\e[1m%b\\e[0m" "$*"
}

cd "$(git rev-parse --show-toplevel)"

#
# Get terminfo.src
#
print_bold '[*] Get terminfo.src\n'
curl -O "$url"
gunzip -f terminfo.src.gz

#
# Build terminfo database
#
print_bold '[*] Build terminfo database\n'
cat terminfo.src scripts/windows.ti | tic -x -o "$db" -
rm -f terminfo.src

#
# Write src/nvim/tui/terminfo_defs.h
#
print_bold "[*] Writing $target... "
sorted_terms="$(echo "${!entries[@]}" | tr ' ' '\n' | sort | xargs)"

cat > "$target" <<EOF
// uncrustify:off

// Generated by scripts/update_terminfo.sh and $(tic -V)

#pragma once

#include <stdint.h>
EOF

for term in $sorted_terms; do
  path="$(find "$db" -name "$term")"
  if [ -z "$path" ]; then
    >&2 echo "Not found: $term. Skipping."
    continue
  fi
  printf '\n'
  infocmp -L -1 -A "$db" "$term" | sed -e '1d' -e 's#^#// #' | tr '\t' ' '
  printf 'static const int8_t %s[] = {\n' "${entries[$term]}"
  printf '  '
  od -v -t d1 < "$path" | cut -c9- | xargs | tr ' ' ','
  printf '};\n'
done >> "$target"

print_bold 'done\n'