Move console line reading to rustyline
Much nicer now, Cool new features like keybindings, history, linting and more does work now
This commit is contained in:
parent
5f3f98060a
commit
b5bac2926d
@ -44,6 +44,9 @@ rand = "0.8.5"
|
|||||||
|
|
||||||
num-bigint = "0.4"
|
num-bigint = "0.4"
|
||||||
|
|
||||||
|
# Console line reading
|
||||||
|
rustyline = "15.0.0"
|
||||||
|
|
||||||
# encryption
|
# encryption
|
||||||
rsa = "0.9.7"
|
rsa = "0.9.7"
|
||||||
rsa-der = "0.3.0"
|
rsa-der = "0.3.0"
|
||||||
|
|||||||
@ -72,7 +72,7 @@ impl ArgumentConsumer for PlayersArgumentConsumer {
|
|||||||
|
|
||||||
impl DefaultNameArgConsumer for PlayersArgumentConsumer {
|
impl DefaultNameArgConsumer for PlayersArgumentConsumer {
|
||||||
fn default_name(&self) -> &'static str {
|
fn default_name(&self) -> &'static str {
|
||||||
"player"
|
"target"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,8 @@ const ARG_ITEM: &str = "item";
|
|||||||
fn item_count_consumer() -> BoundedNumArgumentConsumer<i32> {
|
fn item_count_consumer() -> BoundedNumArgumentConsumer<i32> {
|
||||||
BoundedNumArgumentConsumer::new()
|
BoundedNumArgumentConsumer::new()
|
||||||
.name("count")
|
.name("count")
|
||||||
.min(0)
|
.min(1)
|
||||||
.max(6400)
|
.max(i32::MAX)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GiveExecutor;
|
struct GiveExecutor;
|
||||||
|
|||||||
@ -3,12 +3,13 @@ use crate::server::{ticker::Ticker, Server};
|
|||||||
use plugin::PluginManager;
|
use plugin::PluginManager;
|
||||||
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
|
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
|
||||||
use pumpkin_util::text::TextComponent;
|
use pumpkin_util::text::TextComponent;
|
||||||
|
use rustyline::DefaultEditor;
|
||||||
use std::{
|
use std::{
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
sync::{Arc, LazyLock},
|
sync::{Arc, LazyLock},
|
||||||
};
|
};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
net::{tcp::OwnedReadHalf, TcpListener},
|
net::{tcp::OwnedReadHalf, TcpListener},
|
||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
@ -183,24 +184,23 @@ impl PumpkinServer {
|
|||||||
|
|
||||||
fn setup_console(server: Arc<Server>) {
|
fn setup_console(server: Arc<Server>) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let stdin = tokio::io::stdin();
|
let mut rl = DefaultEditor::new().unwrap();
|
||||||
let mut reader = BufReader::new(stdin);
|
|
||||||
loop {
|
loop {
|
||||||
let mut out = String::new();
|
// maybe put this into config ?
|
||||||
|
let readline = rl.readline("$ ");
|
||||||
|
|
||||||
reader
|
match readline {
|
||||||
.read_line(&mut out)
|
Ok(line) => {
|
||||||
.await
|
rl.add_history_entry(line.as_str()).unwrap();
|
||||||
.expect("Failed to read console line");
|
let dispatcher = server.command_dispatcher.read().await;
|
||||||
|
|
||||||
if !out.is_empty() {
|
|
||||||
let server_clone = server.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let dispatcher = server_clone.command_dispatcher.read().await;
|
|
||||||
dispatcher
|
dispatcher
|
||||||
.handle_command(&mut command::CommandSender::Console, &server_clone, &out)
|
.handle_command(&mut command::CommandSender::Console, &server, &line)
|
||||||
.await;
|
.await;
|
||||||
});
|
}
|
||||||
|
Err(_) => {
|
||||||
|
// TODO: we can handle CTRL+C and stuff here
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user