mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-12 00:33:02 +02:00
Compare commits
6 commits
394382884d
...
f36028b869
Author | SHA1 | Date | |
---|---|---|---|
|
f36028b869 |
||
|
5b1d47fa4d |
||
|
6e226dbd39 |
||
|
6cd132e207 |
||
|
7c3dd210ac |
||
|
d37879730c |
1 changed files with 27 additions and 18 deletions
|
@ -1,8 +1,8 @@
|
|||
#![cfg(feature = "console")]
|
||||
|
||||
use std::{collections::VecDeque, sync::Arc};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use conduwuit::{Server, SyncMutex, debug, defer, error, log, log::is_systemd_mode};
|
||||
use conduwuit::{Arc, Server, SyncMutex, debug, defer, error, log, log::is_systemd_mode};
|
||||
use futures::future::{AbortHandle, Abortable};
|
||||
use ruma::events::room::message::RoomMessageEventContent;
|
||||
use rustyline_async::{Readline, ReadlineError, ReadlineEvent};
|
||||
|
@ -47,7 +47,7 @@ impl Console {
|
|||
}
|
||||
|
||||
pub async fn start(self: &Arc<Self>) {
|
||||
let mut worker_join = self.worker_join.lock();
|
||||
let mut worker_join = self.worker_join.lock().expect("locked");
|
||||
if worker_join.is_none() {
|
||||
let self_ = Arc::clone(self);
|
||||
_ = worker_join.insert(self.server.runtime().spawn(self_.worker()));
|
||||
|
@ -57,7 +57,7 @@ impl Console {
|
|||
pub async fn close(self: &Arc<Self>) {
|
||||
self.interrupt();
|
||||
|
||||
let Some(worker_join) = self.worker_join.lock().take() else {
|
||||
let Some(worker_join) = self.worker_join.lock().expect("locked").take() else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
@ -67,18 +67,22 @@ impl Console {
|
|||
pub fn interrupt(self: &Arc<Self>) {
|
||||
self.interrupt_command();
|
||||
self.interrupt_readline();
|
||||
self.worker_join.lock().as_ref().map(JoinHandle::abort);
|
||||
self.worker_join
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.as_ref()
|
||||
.map(JoinHandle::abort);
|
||||
}
|
||||
|
||||
pub fn interrupt_readline(self: &Arc<Self>) {
|
||||
if let Some(input_abort) = self.input_abort.lock().take() {
|
||||
if let Some(input_abort) = self.input_abort.lock().expect("locked").take() {
|
||||
debug!("Interrupting console readline...");
|
||||
input_abort.abort();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn interrupt_command(self: &Arc<Self>) {
|
||||
if let Some(command_abort) = self.command_abort.lock().take() {
|
||||
if let Some(command_abort) = self.command_abort.lock().expect("locked").take() {
|
||||
debug!("Interrupting console command...");
|
||||
command_abort.abort();
|
||||
}
|
||||
|
@ -113,7 +117,7 @@ impl Console {
|
|||
}
|
||||
|
||||
debug!("session ending");
|
||||
self.worker_join.lock().take();
|
||||
self.worker_join.lock().expect("locked").take();
|
||||
}
|
||||
|
||||
async fn readline(self: &Arc<Self>) -> Result<ReadlineEvent, ReadlineError> {
|
||||
|
@ -128,9 +132,9 @@ impl Console {
|
|||
|
||||
let (abort, abort_reg) = AbortHandle::new_pair();
|
||||
let future = Abortable::new(future, abort_reg);
|
||||
_ = self.input_abort.lock().insert(abort);
|
||||
_ = self.input_abort.lock().expect("locked").insert(abort);
|
||||
defer! {{
|
||||
_ = self.input_abort.lock().take();
|
||||
_ = self.input_abort.lock().expect("locked").take();
|
||||
}}
|
||||
|
||||
let Ok(result) = future.await else {
|
||||
|
@ -151,9 +155,9 @@ impl Console {
|
|||
|
||||
let (abort, abort_reg) = AbortHandle::new_pair();
|
||||
let future = Abortable::new(future, abort_reg);
|
||||
_ = self.command_abort.lock().insert(abort);
|
||||
_ = self.command_abort.lock().expect("locked").insert(abort);
|
||||
defer! {{
|
||||
_ = self.command_abort.lock().take();
|
||||
_ = self.command_abort.lock().expect("locked").take();
|
||||
}}
|
||||
|
||||
_ = future.await;
|
||||
|
@ -177,15 +181,20 @@ impl Console {
|
|||
}
|
||||
|
||||
fn set_history(&self, readline: &mut Readline) {
|
||||
self.history.lock().iter().rev().for_each(|entry| {
|
||||
readline
|
||||
.add_history_entry(entry.clone())
|
||||
.expect("added history entry");
|
||||
});
|
||||
self.history
|
||||
.lock()
|
||||
.expect("locked")
|
||||
.iter()
|
||||
.rev()
|
||||
.for_each(|entry| {
|
||||
readline
|
||||
.add_history_entry(entry.clone())
|
||||
.expect("added history entry");
|
||||
});
|
||||
}
|
||||
|
||||
fn add_history(&self, line: String) {
|
||||
let mut history = self.history.lock();
|
||||
let mut history = self.history.lock().expect("locked");
|
||||
history.push_front(line);
|
||||
history.truncate(HISTORY_LIMIT);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue