-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minimal display mode #571
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use ratatui::buffer::Buffer; | ||
use ratatui::layout::{Constraint, Direction, Layout, Rect}; | ||
use ratatui::style::{Color, Style}; | ||
use ratatui::text::Span; | ||
use ratatui::widgets::{Paragraph, Widget, Wrap}; | ||
|
||
use crate::types::state::AppState; | ||
use crate::ui::widgets::{TuiDirListDetailed, TuiFooter, TuiTopBar}; | ||
|
||
pub struct TuiMinimalView<'a> { | ||
pub app_state: &'a AppState, | ||
pub show_bottom_status: bool, | ||
} | ||
|
||
impl<'a> TuiMinimalView<'a> { | ||
pub fn new(app_state: &'a AppState) -> Self { | ||
Self { | ||
app_state, | ||
show_bottom_status: true, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Widget for TuiMinimalView<'a> { | ||
fn render(self, area: Rect, buf: &mut Buffer) { | ||
let tab_state = self.app_state.state.tab_state_ref(); | ||
|
||
let display_options = &self.app_state.config.display_options; | ||
let constraints = &[Constraint::Ratio(1, 1)]; | ||
|
||
let layout_rect = { | ||
let area = Rect { | ||
y: area.top() + 1, | ||
height: area.height - 2, | ||
..area | ||
}; | ||
calculate_layout(area, constraints) | ||
}; | ||
|
||
let tab_id = tab_state.curr_tab_id(); | ||
if let Some(curr_tab) = tab_state.tab_ref(&tab_id) { | ||
let curr_list = curr_tab.curr_list_ref(); | ||
|
||
let layout_rect = layout_rect[0]; | ||
|
||
// render current view | ||
if let Some(list) = curr_list.as_ref() { | ||
TuiDirListDetailed::new( | ||
&self.app_state.config, | ||
list, | ||
display_options, | ||
curr_tab.option_ref(), | ||
true, | ||
) | ||
.render(layout_rect, buf); | ||
let rect = Rect { | ||
x: 0, | ||
y: area.height - 1, | ||
width: area.width, | ||
height: 1, | ||
}; | ||
|
||
if self.show_bottom_status { | ||
/* draw the bottom status bar */ | ||
if let Some(msg) = self.app_state.state.worker_state_ref().get_msg() { | ||
let message_style = Style::default().fg(Color::Yellow); | ||
let text = Span::styled(msg, message_style); | ||
Paragraph::new(text) | ||
.wrap(Wrap { trim: true }) | ||
.render(rect, buf); | ||
} else if let Some(msg) = | ||
self.app_state.state.message_queue_ref().current_message() | ||
{ | ||
let text = Span::styled(msg.content.as_str(), msg.style); | ||
Paragraph::new(text) | ||
.wrap(Wrap { trim: true }) | ||
.render(rect, buf); | ||
} else { | ||
TuiFooter::new(list, curr_tab.option_ref()).render(rect, buf); | ||
} | ||
} | ||
} | ||
|
||
let topbar_width = area.width; | ||
let rect = Rect { | ||
x: 0, | ||
y: 0, | ||
width: topbar_width, | ||
height: 1, | ||
}; | ||
TuiTopBar::new(self.app_state).render(rect, buf); | ||
} | ||
} | ||
} | ||
|
||
fn calculate_layout(area: Rect, constraints: &[Constraint; 1]) -> Vec<Rect> { | ||
let mut layout_rect = Layout::default() | ||
.direction(Direction::Horizontal) | ||
.constraints(constraints.as_ref()) | ||
.split(area) | ||
.to_vec(); | ||
|
||
layout_rect[0] = Rect { | ||
width: layout_rect[0].width - 1, | ||
..layout_rect[0] | ||
}; | ||
layout_rect | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why I had to qualify this to make it compile, any help/explanation is appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you add
then it won't require you to do this. Up to you on if you add it though, I don't have a huge preference and will probably change it later anyways xd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint!