mirror of
https://github.com/robcholz/vibebox.git
synced 2026-10-11 01:08:41 +02:00
feat: added vm info
This commit is contained in:
1 parent
166b035977
commit
402f37bae4
2 files changed
+24
-8
No files matched your search
@@ -79,12 +79,13 @@ fn main() -> Result<()> {
|
|||||||
mounts: config.box_cfg.mounts.clone(),
|
mounts: config.box_cfg.mounts.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let auto_shutdown_ms = config.supervisor.auto_shutdown_ms;
|
||||||
let vm_info = VmInfo {
|
let vm_info = VmInfo {
|
||||||
version: env!("CARGO_PKG_VERSION").to_string(),
|
|
||||||
max_memory_mb: vm_args.ram_bytes / (1024 * 1024),
|
max_memory_mb: vm_args.ram_bytes / (1024 * 1024),
|
||||||
cpu_cores: vm_args.cpu_count,
|
cpu_cores: vm_args.cpu_count,
|
||||||
|
system_name: "Debian".to_string(), // TODO: read system name from the VM.
|
||||||
|
auto_shutdown_ms,
|
||||||
};
|
};
|
||||||
let auto_shutdown_ms = config.supervisor.auto_shutdown_ms;
|
|
||||||
if let Ok(manager) = SessionManager::new() {
|
if let Ok(manager) = SessionManager::new() {
|
||||||
if let Err(err) = manager.update_global_sessions(&cwd) {
|
if let Err(err) = manager.update_global_sessions(&cwd) {
|
||||||
tracing::warn!(error = %err, "failed to update a global session list");
|
tracing::warn!(error = %err, "failed to update a global session list");
|
||||||
|
|||||||
+21
-6
@@ -34,12 +34,14 @@ const ASCII_BANNER: [&str; 7] = [
|
|||||||
" ╚═══╝ ╚═╝╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝",
|
" ╚═══╝ ╚═╝╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚═╝",
|
||||||
"",
|
"",
|
||||||
];
|
];
|
||||||
|
const INFO_LINE_COUNT: u16 = 5;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct VmInfo {
|
pub struct VmInfo {
|
||||||
pub version: String,
|
|
||||||
pub max_memory_mb: u64,
|
pub max_memory_mb: u64,
|
||||||
pub cpu_cores: usize,
|
pub cpu_cores: usize,
|
||||||
|
pub system_name: String,
|
||||||
|
pub auto_shutdown_ms: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -155,10 +157,14 @@ fn compute_page_layout(app: &AppState, width: u16) -> PageLayout {
|
|||||||
fn header_height() -> u16 {
|
fn header_height() -> u16 {
|
||||||
let banner_height = ASCII_BANNER.len() as u16;
|
let banner_height = ASCII_BANNER.len() as u16;
|
||||||
let welcome_height = 1;
|
let welcome_height = 1;
|
||||||
let info_height = 4;
|
let info_height = info_block_height();
|
||||||
welcome_height + banner_height + info_height
|
welcome_height + banner_height + info_height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn info_block_height() -> u16 {
|
||||||
|
INFO_LINE_COUNT.saturating_add(1)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_tui_once(app: &mut AppState) -> Result<()> {
|
pub fn render_tui_once(app: &mut AppState) -> Result<()> {
|
||||||
let (width, _) = crossterm::terminal::size()?;
|
let (width, _) = crossterm::terminal::size()?;
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
@@ -532,13 +538,15 @@ fn render_header(buffer: &mut Buffer, area: Rect, app: &AppState) {
|
|||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Length(ASCII_BANNER.len() as u16),
|
Constraint::Length(ASCII_BANNER.len() as u16),
|
||||||
Constraint::Length(4),
|
Constraint::Length(info_block_height()),
|
||||||
])
|
])
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
|
let version = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
let welcome = Line::from(vec![
|
let welcome = Line::from(vec![
|
||||||
Span::raw("Welcome to Vibebox v"),
|
Span::raw("Welcome to Vibebox v"),
|
||||||
Span::styled(&app.vm_info.version, Style::default().fg(Color::Yellow)),
|
Span::styled(version, Style::default().fg(Color::Yellow)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Paragraph::new(welcome).render(header_chunks[0], buffer);
|
Paragraph::new(welcome).render(header_chunks[0], buffer);
|
||||||
@@ -557,8 +565,8 @@ fn render_header(buffer: &mut Buffer, area: Rect, app: &AppState) {
|
|||||||
Span::styled(app.cwd.to_string_lossy(), Style::default().fg(Color::Cyan)),
|
Span::styled(app.cwd.to_string_lossy(), Style::default().fg(Color::Cyan)),
|
||||||
]),
|
]),
|
||||||
Line::from(vec![
|
Line::from(vec![
|
||||||
Span::raw("VM Version: "),
|
Span::raw("System: "),
|
||||||
Span::styled(&app.vm_info.version, Style::default().fg(Color::Green)),
|
Span::styled(&app.vm_info.system_name, Style::default().fg(Color::Green)),
|
||||||
]),
|
]),
|
||||||
Line::from(vec![
|
Line::from(vec![
|
||||||
Span::raw("CPU / Memory: "),
|
Span::raw("CPU / Memory: "),
|
||||||
@@ -570,6 +578,13 @@ fn render_header(buffer: &mut Buffer, area: Rect, app: &AppState) {
|
|||||||
Style::default().fg(Color::Green),
|
Style::default().fg(Color::Green),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
Line::from(vec![
|
||||||
|
Span::raw("Auto Shutdown: "),
|
||||||
|
Span::styled(
|
||||||
|
format!("{} ms", app.vm_info.auto_shutdown_ms),
|
||||||
|
Style::default().fg(Color::Green),
|
||||||
|
),
|
||||||
|
]),
|
||||||
];
|
];
|
||||||
|
|
||||||
Paragraph::new(info_lines)
|
Paragraph::new(info_lines)
|
||||||
|
|||||||
Reference in new issue
Block a user