Help buffer prework

This commit is contained in:
Greg Shuflin committed 2024-03-13 03:32:53 -07:00
1 parent f9d1c70843
commit 8955eeae28
4 files changed
+29 -10

No files matched your search

+13 -3
View File
@@ -65,8 +65,7 @@ impl EditorCore {
let active_buffer = BufferId(0);
buffers.insert(active_buffer, TextBuffer::new());
let mut pane_layout = PaneLayout::new();
pane_layout.add_new_buffer(active_buffer);
let pane_layout = PaneLayout::new(active_buffer);
let (command_tx, command_output_rx) = tokio::sync::mpsc::unbounded_channel();
@@ -135,6 +134,7 @@ impl EditorCore {
Ok(())
}
//TODO this needs to only emit EditorAction's , it can't directly modify anything
pub(crate) fn process_commands(&mut self) {
if let Ok(command) = self.command_output_rx.try_recv() {
info!(?command, "Handling command");
@@ -148,7 +148,8 @@ impl EditorCore {
}
CommandOutput::WriteBuffer(path) => log_only(self.write_current_buffer(path)),
CommandOutput::ShowHelp => {
info!("TODO show help");
info!("showing help");
self.handle_action(EditorAction::PopupHelp(true));
}
};
@@ -198,6 +199,15 @@ impl EditorCore {
let buf = self.active_buffer_mut();
buf.cursor_pos.move_cursor(movement, &buf.text);
}
PopupHelp(toggle) => {
//TODO change this hardcoding of the buffer id
let buffer_id = BufferId(1);
if toggle {
self.buffers.insert(buffer_id, TextBuffer::help());
} else {
self.buffers.remove(&buffer_id);
}
}
}
}
}
+3
View File
@@ -28,6 +28,9 @@ pub(crate) enum EditorAction {
/// Toggle mirror
Mirror,
/// Show or hide the popup help
PopupHelp(bool),
}
#[derive(Debug)]
+9
View File
@@ -8,6 +8,7 @@ use super::{buffer_settings::BufferSettings, cursor::Cursor, error::BasicError};
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
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 {
pub(crate) text: Rope,
@@ -29,6 +30,14 @@ impl TextBuffer {
}
}
pub(crate) fn help() -> Self {
let mut buf = Self::new();
let mut t = Rope::new();
t.insert(0, "Dummy help text");
buf.text = t;
buf
}
pub(crate) fn load_file(file: &Path) -> Result<Self, BasicError> {
info!(file=%file.display(), "Opening file");
+4 -7
View File
@@ -7,14 +7,11 @@ pub(super) struct PaneLayout {
}
impl PaneLayout {
pub(super) fn new() -> Self {
Self {
map: HashMap::new(),
}
}
pub(super) fn new(initial_id: BufferId) -> Self {
let mut map = HashMap::new();
map.insert(initial_id, PaneDescriptor::Main { tab: 0 });
pub(super) fn add_new_buffer(&mut self, id: BufferId) {
self.map.insert(id, PaneDescriptor::Main { tab: 0 });
Self { map }
}
}