Split Layout Flag
* Split Layout Flag into `layout` that searches in default layout directories and `layout-path` that takes a path to a layout file Close #506.
This commit is contained in:
parent
b835594bf2
commit
abf0a2d0c6
4 changed files with 15 additions and 15 deletions
|
|
@ -16,10 +16,14 @@ pub struct CliArgs {
|
|||
#[structopt(long)]
|
||||
pub data_dir: Option<PathBuf>,
|
||||
|
||||
/// Path to a layout yaml file
|
||||
/// Name of a layout yaml file inside the plugin directory
|
||||
#[structopt(short, long)]
|
||||
pub layout: Option<PathBuf>,
|
||||
|
||||
/// Path to a layout yaml file
|
||||
#[structopt(long, parse(from_os_str))]
|
||||
pub layout_path: Option<PathBuf>,
|
||||
|
||||
/// Change where zellij looks for the configuration
|
||||
#[structopt(short, long, env=ZELLIJ_CONFIG_FILE_ENV)]
|
||||
pub config: Option<PathBuf>,
|
||||
|
|
|
|||
|
|
@ -190,10 +190,9 @@ pub struct Layout {
|
|||
}
|
||||
|
||||
impl Layout {
|
||||
pub fn new(layout_path: &Path, data_dir: &Path) -> Self {
|
||||
let layout_dir = data_dir.join("layouts/");
|
||||
pub fn new(layout_path: &Path) -> Self {
|
||||
let mut layout_file = File::open(&layout_path)
|
||||
.or_else(|_| File::open(&layout_dir.join(&layout_path).with_extension("yaml")))
|
||||
.or_else(|_| File::open(&layout_path.with_extension("yaml")))
|
||||
.unwrap_or_else(|_| panic!("cannot find layout {}", &layout_path.display()));
|
||||
|
||||
let mut layout = String::new();
|
||||
|
|
@ -207,14 +206,8 @@ impl Layout {
|
|||
|
||||
// It wants to use Path here, but that doesn't compile.
|
||||
#[allow(clippy::ptr_arg)]
|
||||
pub fn from_defaults(layout_path: &PathBuf, data_dir: &Path) -> Self {
|
||||
Self::new(
|
||||
&data_dir
|
||||
.join("layouts/")
|
||||
.join(layout_path)
|
||||
.with_extension("yaml"),
|
||||
&data_dir,
|
||||
)
|
||||
pub fn from_dir(layout: &PathBuf, data_dir: &Path) -> Self {
|
||||
Self::new(&data_dir.join("layouts/").join(layout))
|
||||
}
|
||||
|
||||
pub fn total_terminal_panes(&self) -> usize {
|
||||
|
|
|
|||
|
|
@ -195,10 +195,13 @@ fn init_session(
|
|||
let default_layout = Some(PathBuf::from("default"));
|
||||
#[cfg(test)]
|
||||
let default_layout = None;
|
||||
let layout_path = opts.layout_path;
|
||||
let maybe_layout = opts
|
||||
.layout
|
||||
.map(|p| Layout::new(&p, &data_dir))
|
||||
.or_else(|| default_layout.map(|p| Layout::from_defaults(&p, &data_dir)));
|
||||
.as_ref()
|
||||
.map(|p| Layout::from_dir(&p, &data_dir))
|
||||
.or_else(|| layout_path.map(|p| Layout::new(&p)))
|
||||
.or_else(|| default_layout.map(|p| Layout::from_dir(&p, &data_dir)));
|
||||
|
||||
let pty_thread = thread::Builder::new()
|
||||
.name("pty".to_string())
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub fn accepts_basic_layout() {
|
|||
let mut fake_input_output = get_fake_os_input(&fake_win_size);
|
||||
fake_input_output.add_terminal_input(&[&QUIT]);
|
||||
let mut opts = CliArgs::default();
|
||||
opts.layout = Some(PathBuf::from(
|
||||
opts.layout_path = Some(PathBuf::from(
|
||||
"src/tests/fixtures/layouts/three-panes-with-nesting.yaml",
|
||||
));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue