width$}", c="*", width=x); x 位置几乎没问题,但我想在按 space 时更改 y 位置。-6ren">
gpt4 book ai didi

rust - 在 Rust 中更改终端光标位置

转载 作者:行者123 更新时间:2023-11-29 07:52:15 26 4
gpt4 key购买 nike

为了编写游戏,我需要在终端的不同位置写一些字符。我用过

println!("{c:>width$}", c="*", width=x);

x 位置几乎没问题,但我想在按 space 时更改 y 位置。有什么办法吗?

最佳答案

对于终端控制,我建议使用像 Termion 这样的箱子.使用 Termion 它看起来像:

fn main() {
let mut stdout = stdout().into_raw_mode().unwrap();

writeln!(stdout, "{}Placed at 3,7",
termion::cursor::Goto(3, 7));
}

参见 examples .

关于rust - 在 Rust 中更改终端光标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40426307/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com