Make the log buffer show logs
This commit is contained in:
@ -14,13 +14,23 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
|
||||
use ratatui::text::Text;
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
use super::Buffer;
|
||||
|
||||
pub struct LogBuffer {}
|
||||
pub struct LogBuffer {
|
||||
lines: &'static RwLock<VecDeque<String>>,
|
||||
}
|
||||
|
||||
impl LogBuffer {
|
||||
pub fn new() -> Self {
|
||||
LogBuffer {}
|
||||
pub fn new(lines: &'static RwLock<VecDeque<String>>) -> Self {
|
||||
LogBuffer { lines }
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,4 +38,21 @@ impl Buffer for LogBuffer {
|
||||
fn short_name(&self) -> String {
|
||||
"ratatrix".to_owned()
|
||||
}
|
||||
|
||||
fn content(&self) -> Text {
|
||||
let lines = self
|
||||
.lines
|
||||
.read()
|
||||
.expect("LogBuffer could not get log's RwLock as it is poisoned");
|
||||
let (slice1, slice2) = lines.as_slices();
|
||||
let text = if slice1.is_empty() {
|
||||
slice2.join("\n")
|
||||
} else if slice2.is_empty() {
|
||||
slice1.join("\n")
|
||||
} else {
|
||||
format!("{}\n{}", slice1.join("\n"), slice2.join("\n"))
|
||||
};
|
||||
use ansi_to_tui::IntoText;
|
||||
text.clone().into_text().unwrap_or_else(|_| text.into())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user