new essay: fix-term-color-for-alacritty
This commit is contained in:
		
							parent
							
								
									9c4f4ecdbd
								
							
						
					
					
						commit
						ff3827d2ea
					
				
							
								
								
									
										
											BIN
										
									
								
								content/essays/fix-term-color-for-alacritty/env-term.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								content/essays/fix-term-color-for-alacritty/env-term.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 42 KiB | 
							
								
								
									
										38
									
								
								content/essays/fix-term-color-for-alacritty/index.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								content/essays/fix-term-color-for-alacritty/index.md
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| --- | ||||
| title: "修复 Alacritty 颜色不正常的问题" | ||||
| date: 2023-03-17T18:47:57+08:00 | ||||
| tags: [] | ||||
| categories: [] | ||||
| weight: 50 | ||||
| show_comments: true | ||||
| draft: false | ||||
| --- | ||||
| 
 | ||||
| 在使用 alacritty 通过 ssh 连接到服务器的时候出现了很奇妙的现象,在一个服务器中颜色显示完全正确,另一个则明显不是期望的颜色,最后终于发现是因为一个服务器中少了一个 ncurses-term 的包,顺便大致了解了一下终端颜色显示的一些相关知识。 | ||||
| 
 | ||||
| <!--more--> | ||||
| 
 | ||||
| 首先我服务器的环境是 Debian 11,所使用的 shell 是 zsh 并使用了 prezto 框架,使用的主题是默认的 sorin 主题,所以提示符应该是有颜色的。 | ||||
| 
 | ||||
| 然后描述一下问题,shell 的颜色出现了一些偏差,如提示符不再有颜色,而且使用退格键反而会输入一个空格,但是在 shell 的缓冲区中是已经删掉该字符的,所以不会导致输入的变化,只在显示和缓冲区之间存在不一致。 | ||||
| 
 | ||||
| 另一个比较奇怪的现象是 alacritty 的颜色存在问题,但是 Konsole 却没有任何问题,在测试后发现 Konsole 固定使用 `xterm-256color` 作为 `TERM` 环境变量的值,而 alacritty 则是在检测系统环境以后选择了使用 `alacritty` 作为 `TERM` 的值。 | ||||
| 
 | ||||
| 后来发现了 `infocmp` 命令了解到颜色相关的东西,并且 `TERM` 如果是 `xterm-256color` 那么实际上是指定 `/usr/share/terminfo/x/xterm-256color`,如果是 `alacritty` 则是 `/usr/share/terminfo/a/alacritty`,在 Debian 中,这些文件由 ncurses-term 包提供。 | ||||
| 
 | ||||
| 如果实在不想安装包或者自己的发行版没有找到类似的包,把 `TERM` 设置为 `xterm-256color` 也能通过“撒谎”来得到程序的颜色支持,下面展示一下这种方法: | ||||
| 
 | ||||
|  | ||||
| 
 | ||||
| 如果不能通过设定的 `TERM` 的值找到对应的定义文件,zsh 会在更改此变量时报错 | ||||
| 
 | ||||
| ``` | ||||
| $ export TERM=non-exists | ||||
| zsh: can't find terminal definition for non-exists | ||||
| ``` | ||||
| 
 | ||||
| ## 知识总结 | ||||
| 
 | ||||
| - 终端程序会根据 `TERM` 变量去 `/usr/share/terminfo` 下寻找特定的定义文件 | ||||
| - 一些程序会将自己固定设置为 `xterm-256color` 来获取颜色支持,并避免因为 terminfo 定义文件的缺失导致的不兼容性 | ||||
| - `infocmp` 可以展示当前的 `terminfo` 的细节,或者比较多个 `terminfo` 的细节 | ||||
		Loading…
	
		Reference in a new issue
	
	 leafee98
						leafee98