-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split commands into separate files (#272)
- Loading branch information
Showing
54 changed files
with
1,145 additions
and
1,051 deletions.
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
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
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,10 @@ | ||
use crate::{manager::Manager, tasks::Tasks}; | ||
|
||
impl Manager { | ||
pub fn close(&mut self, tasks: &Tasks) -> bool { | ||
if self.tabs.len() > 1 { | ||
return self.tabs.close(self.tabs.idx); | ||
} | ||
self.quit(tasks, false) | ||
} | ||
} |
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,43 @@ | ||
use std::path::PathBuf; | ||
|
||
use shared::Url; | ||
use tokio::fs::{self}; | ||
|
||
use crate::{emit, files::{File, FilesOp}, input::InputOpt, manager::Manager}; | ||
|
||
impl Manager { | ||
pub fn create(&self, force: bool) -> bool { | ||
let cwd = self.cwd().to_owned(); | ||
tokio::spawn(async move { | ||
let mut result = emit!(Input(InputOpt::top("Create:"))); | ||
let Some(Ok(name)) = result.recv().await else { | ||
return Ok(()); | ||
}; | ||
|
||
let path = cwd.join(&name); | ||
if !force && fs::symlink_metadata(&path).await.is_ok() { | ||
match emit!(Input(InputOpt::top("Overwrite an existing file? (y/N)"))).recv().await { | ||
Some(Ok(c)) if c == "y" || c == "Y" => (), | ||
_ => return Ok(()), | ||
} | ||
} | ||
|
||
if name.ends_with('/') { | ||
fs::create_dir_all(&path).await?; | ||
} else { | ||
fs::create_dir_all(&path.parent().unwrap()).await.ok(); | ||
fs::File::create(&path).await?; | ||
} | ||
|
||
let child = | ||
Url::from(path.components().take(cwd.components().count() + 1).collect::<PathBuf>()); | ||
if let Ok(f) = File::from(child.clone()).await { | ||
emit!(Files(FilesOp::Creating(cwd, f.into_map()))); | ||
emit!(Hover(child)); | ||
emit!(Refresh); | ||
} | ||
Ok::<(), anyhow::Error>(()) | ||
}); | ||
false | ||
} | ||
} |
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,19 @@ | ||
mod close; | ||
mod create; | ||
mod open; | ||
mod peek; | ||
mod quit; | ||
mod refresh; | ||
mod rename; | ||
mod suspend; | ||
mod yank; | ||
|
||
pub use close::*; | ||
pub use create::*; | ||
pub use open::*; | ||
pub use peek::*; | ||
pub use quit::*; | ||
pub use refresh::*; | ||
pub use rename::*; | ||
pub use suspend::*; | ||
pub use yank::*; |
Oops, something went wrong.