-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswap.rs
More file actions
64 lines (57 loc) · 2.37 KB
/
swap.rs
File metadata and controls
64 lines (57 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use ratatui::Frame;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Modifier, Style};
use ratatui::text::{Line, Span};
use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
use crate::app::AppState;
pub(super) fn render(frame: &mut Frame, app: &mut AppState, area: Rect) {
let mut info_lines = vec![Line::from(Span::styled(
"Info",
Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
))];
let swap = if app.swap_enabled {
"Enabled"
} else {
"Disabled"
};
info_lines.push(Line::from(format!("Swapon: {swap}")));
let ram_gib = app.detected_ram_mib as f64 / 1024.0;
let swap_gib = app.swap_size_mib as f64 / 1024.0;
info_lines.push(Line::from(format!(
"Detected RAM: {ram_gib:.1} GiB | Planned swap size: {swap_gib:.2} GiB"
)));
info_lines.push(Line::from(
"Swapon can be used to activate the swap partition.",
));
info_lines.push(Line::from(
"If disabled here, the system will be configured with swapoff.",
));
info_lines.push(Line::from(
"You can always run 'swapon' later to activate the swap partition.",
));
let mut desc_lines = vec![Line::from(Span::styled(
"Description",
Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
))];
desc_lines.push(Line::from("A swap partition in Linux acts as an extension of physical memory (RAM), using disk space to store inactive memory pages when RAM is full. It helps prevent system crashes under heavy load, enables hibernation by saving the RAM state to disk, and allows the operating system to run more applications than would otherwise fit in physical memory."));
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([Constraint::Percentage(45), Constraint::Percentage(55)])
.split(area);
let description = Paragraph::new(desc_lines)
.block(
Block::default()
.borders(Borders::ALL)
.title(" Description "),
)
.wrap(Wrap { trim: true });
frame.render_widget(description, chunks[0]);
let info = Paragraph::new(info_lines)
.block(Block::default().borders(Borders::ALL).title(" Info "))
.wrap(Wrap { trim: true });
frame.render_widget(info, chunks[1]);
}