Some cleaning up of the canvas colour setting feature
This commit is contained in:
parent
f3a70fbf6d
commit
8764b3092a
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bottom"
|
name = "bottom"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"]
|
authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
repository = "https://github.com/ClementTsang/bottom"
|
repository = "https://github.com/ClementTsang/bottom"
|
||||||
|
|
|
@ -13,7 +13,7 @@ regex = true
|
||||||
[colors]
|
[colors]
|
||||||
# Based on gruvbox: https://github.com/morhetz/gruvbox
|
# Based on gruvbox: https://github.com/morhetz/gruvbox
|
||||||
table_header_color="#458588"
|
table_header_color="#458588"
|
||||||
widget_title_color="#076678"
|
widget_title_color="#9d0006"
|
||||||
cpu_core_colors=["#cc241d", "#98971a", "#d79921", "#458588", "#b16286", "#689d6a", "#fb4934", "#b8bb26", "#fabd2f", "#83a598"]
|
cpu_core_colors=["#cc241d", "#98971a", "#d79921", "#458588", "#b16286", "#689d6a", "#fb4934", "#b8bb26", "#fabd2f", "#83a598"]
|
||||||
ram_color="#fb4934"
|
ram_color="#fb4934"
|
||||||
swap_color="#fabd2f"
|
swap_color="#fabd2f"
|
||||||
|
@ -22,6 +22,6 @@ tx_color="#689d6a"
|
||||||
border_color="#ebdbb2"
|
border_color="#ebdbb2"
|
||||||
highlighted_border_color="#fe8019"
|
highlighted_border_color="#fe8019"
|
||||||
text_color="#ebdbb2"
|
text_color="#ebdbb2"
|
||||||
graph_color="#076678"
|
graph_color="#9d0006"
|
||||||
selected_text_color="#282828"
|
selected_text_color="#282828"
|
||||||
selected_bg_color="#458588"
|
selected_bg_color="#458588"
|
152
src/canvas.rs
152
src/canvas.rs
|
@ -188,15 +188,14 @@ pub struct Painter {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CanvasColours {
|
pub struct CanvasColours {
|
||||||
text_colour: Color,
|
currently_selected_text_colour: Color,
|
||||||
scroll_text_colour: Color,
|
currently_selected_bg_colour: Color,
|
||||||
scroll_bg_colour: Color,
|
|
||||||
currently_selected_text_style: Style,
|
currently_selected_text_style: Style,
|
||||||
table_header_style: Style,
|
table_header_style: Style,
|
||||||
ram_colour: Color,
|
ram_style: Style,
|
||||||
swap_colour: Color,
|
swap_style: Style,
|
||||||
rx_colour: Color,
|
rx_style: Style,
|
||||||
tx_colour: Color,
|
tx_style: Style,
|
||||||
cpu_colour_styles: Vec<Style>,
|
cpu_colour_styles: Vec<Style>,
|
||||||
border_style: Style,
|
border_style: Style,
|
||||||
highlighted_border_style: Style,
|
highlighted_border_style: Style,
|
||||||
|
@ -208,15 +207,14 @@ pub struct CanvasColours {
|
||||||
impl Default for CanvasColours {
|
impl Default for CanvasColours {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
CanvasColours {
|
CanvasColours {
|
||||||
text_colour: Color::Gray,
|
currently_selected_text_colour: Color::Black,
|
||||||
scroll_text_colour: Color::Black,
|
currently_selected_bg_colour: Color::Cyan,
|
||||||
scroll_bg_colour: Color::Cyan,
|
|
||||||
currently_selected_text_style: Style::default().fg(Color::Black).bg(Color::Cyan),
|
currently_selected_text_style: Style::default().fg(Color::Black).bg(Color::Cyan),
|
||||||
table_header_style: Style::default().fg(Color::LightBlue),
|
table_header_style: Style::default().fg(Color::LightBlue),
|
||||||
ram_colour: STANDARD_FIRST_COLOUR,
|
ram_style: Style::default().fg(STANDARD_FIRST_COLOUR),
|
||||||
swap_colour: STANDARD_SECOND_COLOUR,
|
swap_style: Style::default().fg(STANDARD_SECOND_COLOUR),
|
||||||
rx_colour: STANDARD_FIRST_COLOUR,
|
rx_style: Style::default().fg(STANDARD_FIRST_COLOUR),
|
||||||
tx_colour: STANDARD_SECOND_COLOUR,
|
tx_style: Style::default().fg(STANDARD_SECOND_COLOUR),
|
||||||
cpu_colour_styles: Vec::new(),
|
cpu_colour_styles: Vec::new(),
|
||||||
border_style: Style::default().fg(Color::Gray),
|
border_style: Style::default().fg(Color::Gray),
|
||||||
highlighted_border_style: Style::default().fg(Color::LightBlue),
|
highlighted_border_style: Style::default().fg(Color::LightBlue),
|
||||||
|
@ -229,8 +227,7 @@ impl Default for CanvasColours {
|
||||||
|
|
||||||
impl CanvasColours {
|
impl CanvasColours {
|
||||||
pub fn set_text_colour(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_text_colour(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.text_colour = convert_hex_to_color(hex)?;
|
self.text_style = Style::default().fg(convert_hex_to_color(hex)?);
|
||||||
self.text_style = Style::default().fg(self.text_colour);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_border_colour(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_border_colour(&mut self, hex: &str) -> error::Result<()> {
|
||||||
|
@ -246,19 +243,19 @@ impl CanvasColours {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_ram_colour(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_ram_colour(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.ram_colour = convert_hex_to_color(hex)?;
|
self.ram_style = Style::default().fg(convert_hex_to_color(hex)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_swap_colour(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_swap_colour(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.swap_colour = convert_hex_to_color(hex)?;
|
self.swap_style = Style::default().fg(convert_hex_to_color(hex)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_rx_colour(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_rx_colour(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.rx_colour = convert_hex_to_color(hex)?;
|
self.rx_style = Style::default().fg(convert_hex_to_color(hex)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_tx_colour(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_tx_colour(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.tx_colour = convert_hex_to_color(hex)?;
|
self.tx_style = Style::default().fg(convert_hex_to_color(hex)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_cpu_colours(&mut self, hex_colours: &Vec<String>) -> error::Result<()> {
|
pub fn set_cpu_colours(&mut self, hex_colours: &Vec<String>) -> error::Result<()> {
|
||||||
|
@ -276,17 +273,17 @@ impl CanvasColours {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_scroll_entry_text_color(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_scroll_entry_text_color(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.scroll_text_colour = convert_hex_to_color(hex)?;
|
self.currently_selected_text_colour = convert_hex_to_color(hex)?;
|
||||||
self.currently_selected_text_style = Style::default()
|
self.currently_selected_text_style = Style::default()
|
||||||
.fg(self.scroll_text_colour)
|
.fg(self.currently_selected_text_colour)
|
||||||
.bg(self.scroll_bg_colour);
|
.bg(self.currently_selected_bg_colour);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_scroll_entry_bg_color(&mut self, hex: &str) -> error::Result<()> {
|
pub fn set_scroll_entry_bg_color(&mut self, hex: &str) -> error::Result<()> {
|
||||||
self.scroll_bg_colour = convert_hex_to_color(hex)?;
|
self.currently_selected_bg_colour = convert_hex_to_color(hex)?;
|
||||||
self.currently_selected_text_style = Style::default()
|
self.currently_selected_text_style = Style::default()
|
||||||
.fg(self.scroll_text_colour)
|
.fg(self.currently_selected_text_colour)
|
||||||
.bg(self.scroll_bg_colour);
|
.bg(self.currently_selected_bg_colour);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +340,7 @@ impl Painter {
|
||||||
.style(self.colours.border_style)
|
.style(self.colours.border_style)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
)
|
)
|
||||||
.style(Style::default().fg(self.colours.text_colour))
|
.style(self.colours.text_style)
|
||||||
.alignment(Alignment::Left)
|
.alignment(Alignment::Left)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
|
@ -388,7 +385,7 @@ impl Painter {
|
||||||
.style(self.colours.border_style)
|
.style(self.colours.border_style)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
)
|
)
|
||||||
.style(Style::default().fg(self.colours.text_colour))
|
.style(self.colours.text_style)
|
||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
|
@ -418,7 +415,7 @@ impl Painter {
|
||||||
.style(self.colours.border_style)
|
.style(self.colours.border_style)
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
)
|
)
|
||||||
.style(Style::default().fg(self.colours.text_colour))
|
.style(self.colours.text_style)
|
||||||
.alignment(Alignment::Center)
|
.alignment(Alignment::Center)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
.render(&mut f, middle_dialog_chunk[1]);
|
.render(&mut f, middle_dialog_chunk[1]);
|
||||||
|
@ -728,7 +725,7 @@ impl Painter {
|
||||||
} else {
|
} else {
|
||||||
Marker::Braille
|
Marker::Braille
|
||||||
})
|
})
|
||||||
.style(Style::default().fg(self.colours.ram_colour))
|
.style(self.colours.ram_style)
|
||||||
.data(&mem_data)];
|
.data(&mem_data)];
|
||||||
|
|
||||||
if !(&swap_data).is_empty() {
|
if !(&swap_data).is_empty() {
|
||||||
|
@ -740,7 +737,7 @@ impl Painter {
|
||||||
} else {
|
} else {
|
||||||
Marker::Braille
|
Marker::Braille
|
||||||
})
|
})
|
||||||
.style(Style::default().fg(self.colours.swap_colour))
|
.style(self.colours.swap_style)
|
||||||
.data(&swap_data),
|
.data(&swap_data),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -795,7 +792,7 @@ impl Painter {
|
||||||
} else {
|
} else {
|
||||||
Marker::Braille
|
Marker::Braille
|
||||||
})
|
})
|
||||||
.style(Style::default().fg(self.colours.rx_colour))
|
.style(self.colours.rx_style)
|
||||||
.data(&network_data_rx),
|
.data(&network_data_rx),
|
||||||
Dataset::default()
|
Dataset::default()
|
||||||
.name("TX")
|
.name("TX")
|
||||||
|
@ -804,7 +801,7 @@ impl Painter {
|
||||||
} else {
|
} else {
|
||||||
Marker::Braille
|
Marker::Braille
|
||||||
})
|
})
|
||||||
.style(Style::default().fg(self.colours.tx_colour))
|
.style(self.colours.tx_style)
|
||||||
.data(&network_data_tx),
|
.data(&network_data_tx),
|
||||||
])
|
])
|
||||||
.render(f, draw_loc);
|
.render(f, draw_loc);
|
||||||
|
@ -869,7 +866,7 @@ impl Painter {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.header_style(self.colours.table_header_style)
|
.header_style(self.colours.table_header_style)
|
||||||
.style(Style::default().fg(self.colours.text_colour))
|
.style(self.colours.text_style)
|
||||||
.widths(
|
.widths(
|
||||||
&(intrinsic_widths
|
&(intrinsic_widths
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -909,10 +906,10 @@ impl Painter {
|
||||||
if temp_row_counter >= 0 {
|
if temp_row_counter >= 0 {
|
||||||
temp_row_counter += 1;
|
temp_row_counter += 1;
|
||||||
}
|
}
|
||||||
Style::default().fg(self.colours.text_colour)
|
self.colours.text_style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Style::default().fg(self.colours.text_colour),
|
_ => self.colours.text_style,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -975,10 +972,10 @@ impl Painter {
|
||||||
if disk_counter >= 0 {
|
if disk_counter >= 0 {
|
||||||
disk_counter += 1;
|
disk_counter += 1;
|
||||||
}
|
}
|
||||||
Style::default().fg(self.colours.text_colour)
|
self.colours.text_style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Style::default().fg(self.colours.text_colour),
|
_ => self.colours.text_style,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -1026,46 +1023,45 @@ impl Painter {
|
||||||
|
|
||||||
let cursor_position = app_state.get_cursor_position();
|
let cursor_position = app_state.get_cursor_position();
|
||||||
|
|
||||||
let query_with_cursor: Vec<Text> = if let app::WidgetPosition::ProcessSearch =
|
let query_with_cursor: Vec<Text> =
|
||||||
app_state.current_widget_selected
|
if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected {
|
||||||
{
|
if cursor_position >= query.len() {
|
||||||
if cursor_position >= query.len() {
|
let mut q = vec![Text::styled(
|
||||||
let mut q = vec![Text::styled(
|
shrunk_query.to_string(),
|
||||||
shrunk_query.to_string(),
|
self.colours.text_style,
|
||||||
Style::default().fg(self.colours.text_colour),
|
)];
|
||||||
)];
|
|
||||||
|
|
||||||
q.push(Text::styled(
|
q.push(Text::styled(
|
||||||
" ".to_string(),
|
" ".to_string(),
|
||||||
self.colours.currently_selected_text_style,
|
self.colours.currently_selected_text_style,
|
||||||
));
|
));
|
||||||
|
|
||||||
q
|
q
|
||||||
} else {
|
} else {
|
||||||
shrunk_query
|
shrunk_query
|
||||||
.chars()
|
.chars()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(itx, c)| {
|
.map(|(itx, c)| {
|
||||||
if let app::WidgetPosition::ProcessSearch =
|
if let app::WidgetPosition::ProcessSearch =
|
||||||
app_state.current_widget_selected
|
app_state.current_widget_selected
|
||||||
{
|
{
|
||||||
if itx == cursor_position {
|
if itx == cursor_position {
|
||||||
return Text::styled(
|
return Text::styled(
|
||||||
c.to_string(),
|
c.to_string(),
|
||||||
self.colours.currently_selected_text_style,
|
self.colours.currently_selected_text_style,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Text::styled(c.to_string(), self.colours.text_style)
|
||||||
Text::styled(c.to_string(), Style::default().fg(self.colours.text_colour))
|
})
|
||||||
})
|
.collect::<Vec<_>>()
|
||||||
.collect::<Vec<_>>()
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
vec![Text::styled(
|
||||||
vec![Text::styled(
|
shrunk_query.to_string(),
|
||||||
shrunk_query.to_string(),
|
self.colours.text_style,
|
||||||
Style::default().fg(self.colours.text_colour),
|
)]
|
||||||
)]
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let mut search_text = vec![if app_state.search_state.is_searching_with_pid() {
|
let mut search_text = vec![if app_state.search_state.is_searching_with_pid() {
|
||||||
Text::styled(
|
Text::styled(
|
||||||
|
@ -1123,7 +1119,7 @@ impl Painter {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.style(Style::default().fg(self.colours.text_colour))
|
.style(self.colours.text_style)
|
||||||
.alignment(Alignment::Left)
|
.alignment(Alignment::Left)
|
||||||
.wrap(false)
|
.wrap(false)
|
||||||
.render(f, draw_loc);
|
.render(f, draw_loc);
|
||||||
|
@ -1186,10 +1182,10 @@ impl Painter {
|
||||||
if process_counter >= 0 {
|
if process_counter >= 0 {
|
||||||
process_counter += 1;
|
process_counter += 1;
|
||||||
}
|
}
|
||||||
Style::default().fg(self.colours.text_colour)
|
self.colours.text_style
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Style::default().fg(self.colours.text_colour),
|
_ => self.colours.text_style,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue