[英]How do you display a character with ncurses in Rust?
我試圖通過簡單地在終端中添加一個字符
use ncurses::*;
fn main()
{
initscr();
addch('#');
endwin();
}
但我收到以下錯誤:
error[E0308]: mismatched types
--> src/main.rs:15:11
|
15 | addch('#');
| ^^^ expected `u32`, found `char`
我檢查了文檔,它說它需要一個chtype
,所以我認為這只是一個字符? 我不確定我應該如何將字符更改為u32
。 char
和chtype
有什么區別?
通過查看定義為u64
(對於 64 位平台)和u32
(對於 32 位平台)的別名的源代碼chtype
。
#[cfg(feature="wide_chtype")]
pub type chtype = u64;
#[cfg(not(feature="wide_chtype"))]
pub type chtype = u32;
為了解決這個錯誤,你可以輸入 cast #
to chtype
。
fn main()
{
initscr();
addch('#' as chtype);
endwin();
}
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.
有關更多信息, 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.