Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ edition = "2021"

[workspace]
members = [
"process-list",
"bounded-queue",
"dynamic-list"
]

Expand All @@ -19,7 +17,5 @@ ratatui = { version = "0.26.0", features = ["serde", "macros"] }
serde = { version = "1.0.188", features = ["derive"] }
anyhow = "1.0.97"
itertools = "0.10.0"
process-list = {path = "./process-list", version = "0.1.0"}
bounded-queue = {path = "./bounded-queue", version = "0.1.0"}
dynamic-list = {path = "./dynamic-list", version = "0.1.0"}
clippy = "0.0.302"
8 changes: 0 additions & 8 deletions bounded-queue/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions bounded-queue/src/lib.rs

This file was deleted.

2 changes: 2 additions & 0 deletions dynamic-list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. This is not used in the app
2. This is the beginnings of a more generalizable p_list
9 changes: 0 additions & 9 deletions process-list/Cargo.toml

This file was deleted.

11 changes: 0 additions & 11 deletions process-list/src/lib.rs

This file was deleted.

124 changes: 76 additions & 48 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
use anyhow::{Ok, Result};
use crossterm::event::KeyEvent;
use ratatui::prelude::*;
use crate::components::temp::TempComponent;
use crate::config::Config;
use crate::components::{
cpu::CPUComponent,
memory::MemoryComponent,
process::ProcessComponent,
sysinfo_wrapper::SysInfoWrapper,
error::ErrorComponent,
Component,
EventState,
DrawableComponent,
help::HelpComponent,
command,
command::CommandInfo,
};

enum MainFocus {
CPU,
Process,
Memory,
Temp,
}

pub struct App {
Expand All @@ -26,6 +28,8 @@ pub struct App {
system_wrapper: SysInfoWrapper,
process: ProcessComponent,
cpu: CPUComponent,
memory: MemoryComponent,
temp: TempComponent,
help: HelpComponent,
pub error: ErrorComponent,
pub config: Config,
Expand All @@ -34,23 +38,21 @@ pub struct App {
impl App {
pub fn new(config: Config) -> Self {
let mut system_wrapper = SysInfoWrapper::new(config.clone());

system_wrapper.refresh_all();

let processes = system_wrapper.get_processes();

let mut cpu = CPUComponent::default();

let cpus = system_wrapper.get_cpus();

cpu.update(cpus);
let process = ProcessComponent::new(config.clone(), &system_wrapper);
let memory = MemoryComponent::new(config.clone(), &system_wrapper);
let cpu = CPUComponent::new(config.clone(), &system_wrapper);
let temp = TempComponent::new(config.clone(), &system_wrapper);

Self {
focus: MainFocus::Process,
expand: false,
system_wrapper,
process: ProcessComponent::new(config.clone(), processes),
process,
cpu,
memory,
temp,
help: HelpComponent::new(config.clone()),
error: ErrorComponent::new(config.clone()),
config: config.clone(),
Expand All @@ -60,27 +62,14 @@ impl App {
pub fn refresh_event(&mut self) -> Result<EventState> {
self.system_wrapper.refresh_all();

self.update_process();

self.update_cpu();

self.update_cmds();
self.process.update(&self.system_wrapper);
self.memory.update(&self.system_wrapper);
self.cpu.update(&self.system_wrapper);
self.temp.update(&self.system_wrapper);

Ok(EventState::Consumed)
}

fn update_process(&mut self) {
let new_processes = self.system_wrapper.get_processes(); // receive ownership

self.process.update(new_processes); // transfer ownership
}

fn update_cpu(&mut self) {
let new_cpus = self.system_wrapper.get_cpus(); // receive ownership

self.cpu.update(new_cpus); // transfer ownership
}

fn toggle_expand(&mut self) {
self.expand = !self.expand
}
Expand All @@ -97,13 +86,6 @@ impl App {

return Ok(EventState::Consumed);
}
else if key.code == self.config.key_config.terminate {
if let Some(pid) = self.process.selected_pid() {
self.system_wrapper.terminate_process(pid);
}

return Ok(EventState::Consumed)
}

Ok(EventState::NotConsumed)
}
Expand All @@ -123,10 +105,26 @@ impl App {
return Ok(EventState::Consumed)
}
}
MainFocus::Memory => {
if self.memory.event(key)?.is_consumed() {
return Ok(EventState::Consumed)
}
}
MainFocus::Temp => {
if self.temp.event(key)?.is_consumed() {
return Ok(EventState::Consumed)
}
}
MainFocus::Process => {
if self.process.event(key)?.is_consumed() {
return Ok(EventState::Consumed)
}
// terminate case
if key.code == self.config.key_config.terminate {
self.process.terminate_process(&self.system_wrapper);

return Ok(EventState::Consumed)
}
}
}

Expand All @@ -137,6 +135,12 @@ impl App {
if key.code == self.config.key_config.tab {
match self.focus {
MainFocus::CPU => {
self.focus = MainFocus::Memory
}
MainFocus::Memory => {
self.focus = MainFocus::Temp
}
MainFocus::Temp => {
self.focus = MainFocus::Process
}
MainFocus::Process => {
Expand Down Expand Up @@ -177,13 +181,30 @@ impl App {
true,
)?;
}

if matches!(self.focus, MainFocus::Memory) {
self.memory.draw(
f,
chunks[0],
true,
)?;
}

if matches!(self.focus, MainFocus::Temp) {
self.temp.draw(
f,
chunks[0],
true,
)?;
}
}
else {
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage(25),
Constraint::Percentage(75),
Constraint::Percentage(24),
Constraint::Percentage(24),
Constraint::Percentage(52),
].as_ref())
.split(chunks[0]);

Expand All @@ -193,9 +214,8 @@ impl App {
let horizontal_chunk = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(33),
Constraint::Percentage(33),
Constraint::Percentage(34),
Constraint::Percentage(50),
Constraint::Percentage(50),
])
.split(*chunk);

Expand All @@ -204,7 +224,7 @@ impl App {

self.process.draw(
f,
vertical_chunks[1],
vertical_chunks[2],
matches!(self.focus, MainFocus::Process)
)?;

Expand All @@ -213,19 +233,27 @@ impl App {
vertical_chunks[0],
matches!(self.focus, MainFocus::CPU)
)?;

self.memory.draw(
f,
horizontal_chunks[1][0],
//vertical_chunks[1],
matches!(self.focus, MainFocus::Memory)
)?;

self.temp.draw(
f,
horizontal_chunks[1][1],
matches!(self.focus, MainFocus::Temp)
)?;
}

self.help.draw(f, Rect::default(), false)?;

return Ok(())
}

fn update_cmds(&mut self) {
let cmds = self.commands();

self.help.set_commands(cmds);
}

/*
fn commands(&self) -> Vec<CommandInfo> {
let res = vec![
CommandInfo::new(command::help(&self.config.key_config)),
Expand All @@ -243,5 +271,5 @@ impl App {
];

res
}
}*/
}
2 changes: 1 addition & 1 deletion src/components/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn exit_popup(key: &KeyConfig) -> CommandText {
CommandText::new(
format!(
"Exit current screen [{:?}]",
key.exit_popup,
key.exit,
),
CMD_GROUP_GENERAL
)
Expand Down
Loading
Loading