1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
use tui::buffer::Buffer;
use tui::layout::{Direction, Layout, Rect};
use tui::style::{Color, Modifier, Style};
use tui::widgets::{Paragraph, Text, Widget};
use super::{TuiDirList, TuiDirListDetailed, TuiFooter, TuiTabBar, TuiTopBar};
use crate::context::JoshutoContext;
const TAB_VIEW_WIDTH: u16 = 15;
pub struct TuiView<'a> {
pub context: &'a JoshutoContext,
pub show_bottom_status: bool,
}
use super::super::{DEFAULT_LAYOUT, NO_PREVIEW_LAYOUT};
impl<'a> TuiView<'a> {
pub fn new(context: &'a JoshutoContext) -> Self {
Self {
context,
show_bottom_status: true,
}
}
}
impl<'a> Widget for TuiView<'a> {
fn draw(&mut self, area: Rect, buf: &mut Buffer) {
let f_size = area;
let curr_tab = self.context.curr_tab_ref();
let curr_list = curr_tab.curr_list_ref();
let parent_list = curr_tab.parent_list_ref();
let child_list = curr_tab.child_list_ref();
let constraints = match child_list {
Some(_) => DEFAULT_LAYOUT,
None => NO_PREVIEW_LAYOUT,
};
let layout_rect = Layout::default()
.direction(Direction::Horizontal)
.margin(1)
.constraints(constraints.as_ref())
.split(f_size);
{
let curr_path = curr_tab.curr_path.as_path();
if self.context.tabs.len() > 1 {
let topbar_width = if f_size.width > TAB_VIEW_WIDTH {
f_size.width - TAB_VIEW_WIDTH
} else {
0
};
let rect = Rect {
x: 0,
y: 0,
width: topbar_width,
height: 1,
};
TuiTopBar::new(curr_path).draw(rect, buf);
let rect = Rect {
x: topbar_width,
y: 0,
width: TAB_VIEW_WIDTH,
height: 1,
};
let name = if let Some(ostr) = curr_path.file_name() {
ostr.to_str().unwrap_or("")
} else {
""
};
TuiTabBar::new(name, self.context.curr_tab_index, self.context.tabs.len())
.draw(rect, buf);
} else {
let topbar_width = f_size.width;
let rect = Rect {
x: 0,
y: 0,
width: topbar_width,
height: 1,
};
TuiTopBar::new(curr_path).draw(rect, buf);
}
}
if let Some(curr_list) = parent_list.as_ref() {
TuiDirList::new(&curr_list).draw(layout_rect[0], buf);
};
if let Some(curr_list) = curr_list.as_ref() {
TuiDirListDetailed::new(&curr_list).draw(layout_rect[1], buf);
let rect = Rect {
x: 0,
y: f_size.height - 1,
width: f_size.width,
height: 1,
};
let message_style = Style::default()
.fg(Color::LightCyan)
.modifier(Modifier::BOLD);
if self.show_bottom_status {
/* draw the bottom status bar */
if let Some(msg) = self.context.worker_msg.as_ref() {
let text = [Text::styled(msg, message_style)];
Paragraph::new(text.iter()).wrap(true).draw(rect, buf);
} else if !self.context.message_queue.is_empty() {
let text = [Text::styled(&self.context.message_queue[0], message_style)];
Paragraph::new(text.iter()).wrap(true).draw(rect, buf);
} else if let Some(entry) = curr_list.get_curr_ref() {
TuiFooter::new(entry).draw(rect, buf);
}
}
};
if let Some(curr_list) = child_list.as_ref() {
TuiDirList::new(&curr_list).draw(layout_rect[2], buf);
};
}
}
|