Find and read terminfo file for given terminal name. Terminfo files are stored in directories using the first character of the terminal name as a subdirectory.
(terminal_name: str)
| 131 | |
| 132 | |
| 133 | def _read_terminfo_file(terminal_name: str) -> bytes: |
| 134 | """Find and read terminfo file for given terminal name. |
| 135 | |
| 136 | Terminfo files are stored in directories using the first character |
| 137 | of the terminal name as a subdirectory. |
| 138 | """ |
| 139 | _validate_terminal_name_or_raise(terminal_name) |
| 140 | first_char = terminal_name[0].lower() |
| 141 | filename = terminal_name |
| 142 | |
| 143 | for directory in _get_terminfo_dirs(): |
| 144 | path = directory / first_char / filename |
| 145 | if path.is_file(): |
| 146 | return path.read_bytes() |
| 147 | |
| 148 | # Try with hex encoding of first char (for special chars) |
| 149 | hex_dir = "%02x" % ord(first_char) |
| 150 | path = directory / hex_dir / filename |
| 151 | if path.is_file(): |
| 152 | return path.read_bytes() |
| 153 | |
| 154 | raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), filename) |
| 155 | |
| 156 | |
| 157 | # Hard-coded terminal capabilities for common terminals |
no test coverage detected
searching dependent graphs…