summaryrefslogtreecommitdiffstats
path: root/Test/V15nearcolor.ztst
blob: 52c6ab2f15950019201df19961d461e06fb5ea7b (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
88
89
90
91
92
93
94
95
96
97
98
99
100
# tests for the zsh/nearcolor module

%prep

  if ! zmodload -s zsh/nearcolor; then
    ZTST_unimplemented='the zsh/nearcolor module is not available'
  elif ! zmodload -s zsh/terminfo; then
    ZTST_unimplemented='the zsh/terminfo module is not available'
  fi

  term88= term256=
  local t
  for t in xterm-88color rxvt-unicode rxvt-88color; do
    if ( TERM=$t; [[ $terminfo[colors] == 88 ]] ) 2> /dev/null; then
      term88=$t
      break
    fi
  done
  for t in xterm-256color rxvt-256color; do
    if ( TERM=$t; [[ $terminfo[colors] == 256 ]] ) 2> /dev/null; then
      term256=$t
      break
    fi
  done
  if [[ -z $term88 && -z $term256 ]]; then
    ZTST_unimplemented='no 88- and 256-color terminals'
  else
    print -u $ZTST_fd "88-color terminal:  ${term88:-not found}"
    print -u $ZTST_fd "256-color terminal: ${term256:-not found}"
  fi

%test

  for 1 in $term88 $term256; do
    for 2 in '' -truecolor; do (
      TERM=$1
      typeset -a .term.extensions=( $2 )
      zmodload -iu zsh/nearcolor
      zmodload | grep -q zsh/nearcolor && echo unexpectedly loaded
      : ${(%):-'%F{#123456}'}
      zmodload | grep -q zsh/nearcolor || echo not autoloaded
    ); done
  done
0:automatically loaded without truecolor extension

  for 1 in $term88 $term256; do (
    TERM=$1
    typeset -a .term.extensions=( truecolor )
    zmodload -iu zsh/nearcolor
    zmodload | grep -q zsh/nearcolor && echo unexpectedly loaded
    : ${(%):-'%F{#123456}'}
    zmodload | grep -q zsh/nearcolor && echo unexpectedly loaded
  ); done
1:not automatically loaded with truecolor extension

# see https://github.com/exg/rxvt-unicode/blob/5865a435983be27c/src/init.C#L213
  if [[ -z $term88 ]]; then
    ZTST_skip='88-color conversion (no 88-color terminal)'
  else
  (
    TERM=$term88
    for 1 in 123456 654321 8a6cb4 8bffcd a5e02d cccccc d0d0d0 f00 0f0 00f; do
      print -r - $1 ${(V)${(%):-"%F{#$1}"}}
    done
  )
  fi
0:88-colour conversion
>123456 ^[[38;5;80m
>654321 ^[[38;5;81m
>8a6cb4 ^[[38;5;38m
>8bffcd ^[[38;5;46m
>a5e02d ^[[38;5;40m
>cccccc ^[[38;5;58m
>d0d0d0 ^[[38;5;86m
>f00 ^[[38;5;64m
>0f0 ^[[38;5;28m
>00f ^[[38;5;19m

# see https://github.com/exg/rxvt-unicode/blob/5865a435983be27c/src/init.C#L293
  if [[ -z $term256 ]]; then
    ZTST_skip='256-color conversion (no 256-color terminal)'
  else
  (
    TERM=$term256
    for 1 in 123456 654321 87af5f 8a6cb4 a5e02d cccccc d0d0d0 f00 0f0 00f; do
      print -r - $1 ${(V)${(%):-"%F{#$1}"}}
    done
  )
  fi
0:256-colour conversion
>123456 ^[[38;5;24m
>654321 ^[[38;5;95m
>87af5f ^[[38;5;107m
>8a6cb4 ^[[38;5;97m
>a5e02d ^[[38;5;148m
>cccccc ^[[38;5;252m
>d0d0d0 ^[[38;5;252m
>f00 ^[[38;5;196m
>0f0 ^[[38;5;46m
>00f ^[[38;5;21m