Help pane

This commit is contained in:
Greg Shuflin committed 2024-03-19 02:37:51 -07:00
1 parent 810b5e3ac0
commit 9ac513ff62
2 files changed
+35 -11

No files matched your search

+13
View File
@@ -11,6 +11,7 @@ pub(crate) struct BufferId(pub(crate) usize);
//TODO make these settings nonpublic, except for some setting that indicates style
#[derive(Debug)]
pub(crate) struct TextBuffer {
title: Option<String>,
pub(crate) text: Rope,
pub(crate) cursor_pos: Cursor,
pub(crate) buffer_settings: BufferSettings,
@@ -20,8 +21,13 @@ pub(crate) struct TextBuffer {
//TODO consider try_ versions of rope methods to avoid panic
impl TextBuffer {
pub(crate) fn title(&self) -> Option<&str> {
self.title.as_ref().map(|x| x.as_str())
}
pub(crate) fn new() -> Self {
Self {
title: None,
text: Rope::new(),
cursor_pos: Cursor::new(),
buffer_settings: BufferSettings::new(),
@@ -36,6 +42,7 @@ impl TextBuffer {
t.insert(0, "Dummy help text");
buf.text = t;
buf.writeable = false;
buf.title = Some("Help".to_string());
buf
}
@@ -49,7 +56,13 @@ impl TextBuffer {
t.insert(0, &text);
t
};
let title = file
.file_name()
.map(|x| x.to_string_lossy().to_string())
.unwrap_or("<no title>".to_owned());
Ok(Self {
title: Some(title),
text,
cursor_pos: Cursor::new(),
buffer_settings: BufferSettings::new(),
+22 -11
View File
@@ -7,6 +7,7 @@ use ratatui::{
prelude::*,
widgets::{Block, Borders, Clear, Paragraph},
};
use tracing::warn;
use crate::{
core::{
@@ -57,8 +58,20 @@ impl TerminalState {
);
}
fn render_popup(&mut self, frame: &mut Frame, outer_rect: Rect, title: &str) {
let block = Block::default().title(title).borders(Borders::ALL);
fn render_popup(&mut self, frame: &mut Frame, outer_rect: Rect, buffer: &TextBuffer) {
let title = buffer.title().unwrap_or("<no title>");
let popup_color = if buffer.writeable {
Color::Black
} else {
Color::Blue
};
//TODO fillin text
//let text = single_buffer_lines(buffer, rect.height, cursor_style, line_number_style);
let block = Block::default()
.title(title)
.borders(Borders::ALL)
.bg(popup_color);
// helper function to create a centered rect using up certain percentage of the available rect `r`
// code from https://github.com/ratatui-org/ratatui/blob/main/examples/popup.rs
@@ -88,21 +101,18 @@ impl TerminalState {
let line_number_style = line_number_style(&core);
let active_buffer = core.active_buffer();
let terminal_buf_height = rect.height;
let pane_layout = core.pane_layout();
let text = single_buffer_lines(
active_buffer,
terminal_buf_height,
cursor_style,
line_number_style,
);
let text = single_buffer_lines(active_buffer, rect.height, cursor_style, line_number_style);
frame.render_widget(Paragraph::new(text).white().on_black(), rect);
if let Some(floating) = pane_layout.has_popup() {
let _floating_buf = core.get_buffer_by_id(floating);
self.render_popup(frame, rect, "yolo");
if let Some(floating_buf) = core.get_buffer_by_id(floating) {
self.render_popup(frame, rect, floating_buf);
} else {
warn!(id=?floating, "Buffer not found");
}
}
/*
@@ -131,6 +141,7 @@ impl TerminalState {
}
*/
/// Generate lines of text for a buffe;
fn single_buffer_lines<'a>(
active_buffer: &TextBuffer,
terminal_buf_height: u16,