curses和UTF-8的问题 [英] Problem with curses and UTF-8

查看:82
本文介绍了curses和UTF-8的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在终端中运行以下代码并将编码设置为

UTF-8时,第一行会出现垃圾,但第二行会出现正确的输出。

导入诅咒

s = curses.initscr()

s.addstr(''\ xc3 \ x85 U + 00C5带有戒指的拉丁文大写字母A n'')

s.addstr(''\ xc3 \ xa5 U + 00F5 LATIN SMALL LETTER O with TILDE'')

s.refresh()

s.getstr()

curses.endwin()

我用gnome-terminal,Python 2.4和Ubuntu breezy测试过。当我运行以下代码时输出

是正确的:

print''\ xc3 \ x85 U + 00C5 LATIN CAPITAL LETTER A WITH WITH RING''br />
打印''\ xc3 \ xa5 U + 00F5 LATIN小写字母O带TILDE''

任何想法?


Ian沃德

When I run the following code in a terminal with the encoding set to
UTF-8 I get garbage on the first line, but the correct output on the second.
import curses
s = curses.initscr()
s.addstr(''\xc3\x85 U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE\n'')
s.addstr(''\xc3\xa5 U+00F5 LATIN SMALL LETTER O WITH TILDE'')
s.refresh()
s.getstr()
curses.endwin()
I tested with gnome-terminal, Python 2.4 and Ubuntu breezy. The output
is correct when I run the following code:
print ''\xc3\x85 U+00C5 LATIN CAPITAL LETTER A WITH RING ABOVE''
print ''\xc3\xa5 U+00F5 LATIN SMALL LETTER O WITH TILDE''
Any Ideas?

Ian Ward

推荐答案

Ian Ward写道:
Ian Ward wrote:
任何想法?




我认为某处存在一个或多个ncurses错误。


ncurses文档建议你应该链接

ncurses_w而不是用ncurses链接 - 你可以试试

。如果有帮助,请报告回来。


最终,有人需要调试ncurses才能找出确切发生的事情,以及为什么会这样做。


问候,

Martin



I think there is one or more ncurses bugs somewhere.

The ncurses documentation suggests that you should link with
ncurses_w instead of linking with ncurses - you might try
that as well. If it helps, please do report back.

Ultimately, somebody will need to debug ncurses to find out
what precisely happens, and why.

Regards,
Martin


Martin v.L?wis写道:
Martin v. L?wis wrote:
Ian Ward写道:

Ian Ward wrote:

任何想法?
Any Ideas?



我认为有一个或更多ncurses错误的地方。

ncurses文档建议您应该链接
ncurses_w而不是与ncurses链接 - 您也可以尝试
。如果它有帮助,请报告回来。

最终,有人需要调试ncurses才能找到确切发生的事情,以及原因。



I think there is one or more ncurses bugs somewhere.

The ncurses documentation suggests that you should link with
ncurses_w instead of linking with ncurses - you might try
that as well. If it helps, please do report back.

Ultimately, somebody will need to debug ncurses to find out
what precisely happens, and why.


感谢您的回复。我看到还有其他人在同一个问题上运行了



我在开发Urwid时必须解决许多诅咒问题(a

控制台UI库)。即使错误被修复,我也不得不绕过curses模块以可靠的方式为所有用户支持UTF-8。


我认为所有现代终端都有足够的转义序列

这样我就可以为我的库构建一个通用的curses替代品。

但是,如果有人已经在工作了在类似的东西我不想要

来重新发明轮子。


Ian Ward


Thank you for your response. I see there are other people that have run
into the same problem.

I''ve had to work around many curses issues while developing Urwid (a
console UI library). Even if the bugs are fixed I''m going to have to
bypass the curses module to support UTF-8 in a reliable way for all users.

I think there are enough escape sequences common to all modern terminals
so that I can build a generic curses-replacement for my library.
However, if someone is already working on something similar I don''t want
to reinvent the wheel.

Ian Ward


" Martin v.L?wis" <毫安**** @ v.loewis.de>写道:
"Martin v. L?wis" <ma****@v.loewis.de> wrote:
Ian Ward写道:
Ian Ward wrote:
任何想法?


我认为某处有一个或多个ncurses错误。确实是


。报告它们可能不错,而不是低估它。

ncurses文档建议你应该用 ncurses_w链接而不是用ncurses链接 - 你可能会尝试
好。如果有帮助,请报告回来。


ncursesw

最终,有人需要调试ncurses才能找出究竟发生了什么,以及原因。

I think there is one or more ncurses bugs somewhere.
indeed. It might be nice to report them rather than jawing about it.
The ncurses documentation suggests that you should link with
ncurses_w instead of linking with ncurses - you might try
that as well. If it helps, please do report back.
ncursesw
Ultimately, somebody will need to debug ncurses to find out
what precisely happens, and why.



无需调试 - 这是一个众所周知的问题。 UTF-8每个单元使用一个字节超过
,正常的curses每个单元使用一个字节。要处理UTF-8,

你需要ncursesw。


-

Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net


这篇关于curses和UTF-8的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆