tui render refactor
This commit is contained in:
1 parent
ec643e6edd
commit
67230d194d
3 files changed
+45
-28
No files matched your search
+15
-28
@@ -1,3 +1,6 @@
|
||||
mod layout;
|
||||
mod styles;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use ratatui::{
|
||||
@@ -5,11 +8,16 @@ use ratatui::{
|
||||
widgets::{Block, Borders, Clear, Paragraph},
|
||||
};
|
||||
|
||||
use crate::core::{
|
||||
buffer::{BufferId, TextBuffer},
|
||||
EditorCore,
|
||||
use crate::{
|
||||
core::{
|
||||
buffer::{BufferId, TextBuffer},
|
||||
EditorCore,
|
||||
},
|
||||
tui::render::styles::{cursor_style, line_number_style},
|
||||
};
|
||||
|
||||
use self::layout::global_layout;
|
||||
|
||||
pub(crate) struct TerminalState {
|
||||
#[allow(dead_code)]
|
||||
buffer_visible_lines: HashMap<BufferId, (usize, usize)>,
|
||||
@@ -23,23 +31,14 @@ impl TerminalState {
|
||||
}
|
||||
|
||||
pub(super) fn render(&mut self, frame: &mut Frame, core: &EditorCore) {
|
||||
let area = frame.size();
|
||||
|
||||
let layout = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(vec![
|
||||
Constraint::Min(0),
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.split(area);
|
||||
let [main_area, info_area, command_area] = global_layout(&frame);
|
||||
|
||||
let active_buffer = core.active_buffer();
|
||||
let cursor = active_buffer.cursor_pos;
|
||||
|
||||
//frame.render_widget(Paragraph::new(text).white().on_black(), layout[0]);
|
||||
|
||||
self.render_main_buffers(frame, layout[0], core);
|
||||
self.render_main_buffers(frame, main_area, core);
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(vec![Line::from(vec![
|
||||
@@ -52,10 +51,10 @@ impl TerminalState {
|
||||
])])
|
||||
.black()
|
||||
.on_white(),
|
||||
layout[1],
|
||||
info_area,
|
||||
);
|
||||
|
||||
self.render_command(frame, core, layout[2]);
|
||||
self.render_command(frame, core, command_area);
|
||||
}
|
||||
|
||||
fn render_popup(&mut self, frame: &mut Frame, outer_rect: Rect, title: &str) {
|
||||
@@ -188,18 +187,6 @@ impl TerminalState {
|
||||
}
|
||||
}
|
||||
|
||||
// Style computations
|
||||
|
||||
fn line_number_style(_core: &EditorCore) -> Style {
|
||||
Style::default().fg(Color::Yellow)
|
||||
}
|
||||
|
||||
fn cursor_style(_core: &EditorCore) -> Style {
|
||||
Style::default()
|
||||
.bg(Color::White)
|
||||
.add_modifier(Modifier::SLOW_BLINK)
|
||||
}
|
||||
|
||||
fn process_line(input: &str, expand_tab: usize) -> String {
|
||||
input
|
||||
.chars()
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
use ratatui::prelude::*;
|
||||
|
||||
pub(super) fn global_layout(frame: &Frame) -> [Rect; 3] {
|
||||
let area = frame.size();
|
||||
Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(vec![
|
||||
Constraint::Min(0),
|
||||
Constraint::Length(2),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.areas(area)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
use ratatui::prelude::*;
|
||||
|
||||
// Style computations
|
||||
|
||||
use ratatui::style::Style;
|
||||
|
||||
use crate::core::EditorCore;
|
||||
|
||||
pub(super) fn line_number_style(_core: &EditorCore) -> Style {
|
||||
Style::default().fg(Color::Yellow)
|
||||
}
|
||||
|
||||
pub(super) fn cursor_style(_core: &EditorCore) -> Style {
|
||||
Style::default()
|
||||
.bg(Color::White)
|
||||
.add_modifier(Modifier::SLOW_BLINK)
|
||||
}
|
||||
Reference in new issue
Block a user