Finish generalizing buffers
This commit is contained in:
1 parent
c83c91c335
commit
eab49608c8
3 files changed
+33
-21
No files matched your search
+9
-3
@@ -179,14 +179,18 @@ impl EditorCore {
|
||||
Mode::Command => self.commands.add_char(ch),
|
||||
_ => {
|
||||
let buf = self.active_buffer_mut();
|
||||
buf.insert_char(ch);
|
||||
if let Buffer::Text(ref mut tb) = buf {
|
||||
tb.insert_char(ch);
|
||||
}
|
||||
}
|
||||
},
|
||||
DeleteChar => match mode {
|
||||
Mode::Command => self.commands.del_char(),
|
||||
_ => {
|
||||
let buf = self.active_buffer_mut();
|
||||
buf.delete_char();
|
||||
if let Buffer::Text(ref mut tb) = buf {
|
||||
tb.delete_char()
|
||||
}
|
||||
}
|
||||
},
|
||||
TransitionToMode(mode) => {
|
||||
@@ -202,7 +206,9 @@ impl EditorCore {
|
||||
}
|
||||
MoveCursor(movement) => {
|
||||
let buf = self.active_buffer_mut();
|
||||
buf.move_cursor(movement);
|
||||
if let Buffer::Text(ref mut tb) = buf {
|
||||
tb.move_cursor(movement);
|
||||
}
|
||||
}
|
||||
PopupHelp(toggle) => {
|
||||
info!(%toggle, "invoke help");
|
||||
|
||||
@@ -15,6 +15,8 @@ pub(crate) struct BufferId(pub(crate) usize);
|
||||
|
||||
pub(crate) enum Buffer {
|
||||
Text(TextBuffer),
|
||||
#[allow(dead_code)]
|
||||
Dummy,
|
||||
}
|
||||
|
||||
//TODO make these settings nonpublic, except for some setting that indicates style
|
||||
|
||||
+22
-18
@@ -11,7 +11,7 @@ use tracing::warn;
|
||||
|
||||
use crate::{
|
||||
core::{
|
||||
buffer::{BufferId, TextBuffer},
|
||||
buffer::{Buffer, BufferId, TextBuffer},
|
||||
EditorCore,
|
||||
},
|
||||
tui::render::styles::{cursor_style, line_number_style},
|
||||
@@ -41,21 +41,23 @@ impl TerminalState {
|
||||
|
||||
fn render_info_pane(&mut self, frame: &mut Frame, info_area: Rect, core: &EditorCore) {
|
||||
let active_buffer = core.active_buffer();
|
||||
let cursor = active_buffer.cursor_pos;
|
||||
if let Buffer::Text(tb) = active_buffer {
|
||||
let cursor = tb.cursor_pos;
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(vec![Line::from(vec![
|
||||
format!("Mode: {:?} ", core.mode()).into(),
|
||||
Span::styled(
|
||||
format!("Cursor: {}", cursor),
|
||||
Style::default().fg(Color::Red),
|
||||
)
|
||||
.into(),
|
||||
])])
|
||||
.black()
|
||||
.on_white(),
|
||||
info_area,
|
||||
);
|
||||
frame.render_widget(
|
||||
Paragraph::new(vec![Line::from(vec![
|
||||
format!("Mode: {:?} ", core.mode()).into(),
|
||||
Span::styled(
|
||||
format!("Cursor: {}", cursor),
|
||||
Style::default().fg(Color::Red),
|
||||
)
|
||||
.into(),
|
||||
])])
|
||||
.black()
|
||||
.on_white(),
|
||||
info_area,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn render_popup(&mut self, frame: &mut Frame, outer_rect: Rect, buffer: &TextBuffer) {
|
||||
@@ -104,11 +106,13 @@ impl TerminalState {
|
||||
|
||||
let pane_layout = core.pane_layout();
|
||||
|
||||
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 Buffer::Text(tb) = active_buffer {
|
||||
let text = single_buffer_lines(&tb, 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() {
|
||||
if let Some(floating_buf) = core.get_buffer_by_id(floating) {
|
||||
if let Some(Buffer::Text(floating_buf)) = core.get_buffer_by_id(floating) {
|
||||
self.render_popup(frame, rect, floating_buf);
|
||||
} else {
|
||||
warn!(id=?floating, "Buffer not found");
|
||||
|
||||
Reference in new issue
Block a user