Make the log buffer show logs

This commit is contained in:
2023-11-01 18:56:54 +01:00
parent b81906c318
commit 1c13d2c784
9 changed files with 169 additions and 39 deletions

View File

@ -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())
}
}