Made search drawing on canvas a bit more efficient if possible, fixed app positionings due to search repositioning

This commit is contained in:
ClementTsang 2020-02-02 23:36:44 -05:00
parent f9bd7a6f21
commit 0a13d75415
2 changed files with 41 additions and 34 deletions

View File

@ -601,10 +601,10 @@ impl App {
// CPU -(down)> MEM
// MEM -(down)> Network, -(right)> TEMP
// TEMP -(down)> Disk, -(left)> MEM, -(up)> CPU
// Disk -(down)> Processes OR PROC_SEARCH, -(left)> MEM, -(up)> TEMP
// Disk -(down)> Processes, -(left)> MEM, -(up)> TEMP
// Network -(up)> MEM, -(right)> PROC
// PROC -(up)> Disk OR PROC_SEARCH if enabled, -(left)> Network
// PROC_SEARCH -(up)> Disk, -(down)> PROC, -(left)> Network
// PROC -(up)> Disk, -(down)> PROC_SEARCH, -(left)> Network
// PROC_SEARCH -(up)> PROC, -(left)> Network
pub fn move_left(&mut self) {
if !self.is_in_dialog() {
self.current_widget_selected = match self.current_widget_selected {
@ -634,14 +634,8 @@ impl App {
self.current_widget_selected = match self.current_widget_selected {
WidgetPosition::Mem => WidgetPosition::Cpu,
WidgetPosition::Network => WidgetPosition::Mem,
WidgetPosition::Process => {
if self.is_searching() {
WidgetPosition::ProcessSearch
} else {
WidgetPosition::Disk
}
}
WidgetPosition::ProcessSearch => WidgetPosition::Disk,
WidgetPosition::Process => WidgetPosition::Disk,
WidgetPosition::ProcessSearch => WidgetPosition::Process,
WidgetPosition::Temp => WidgetPosition::Cpu,
WidgetPosition::Disk => WidgetPosition::Temp,
_ => self.current_widget_selected,
@ -656,14 +650,14 @@ impl App {
WidgetPosition::Cpu => WidgetPosition::Mem,
WidgetPosition::Mem => WidgetPosition::Network,
WidgetPosition::Temp => WidgetPosition::Disk,
WidgetPosition::Disk => {
WidgetPosition::Disk => WidgetPosition::Process,
WidgetPosition::Process => {
if self.is_searching() {
WidgetPosition::ProcessSearch
} else {
WidgetPosition::Process
}
}
WidgetPosition::ProcessSearch => WidgetPosition::Process,
_ => self.current_widget_selected,
};
self.reset_multi_tap_keys();

View File

@ -897,33 +897,46 @@ fn draw_search_field<B: backend::Backend>(
&query[(query.len() - width as usize)..]
};
// TODO: [SEARCH] Consider making this look prettier
let cursor_position = app_state.get_cursor_position();
// TODO: [SEARCH] This can be optimized... if the cursor is at the very end or not focused we can skip this
let mut query_with_cursor: Vec<Text> = shrunk_query
.chars()
.enumerate()
.map(|(itx, c)| {
if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected {
if itx == cursor_position {
return Text::styled(
c.to_string(),
Style::default().fg(TEXT_COLOUR).bg(TABLE_HEADER_COLOUR),
);
}
}
Text::styled(c.to_string(), Style::default().fg(TEXT_COLOUR))
})
.collect::<Vec<_>>();
if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected {
let query_with_cursor: Vec<Text> = if let app::WidgetPosition::ProcessSearch =
app_state.current_widget_selected
{
if cursor_position >= query.len() {
query_with_cursor.push(Text::styled(
let mut q = vec![Text::styled(
shrunk_query.to_string(),
Style::default().fg(TEXT_COLOUR),
)];
q.push(Text::styled(
" ".to_string(),
Style::default().fg(TEXT_COLOUR).bg(TABLE_HEADER_COLOUR),
))
));
q
} else {
shrunk_query
.chars()
.enumerate()
.map(|(itx, c)| {
if let app::WidgetPosition::ProcessSearch = app_state.current_widget_selected {
if itx == cursor_position {
return Text::styled(
c.to_string(),
Style::default().fg(TEXT_COLOUR).bg(TABLE_HEADER_COLOUR),
);
}
}
Text::styled(c.to_string(), Style::default().fg(TEXT_COLOUR))
})
.collect::<Vec<_>>()
}
}
} else {
vec![Text::styled(
shrunk_query.to_string(),
Style::default().fg(TEXT_COLOUR),
)]
};
let mut search_text = vec![if app_state.search_state.is_searching_with_pid() {
Text::styled(