翼度科技»论坛 云主机 LINUX 查看内容

[20240804]关于kitty设置与linux LANG环境设置问题.txt

3

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
[20240804]关于kitty设置与linux LANG环境设置问题.txt

--//更正我以前理解的一个混沌的地方:
--//我以前个人的工作习惯:LANG=en_US,kitty Remote character set 选择 Use font encoding.
--//目前这样的设置存在一些问题:

--//kitty设置LANG=en_US.UTF-8的情况下,kitty window->Translation ,Remote character set=utf-8,输入的汉字是UTF-8编码!!

--//张 utf-8的编码是  e5 bc a0
--//张 gb2312的编码是 d5 c5   --//213 = 0xd5 197 = 0xc5

--//简单的测试说明问题:

1.第一种情况,LANG=en_US,kitty Remote character set 选择 Use font encoding.
# echo $LANG
en_US

# mkdir test;cd test
# touch 张
# ls -1


# ls -1 | xxd -c 16
00000000: d5c5 0a                                  ...

# ls -1 ??| xxd -c 16
00000000: d5c5 0a                                  ...

--//中文gb2132编码.
# echo 111111 >> 张
--//给文件加入内容,方便下面的测试与观察.
--//补充:
# ls -l
total 4
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05 寮?
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 张

2.第二种情况,LANG=en_US,kitty Remote character set 选择 utf-8:

# echo $LANG
en_US

# cd test
 # ls  -l ??
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 ??
--//实际上看到的是一个图形符号.

# touch 张
# ls -l
total 4
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05 张
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 ??
--//这样建立了2个文件.

# ls -1|xxd -c 16
00000000: e5bc a00a d5c5 0a                        .......
--//可以发现第1个文件名编码是e5 bc a0,第2个文件名编码是 d5 c5.
--//回到第1个终端会话,看到如下:
# ls -l
total 4
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05 寮?
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 张

--//这里看到的文件名与第2种情况互换了,可以通过文件大小判断.

3.第三种情况,LANG=en_US.utf-8,kitty Remote character set 选择 Use font encoding:
--//注意测试前先修改/etc/locale.conf文件.

# echo $LANG
en_US.UTF-8

# ls -l
total 4
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 ''$'\325\305'
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05  寮?
--//两个文件的显示都存在异常.第1个是gb2312编码的文件,第2个uft-8编码文件.
# echo "ibase=8;325;305" |bc
213
197

# echo "obase=16;ibase=8;325;305" |bc |paste -sd ' '
D5 C5
--//只不过以8进制显示.前面不知道为什么显示''$'.

# ls -b -l
total 4
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 \325\305
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05 寮?

4.第四种情况,LANG=en_US.utf-8,kitty Remote character set 选择 utf-8:

# echo $LANG
en_US.UTF-8

# cd test;ls -l
total 4
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 ''$'\325\305'
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05  张
--//这种情况utf-8字符的显示正常.

# ls -l -b
total 4
-rw-r--r-- 1 root root 7 2024-08-03 23:20:58 \325\305
-rw-r--r-- 1 root root 0 2024-08-03 23:15:05 张

5.拷贝与粘贴情况:
--//最后看看从windows copy and paste 中英文的情况:
--//在windows记事本上写入 1张2 ,然后拷贝与粘贴测试
--//在终端上测试:
--//除了第3种情况出现  1耪2 其他正常.

--//再测试启动tmux的情况:
--//第一种情况,LANG=en_US,kitty Remote character set 选择 Use font encoding,       显示12
--//第二种情况,LANG=en_US,kitty Remote character set 选择 utf-8,                   显示1__2
--//第三种情况,LANG=en_US.utf-8,kitty Remote character set 选择 Use font encoding, 显示12
--//第四种情况,LANG=en_US.utf-8,kitty Remote character set 选择 utf-8,             显示1张2.

6.输入汉字的情况:
--//在终端上测试,输入张:
--//第一种情况,LANG=en_US,kitty Remote character set 选择 Use font encoding,       显示 张 gb2312编码
--//第二种情况,LANG=en_US,kitty Remote character set 选择 utf-8,                   显示 张 utf-8编码
--//第三种情况,LANG=en_US.utf-8,kitty Remote character set 选择 Use font encoding, 显示 耪
--//第四种情况,LANG=en_US.utf-8,kitty Remote character set 选择 utf-8,             显示 张 utf-8编码

--//补充测试:
# echo -e 耪 | xxd -c 16
00000000: c5d5 0a                  ...
--//编码与张的gb2312编码正好反了一下.

--//再测试启动tmux的情况:
--//第一种情况,LANG=en_US,kitty Remote character set 选择 Use font encoding,       显示 无法输入
--//第二种情况,LANG=en_US,kitty Remote character set 选择 utf-8,                   显示 __
--//第三种情况,LANG=en_US.utf-8,kitty Remote character set 选择 Use font encoding, 显示 无法输入
--//第四种情况,LANG=en_US.utf-8,kitty Remote character set 选择 utf-8,             显示 张  utf-8编码

5.总结:
--//从上面的测试可以看出:
--//第4种情况,LANG=en_US.utf-8,kitty Remote character set 选择 utf-8,可以比较好的支持汉字显示.
--//不过汉字编码不再是gb2312,而是utf-8,我个人始终不理解,在windows下输入编码是gb2312的汉字,在linux
--//的LANG=en_US.utf-8的情况下,如何转换为utf-8编码,也许存在某种规则或者算法,这种方法在设计编码时已经考虑的.

--//第1种情况,LANG=en_US,kitty Remote character set 选择 Use font encoding,可以很好的输入gb2312编码,但是在tmux下
--//要么无法输入,要么拷贝粘贴丢失..

--//之所以做这些测试,主要问题是我们团队缺乏统一管理,我不可能要求每个的设置都一样.
--//而且如果设置utf-8,在服务端操作数据库做一些dml涉及到中文时,会导致乱码问题.
--//我已经遇到类似的问题,比如在数据库新建立的包,函数,可以发现里面的一些注解看到的都是乱码.
--//而且现在我感觉大有统一到utf-8的情况,至少许多软件有这个的趋势.

--//我以前使用老版本的kitty在第一种情况终端,tmux都正常工作,现在仅仅终端可以.
--//而且以前建立的数据库选择如下:
--//characterSet ZHS16GBK -nationalCharacterSet AL16UTF16
--//如果在服务端做DML涉及中文的话,可能导致数据库一些字段出现乱码.

--//仔细查看man tmux文档,存在如下内容.

ENVIRONMENT
     When tmux is started, it inspects the following environment variables:

     EDITOR    If the command specified in this variable contains the string 'vi' and VISUAL is unset, use vi-style
               key bindings.  Overridden by the mode-keys and status-keys options.

     HOME      The user's login directory.  If unset, the passwd(5) database is consulted.

     LC_CTYPE  The character encoding locale(1).  It is used for two separate purposes.  For output to the terminal,
               UTF-8 is used if the -u option is given or if LC_CTYPE contains "UTF-8" or"UTF8".  Otherwise, only ASCII
               characters are written and non-ASCII characters are replaced with underscores ('_').  For input, tmux
               always runs with a UTF-8 locale. If en_US.UTF-8 is provided by the operating system it is used and
               LC_CTYPE is ignored for input.  Otherwise, LC_CTYPE tells tmux what the UTF-8 locale is called on the
               current system.If the locale specified by LC_CTYPE is not available or is not a UTF-8 locale, tmux exits
               with an error message.

--//这些细节应该在工作中引起注意.
来源:https://www.cnblogs.com/lfree/p/18344013
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

举报 回复 使用道具