summaryrefslogtreecommitdiffstats
path: root/src/layout.rs
diff options
context:
space:
mode:
authorKyohei Uto <kyoheiu@outlook.com>2022-10-25 06:08:54 +0900
committerKyohei Uto <kyoheiu@outlook.com>2022-10-25 06:08:54 +0900
commitfc6703518898e2904cd67ecce460766bb5be7329 (patch)
treeefce47ff9e4ea3a0d28d327be0a2a261b1034bee /src/layout.rs
parent997432e87832e116693109e5c67d56d4b63a5aa7 (diff)
Add primitively the feature to toggle vertical/horizontal
Diffstat (limited to 'src/layout.rs')
-rw-r--r--src/layout.rs39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/layout.rs b/src/layout.rs
index 6c085d9..3e3c1ac 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -30,6 +30,7 @@ pub struct Layout {
pub preview: bool,
pub split: Split,
pub preview_start_column: u16,
+ pub preview_start_row: u16,
pub preview_width: u16,
pub has_chafa: bool,
pub is_kitty: bool,
@@ -46,17 +47,24 @@ pub enum PreviewType {
#[derive(Debug)]
pub enum Split {
- Horizontal,
Vertical,
+ Horizontal,
}
impl Layout {
/// Print preview according to the preview type.
pub fn print_preview(&self, item: &ItemInfo, y: u16) {
- //At least print the item name
- self.print_file_name(item);
- //Clear preview space
- self.clear_preview(self.preview_start_column);
+ match self.split {
+ Split::Vertical => {
+ //At least print the item name
+ self.print_file_name(item);
+ //Clear preview space
+ self.clear_preview(self.preview_start_column);
+ }
+ Split::Horizontal => {
+ self.clear_preview(self.preview_start_row);
+ }
+ }
match check_preview_type(item) {
PreviewType::NotReadable => {
@@ -172,12 +180,23 @@ impl Layout {
}
/// Clear the preview space.
- fn clear_preview(&self, preview_start_column: u16) {
- for i in 0..self.terminal_row {
- move_to(preview_start_column, BEGINNING_ROW + i as u16);
- clear_until_newline();
+ fn clear_preview(&self, preview_start_point: u16) {
+ match self.split {
+ Split::Vertical => {
+ for i in 0..self.terminal_row {
+ move_to(preview_start_point, BEGINNING_ROW + i as u16);
+ clear_until_newline();
+ }
+ move_to(self.preview_start_column, BEGINNING_ROW);
+ }
+ Split::Horizontal => {
+ for i in 0..self.terminal_row {
+ move_to(1, preview_start_point + i as u16);
+ clear_until_newline();
+ }
+ move_to(1, preview_start_point);
+ }
}
- move_to(self.preview_start_column, BEGINNING_ROW);
}
}