rust - Rust 命令行历史就像在终端中一样
问题描述
我有一些生锈的代码,可以循环获取当前输入
use std::io;
fn main() {
let mut input = String::new();
loop {
io::stdin().read_line(&mut input).ok().expect("Couldn't read line");
println!("hello {}", input)
}
}
当在终端中按下向上箭头时,我如何让它将最近输入的输入放入输入中
终端示例:
>> echo "hello"
hello
>> echo "hello" [pressed up arrow]
hello
我想要它:
>> bucket
hello bucket
>> bucket [pressed up arrow]
hello bucket
解决方案
我认为您正在寻找的关键字可能是“readline”,它是用于在许多应用程序中实现此功能的 GNU 库。对于 Rust,例如rustyline等等。
推荐阅读
- java - 是否有可能在具有 Completable 未来的 Java 中为 IO 密集型服务获得高吞吐量(4-5 TPS),或者 NodeJs 是更好的选择
- html - 自动调整高度
- 适合内容
- pine-script - 当价格与指数移动平均线相距特定百分比距离时,如何打开/关闭交易?(松树)
- r - dplyr 和 tibbletime。对象不属于“til_time”类。时间聚合的一般方法
- javascript - 如何在禁用的输入框中禁用用户选择
- python - 通过将 URL 从其他 *.py 文件传递给 Scrapy 从 url 中获取数据
- reactjs - React Router Dom Redirect 需要刷新页面才能工作
- python - 为什么我在逻辑回归和支持向量机中得到相同的输出
- php - 基于表中最新的 150 个条目的 SQL 计数元素
- c - 当函数没有参数时,为什么我不会收到“冲突类型”错误?