mirror of
https://github.com/sxyazi/yazi.git
synced 2024-12-22 08:11:33 +03:00
feat: make the manager offset customizable
This commit is contained in:
parent
d04f8acaf8
commit
0945d780eb
config
@ -27,6 +27,10 @@ tab_width = 1
|
||||
border_symbol = "│"
|
||||
border_style = { fg = "gray" }
|
||||
|
||||
# Offset
|
||||
folder_offset = [ 1, 0, 1, 0 ]
|
||||
preview_offset = [ 1, 1, 1, 1 ]
|
||||
|
||||
# Highlighting
|
||||
syntect_theme = ""
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
use anyhow::bail;
|
||||
use crossterm::terminal::WindowSize;
|
||||
use ratatui::prelude::Rect;
|
||||
use ratatui::{prelude::Rect, widgets::{Block, Padding}};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use shared::Term;
|
||||
|
||||
use super::{FOLDER_MARGIN, PREVIEW_BORDER, PREVIEW_MARGIN};
|
||||
use crate::THEME;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[serde(try_from = "Vec<u32>")]
|
||||
@ -42,14 +42,13 @@ impl ManagerLayout {
|
||||
let width = (columns as u32 * self.preview) as f64 / self.all as f64;
|
||||
let width = if width.fract() > 0.5 { width.ceil() as u16 } else { width.floor() as u16 };
|
||||
|
||||
let x = columns.saturating_sub(width);
|
||||
|
||||
Rect {
|
||||
x: x.saturating_add(PREVIEW_BORDER / 2),
|
||||
y: PREVIEW_MARGIN / 2,
|
||||
width: width.saturating_sub(PREVIEW_BORDER),
|
||||
height: rows.saturating_sub(PREVIEW_MARGIN),
|
||||
}
|
||||
let offset = THEME.manager.preview_offset;
|
||||
Block::default().padding(Padding::new(offset.3, offset.1, offset.0, offset.2)).inner(Rect {
|
||||
x: columns.saturating_sub(width),
|
||||
y: 0,
|
||||
width,
|
||||
height: rows,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -58,12 +57,13 @@ impl ManagerLayout {
|
||||
pub fn folder_rect(&self) -> Rect {
|
||||
let WindowSize { columns, rows, .. } = Term::size();
|
||||
|
||||
Rect {
|
||||
let offset = THEME.manager.folder_offset;
|
||||
Block::default().padding(Padding::new(offset.3, offset.1, offset.0, offset.2)).inner(Rect {
|
||||
x: (columns as u32 * self.parent / self.all) as u16,
|
||||
y: FOLDER_MARGIN / 2,
|
||||
y: 0,
|
||||
width: (columns as u32 * self.current / self.all) as u16,
|
||||
height: rows.saturating_sub(FOLDER_MARGIN),
|
||||
}
|
||||
height: rows,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -5,8 +5,3 @@ mod sorting;
|
||||
pub use layout::*;
|
||||
pub use manager::*;
|
||||
pub use sorting::*;
|
||||
|
||||
const FOLDER_MARGIN: u16 = 2;
|
||||
|
||||
const PREVIEW_BORDER: u16 = 2;
|
||||
const PREVIEW_MARGIN: u16 = 2;
|
||||
|
@ -34,6 +34,10 @@ pub struct Manager {
|
||||
pub border_symbol: String,
|
||||
pub border_style: Style,
|
||||
|
||||
// Offset
|
||||
pub(crate) folder_offset: (u16, u16, u16, u16),
|
||||
pub(crate) preview_offset: (u16, u16, u16, u16),
|
||||
|
||||
// Highlighting
|
||||
pub syntect_theme: PathBuf,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user