mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
help command
This commit is contained in:
parent
771562f52b
commit
f23963c8b8
@ -70,6 +70,9 @@ fn on_command(host: &str, command: &str) -> Result<(), Box<dyn Error>> {
|
||||
} else if command == "spam" {
|
||||
send_message(host, &format!("\r\x1B[1A{}{}", args.join(" "), " ".repeat(10)).repeat(MAX_MESSAGES))?;
|
||||
// *input.write().unwrap() = "/ заспамлено)))".to_string();
|
||||
} else if command == "help" {
|
||||
write!(stdout(), "/clear - clear console; /spam *args - spam console with text; /help - show help message")?;
|
||||
stdout().flush()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
45
src/term.rs
45
src/term.rs
@ -4,7 +4,7 @@ use colored::{Color, Colorize};
|
||||
use crossterm::{cursor::MoveLeft, event::{self, Event, KeyCode}, terminal::{disable_raw_mode, enable_raw_mode}, ExecutableCommand};
|
||||
use regex::Regex;
|
||||
|
||||
use crate::{on_command, rac::send_message, ADVERTISEMENT, COLORED_USERNAMES, DATE_REGEX, MAGIC_KEY, MAX_MESSAGES, UPDATE_TIME};
|
||||
use crate::{on_command, rac::send_message, ADVERTISEMENT, COLORED_USERNAMES, DATE_REGEX, MAGIC_KEY, MAX_MESSAGES};
|
||||
|
||||
pub fn print_console(messages: &str, input: &str) -> Result<(), Box<dyn Error>> {
|
||||
let mut messages = messages.split("\n")
|
||||
@ -80,7 +80,7 @@ fn find_username_color(message: &str) -> Option<(String, String, Color)> {
|
||||
None
|
||||
}
|
||||
|
||||
fn poll_events(input: Arc<RwLock<String>>, host: String, name: String) {
|
||||
fn poll_events(input: Arc<RwLock<String>>, messages: Arc<RwLock<String>>, host: String, name: String) {
|
||||
loop {
|
||||
if !event::poll(Duration::from_millis(50)).unwrap_or(false) { continue }
|
||||
|
||||
@ -95,18 +95,27 @@ fn poll_events(input: Arc<RwLock<String>>, host: String, name: String) {
|
||||
KeyCode::Enter => {
|
||||
let message = input.read().unwrap().clone();
|
||||
|
||||
if !message.is_empty() {
|
||||
let input_len = input.read().unwrap().chars().count();
|
||||
stdout().lock().execute(MoveLeft(input_len as u16)).unwrap();
|
||||
write!(stdout(), "{}{}", " ".repeat(input_len), MoveLeft(input_len as u16).to_string()).unwrap();
|
||||
write!(stdout(),
|
||||
"{}{}{}",
|
||||
MoveLeft(1).to_string().repeat(input_len),
|
||||
" ".repeat(input_len),
|
||||
MoveLeft(1).to_string().repeat(input_len)
|
||||
).unwrap();
|
||||
stdout().lock().flush().unwrap();
|
||||
input.write().unwrap().clear();
|
||||
|
||||
if !message.is_empty() {
|
||||
if message.starts_with("/") {
|
||||
on_command(&host, &message).expect("Error on command");
|
||||
} else {
|
||||
send_message(&host, &format!("{}<{}> {}", MAGIC_KEY, name, message)).expect("Error sending message");
|
||||
}
|
||||
} else {
|
||||
print_console(
|
||||
&messages.read().unwrap(),
|
||||
&input.read().unwrap()
|
||||
).expect("Error printing console");
|
||||
}
|
||||
}
|
||||
KeyCode::Backspace => {
|
||||
@ -141,18 +150,20 @@ fn poll_events(input: Arc<RwLock<String>>, host: String, name: String) {
|
||||
pub fn run_main_loop(messages: Arc<RwLock<String>>, input: Arc<RwLock<String>>, host: String, name: String) {
|
||||
enable_raw_mode().unwrap();
|
||||
|
||||
thread::spawn({
|
||||
let messages = messages.clone();
|
||||
let input = input.clone();
|
||||
// thread::spawn({
|
||||
// let messages = messages.clone();
|
||||
// let input = input.clone();
|
||||
|
||||
move || {
|
||||
print_console(
|
||||
&messages.read().unwrap(),
|
||||
&input.read().unwrap()
|
||||
).expect("Error printing console");
|
||||
thread::sleep(Duration::from_millis(UPDATE_TIME));
|
||||
}
|
||||
});
|
||||
// move || {
|
||||
// loop {
|
||||
// print_console(
|
||||
// &messages.read().unwrap(),
|
||||
// &input.read().unwrap()
|
||||
// ).expect("Error printing console");
|
||||
// thread::sleep(Duration::from_secs(5));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
poll_events(input.clone(), host, name);
|
||||
poll_events(input.clone(), messages.clone(), host, name);
|
||||
}
|
Loading…
Reference in New Issue
Block a user