Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
2 changed files with 49 additions and 10 deletions
Showing only changes of commit 7730d994ff - Show all commits

View File

@ -2,6 +2,11 @@ use crossterm::event::KeyCode;
use readmap::types::Section;
use std::path::PathBuf;
use tool_helper::Error;
use tui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Style},
widgets::{Block, Borders, BorderType, Paragraph}
};
pub type EventReceiver = std::sync::mpsc::Receiver<Event<crossterm::event::KeyEvent>>;
pub type Terminal = tui::Terminal<tui::backend::CrosstermBackend<std::io::Stdout>>;
@ -17,13 +22,15 @@ pub enum UIState {
}
pub struct ConsoleUI {
rx: EventReceiver,
terminal: Terminal
rx: EventReceiver,
terminal: Terminal,
frame: Rect,
sub_frames: Vec<Rect>
}
impl ConsoleUI {
pub fn new(rx: EventReceiver, terminal: Terminal) -> ConsoleUI {
ConsoleUI{rx, terminal}
ConsoleUI{rx, terminal, frame: Rect::default(), sub_frames: Vec::default()}
}
pub fn update(&self) -> Result<UIState, Error> {
@ -38,7 +45,17 @@ impl ConsoleUI {
}
}
pub fn render(&self) {}
pub fn render(&mut self) -> Result<(), Error> {
self.terminal.draw(|frame| {
Self::update_sub_frames(&mut self.sub_frames, &mut self.frame, frame.size());
frame.render_widget(Self::create_titel(), self.sub_frames[0]);
frame.render_widget(Self::create_titel(), self.sub_frames[1]);
frame.render_widget(Self::create_titel(), self.sub_frames[2]);
})?;
Ok(())
}
pub fn close(mut self) -> Result<(), Error> {
crossterm::terminal::disable_raw_mode()?;
@ -47,6 +64,28 @@ impl ConsoleUI {
Ok(())
}
fn update_sub_frames(sub_frames: &mut Vec<Rect>, frame: &mut Rect, new_frame: Rect) {
if new_frame != *frame {
*sub_frames = Layout::default().direction(Direction::Vertical).constraints([
Constraint::Length(3),
Constraint::Length(3),
Constraint::Min(3)
]).split(new_frame);
*frame = new_frame;
}
}
fn create_titel<'a>() -> Paragraph<'a> {
Paragraph::new("psxreadmap")
.style(Style::default().fg(Color::White))
.alignment(Alignment::Center)
.block(Block::default()
.borders(Borders::ALL)
.style(Style::default().fg(Color::White))
.border_type(BorderType::Plain)
)
}
}
pub fn load_memory_map(file_path: Option<PathBuf>) -> Result<Vec<Section>, Error> {

View File

@ -9,7 +9,7 @@ use tui::backend::CrosstermBackend;
#[clap(about = "Opens and scans a MAP file to print extended information", long_about = None)]
struct CommandLine {
#[clap(value_parser, help="Input MAP file for scannning")]
input: Option<PathBuf>
input: PathBuf
}
pub fn main() {
@ -27,13 +27,13 @@ pub fn main() {
}
fn run_main(cmd: CommandLine) -> Result<(), Error> {
let _sections = load_memory_map(cmd.input)?;
let rx = start_event_loop();
let terminal = setup_console()?;
let console_ui = ConsoleUI::new(rx, terminal);
let _sections = load_memory_map(Some(cmd.input))?;
let rx = start_event_loop();
let terminal = setup_console()?;
let mut console_ui = ConsoleUI::new(rx, terminal);
while matches!(console_ui.update()?, psxreadmap::UIState::Alive) {
console_ui.render();
console_ui.render()?;
}
console_ui.close()