Skip to content

Commit

Permalink
added initial support for fetching GPU information
Browse files Browse the repository at this point in the history
  • Loading branch information
grtcdr committed Aug 10, 2021
1 parent 2c26982 commit 62f5048
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 70 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

20 changes: 6 additions & 14 deletions macchina.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
# Disables color.
# Conflicts with: color, separator_color
no_color = false

# Hides the separator.
# Conflicts with: separator_color
no_separator = false

# Hides bar delimiters
no_bar_delimiter = true

# Hides the title of the box surrounding system information
# Conflicts with: box_title
no_title = false

# Disables the box surrounding system information.
# Conflicts with: box_title
no_box = false

# Disables ASCII art
Expand All @@ -27,7 +23,6 @@ palette = true
bar = true

# Prefer small ASCII variant.
# Conflicts with: no_ascii
small_ascii = false

# Randomizes the color of the keys each time your run the program
Expand All @@ -37,7 +32,6 @@ random_color = false
random_sep_color = false

# Specify a color for the keys.
# Conflicts with: no_color
# Accepted values (case-sensitive):
# - White
# - Black
Expand All @@ -50,7 +44,6 @@ random_sep_color = false
color = "Blue"

# Specify a color for the separator.
# Conflicts with: no_color
# Accepted values (case-sensitive):
# - White
# - Black
Expand All @@ -69,15 +62,12 @@ short_uptime = true
long_shell = false

# Specify the title of the box
# Conflicts with: no_title.
box_title = " Macchina "

# Specify the horizontal inner margin value of the box surrounding system information.
# Conflicts with: no_box
box_inner_margin_x = 1

# Specify the vertical inner margin value of the box surrounding system information.
# Conflicts with: no_box
box_inner_margin_y = 0

# Specify the theme to use
Expand Down Expand Up @@ -111,8 +101,9 @@ theme = "Beryllium"
# - Terminal
# - Shell
# - Uptime
# - Processor
# - ProcessorUsage
# - CPU
# - GPU
# - CPULoad
# - Memory
# - Battery
# Example:
Expand All @@ -134,8 +125,9 @@ hide = []
# - Terminal
# - Shell
# - Uptime
# - Processor
# - ProcessorUsage
# - CPU
# - GPU
# - CPULoad
# - Memory
# - Battery
# Example:
Expand Down
16 changes: 5 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,22 @@ impl Default for Opt {
no_box: false,

color: None,
bar: false,

separator_color: None,
random_color: false,
random_sep_color: false,

custom_ascii: None,
custom_ascii_color: None,
small_ascii: false,

bar: false,
hide: None,
show_only: None,

doctor: false,

short_uptime: false,
long_shell: false,

theme: None,

box_title: None,

custom_ascii: None,
custom_ascii_color: None,
small_ascii: false,

box_inner_margin_x: 1,
box_inner_margin_y: 0,
export_config: false,
Expand Down
16 changes: 0 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,6 @@ impl Opt {
conflicts.push("hide and show_only");
}

if self.separator_color.is_some() && self.no_separator {
conflicts.push("separator_color and no_separator");
}

if self.color.is_some() && self.no_color {
conflicts.push("color and no_color");
}

if self.separator_color.is_some() && self.no_color {
conflicts.push("separator_color and no_color");
}

if self.box_title.is_some() && self.no_title {
conflicts.push("box_title and no_title");
}

conflicts
}
}
42 changes: 25 additions & 17 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ arg_enum! {
Shell,
Terminal,
Uptime,
Processor,
ProcessorUsage,
CPU,
GPU,
CPULoad,
Memory,
Battery,
LocalIP,
Expand Down Expand Up @@ -257,40 +258,47 @@ pub fn get_all_readouts<'a>(
}
}

if should_display.contains(&ReadoutKey::Processor) {
if should_display.contains(&ReadoutKey::CPU) {
match (
general_readout.cpu_model_name(),
general_readout.cpu_cores(),
) {
(Ok(m), Ok(c)) => {
readout_values.push(Readout::new(ReadoutKey::Processor, format_cpu(&m, c)))
}
(Ok(m), _) => {
readout_values.push(Readout::new(ReadoutKey::Processor, format_cpu_only(&m)))
(Ok(m), Ok(c)) => readout_values.push(Readout::new(ReadoutKey::CPU, format_cpu(&m, c))),
(Ok(m), _) => readout_values.push(Readout::new(ReadoutKey::CPU, format_cpu_only(&m))),
(Err(e), _) => readout_values.push(Readout::new_err(ReadoutKey::CPU, e)),
}
}

if should_display.contains(&ReadoutKey::GPU) {
match general_readout.gpus() {
Ok(gpus) => {
for g in gpus {
readout_values.push(Readout::new(ReadoutKey::GPU, g));
}
}
(Err(e), _) => readout_values.push(Readout::new_err(ReadoutKey::Processor, e)),

Err(e) => readout_values.push(Readout::new_err(ReadoutKey::Uptime, e)),
}
}

if should_display.contains(&ReadoutKey::ProcessorUsage) {
if should_display.contains(&ReadoutKey::CPULoad) {
match (general_readout.cpu_usage(), opt.bar, tts) {
(Ok(u), true, false) => {
if u > 100 {
readout_values.push(Readout::new(
ReadoutKey::ProcessorUsage,
ReadoutKey::CPULoad,
create_bar(theme, crate::bars::num_to_blocks(100_u8)),
))
}
readout_values.push(Readout::new(
ReadoutKey::ProcessorUsage,
ReadoutKey::CPULoad,
create_bar(theme, crate::bars::num_to_blocks(u as u8)),
))
}
(Ok(u), _, _) => readout_values.push(Readout::new(
ReadoutKey::ProcessorUsage,
format_cpu_usage(u),
)),
(Err(e), _, _) => readout_values.push(Readout::new_err(ReadoutKey::ProcessorUsage, e)),
(Ok(u), _, _) => {
readout_values.push(Readout::new(ReadoutKey::CPULoad, format_cpu_usage(u)))
}
(Err(e), _, _) => readout_values.push(Readout::new_err(ReadoutKey::CPULoad, e)),
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use tui::buffer::{Buffer, Cell};
use tui::layout::{Margin, Rect};
use tui::style::Color;
use tui::text::Text;
use tui::widgets::{Block, BorderType, Borders, Paragraph, Widget};
use tui::widgets::{Block, BorderType, Borders, Paragraph, Widget, Wrap};
use unicode_width::UnicodeWidthStr;

fn create_backend() -> CrosstermBackend<Stdout> {
Expand Down Expand Up @@ -64,7 +64,9 @@ fn draw_ascii(ascii: Text<'static>, tmp_buffer: &mut Buffer) -> Rect {
height: ascii.height() as u16,
};

Paragraph::new(ascii).render(ascii_rect, tmp_buffer);
Paragraph::new(ascii)
.wrap(Wrap { trim: false })
.render(ascii_rect, tmp_buffer);
ascii_rect
}

Expand Down
9 changes: 7 additions & 2 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ impl ReadoutKey {
values.insert(&AbbreviationType::Alternative, "Upt");
values.insert(&AbbreviationType::Long, "Uptime");
}
ReadoutKey::Processor => {
ReadoutKey::CPU => {
values.insert(&AbbreviationType::Classic, "CPU");
values.insert(&AbbreviationType::Alternative, "Cpu");
values.insert(&AbbreviationType::Long, "Processor");
}
ReadoutKey::ProcessorUsage => {
ReadoutKey::GPU => {
values.insert(&AbbreviationType::Classic, "GPU");
values.insert(&AbbreviationType::Alternative, "Gpu");
values.insert(&AbbreviationType::Long, "Graphics Processor");
}
ReadoutKey::CPULoad => {
values.insert(&AbbreviationType::Classic, "CPU%");
values.insert(&AbbreviationType::Alternative, "Cp%");
values.insert(&AbbreviationType::Long, "Processor Usage");
Expand Down

0 comments on commit 62f5048

Please sign in to comment.