Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminfo (tmux-256color, xterm-256color) not considered to be valid #117

Open
blueyed opened this issue Oct 13, 2021 · 6 comments
Open

terminfo (tmux-256color, xterm-256color) not considered to be valid #117

blueyed opened this issue Oct 13, 2021 · 6 comments
Labels

Comments

@blueyed
Copy link
Contributor

blueyed commented Oct 13, 2021

Using /usr/lib/terminfo/t/tmux-256color from ncurses 6.2-2 (on Arch Linux) color support (SUPPORTS_COLOR) is not detected properly.

[38] > …/Vcs/better-exceptions/better_exceptions/color.py(106)<module>()->None

...
 99             if is_tty:
100                 f = get_terminfo_file()
101                 if f is not None:
102                     with f:
103                         # f is a valid terminfo; seek and read!
104                         magic_number = struct.unpack('<h', f.read(2))[0]
105
106  ->                     if magic_number == 0x11A:
107                             # the opened terminfo file is valid.
108                             offset = 2 + 10  # magic number + size section (the next thing we read fr
109                             offset += struct.unpack('<h', f.read(2))[0]  # skip over names section
110                             offset += struct.unpack('<h', f.read(2))[0]  # skip over bool section
111                             offset += offset % 2  # align to short boundary
112                             offset += 13 * 2  # maxColors is the 13th numeric value
113
114                             f.seek(offset)
115                             max_colors = struct.unpack('<h', f.read(2))[0]
116
117                             if max_colors >= 8:
118                                 SUPPORTS_COLOR = True
 return None
(Pdb++) f
<_io.BufferedReader name='/usr/lib/terminfo/t/tmux-256color'>
(Pdb++) magic_number
542
(Pdb++) 0x11A
282

This also happens with /usr/lib/terminfo/x/xterm-256color (magic_number also being 542).

Using better-exceptions 0.3.3-1-g70e282d.

@Qix-
Copy link
Owner

Qix- commented Oct 13, 2021

Hmm. Very strange. I wonder if terminfo updated its file format.

@eric-s-raymond Hey there, sorry to bug you (not sure if you'll see this at all anyway). Do you know why the magic number might be different between versions of terminfo? Did the file format change at all within the last few years?

@blueyed Would you be willing to attach the terminfo file on this issue so I can take a look? It shouldn't contain any identifying/private information. I don't have an Arch machine onhand to pull the latest ncurses and try to repro (and I'm pretty strapped for time the next few weeks), so an upload would be very helpful.

Thanks for the detailed report!

@Qix- Qix- added the bug label Oct 13, 2021
@blueyed
Copy link
Contributor Author

blueyed commented Oct 13, 2021

@Qix- https://archlinux.org/packages/core/x86_64/ncurses/download (via https://archlinux.org/packages/core/x86_64/ncurses/)
I have not checked, but it is likely the same as with the upstream/original files. But I have no idea about this magic number in general.

@bremme
Copy link

bremme commented Dec 6, 2021

I can confirm this. I'm running Ubuntu 20.04 with the default gnome-terminal application. My TERM environmental variable is set to xterm-256color and I get no colored output.

If I force colors by setting: export FORCE_COLOR=1 I get colored output.

Let me know if I can do anything else to help resolve this issue?

@bremme
Copy link

bremme commented Dec 6, 2021

For completeness, better-exceptions finds the following values for my system:

  • terminfo file: /usr/lib/terminfo/x/xterm-256color
  • magic_numer: 542 (hex 0x21E)

@bremme
Copy link

bremme commented Dec 6, 2021

@Qix- I zipped my xterm-256color terminfo file since Github does not allow uploading the plain binairy file. Hope this helps.

xterm-256color.zip

@agvxov
Copy link

agvxov commented Jun 3, 2024

bumping out of interest, as it affects me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants