[英]How do you display a character with ncurses in Rust?
I'm trying to just add a character into the terminal by simply doing我试图通过简单地在终端中添加一个字符
use ncurses::*;
fn main()
{
initscr();
addch('#');
endwin();
}
but I'm getting the following error:但我收到以下错误:
error[E0308]: mismatched types
--> src/main.rs:15:11
|
15 | addch('#');
| ^^^ expected `u32`, found `char`
I checked the documentation and it says that it takes a chtype
, so I figuered that was just a character?我检查了文档,它说它需要一个
chtype
,所以我认为这只是一个字符? I'm not sure how I am supposed to change a character to a u32
.我不确定我应该如何将字符更改为
u32
。 What is the difference between a char
, and a chtype
? char
和chtype
有什么区别?
By looking at the source code chtype
defined as an alias to u64
(for 64bit platforms) and u32
(for 32 bit platforms) .通过查看定义为
u64
(对于 64 位平台)和u32
(对于 32 位平台)的别名的源代码chtype
。
#[cfg(feature="wide_chtype")]
pub type chtype = u64;
#[cfg(not(feature="wide_chtype"))]
pub type chtype = u32;
In order to to solve the error, you can type cast #
to chtype
.为了解决这个错误,你可以输入 cast
#
to chtype
。
fn main()
{
initscr();
addch('#' as chtype);
endwin();
}
chtype
holds more than a character, as described in the ncurses manual page : chtype
包含多个字符,如 ncurses手册页中所述:
ncurses
the "normal" library, which handles 8-bit characters. The
normal (8-bit) library stores characters combined with
attributes in chtype data.
Attributes alone (no corresponding character) may be stored in
chtype or the equivalent attr_t data. In either case, the data
is stored in something like an integer.
For more information, the waddch
manual page elaborates:有关更多信息,
waddch
手册页详细说明:
Video attributes can be combined with a character argument passed to
addch or related functions by logical-ORing them into the character.
(Thus, text, including attributes, can be copied from one place to
another using inch(3x) and addch.) See the curs_attr(3x) page for
values of predefined video attribute constants that can be usefully
OR'ed into characters.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.