mirror of
https://github.com/chylex/Bark-Browser.git
synced 2025-05-29 03:34:03 +02:00
Add command line argument for specifying the root path
This commit is contained in:
parent
d6e45a09a2
commit
a2f9a8d339
@ -1,6 +1,6 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
<configuration default="false" name="Run" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
<option name="command" value="run --package bark --bin bark" />
|
<option name="command" value="run --package bark --bin bark -- /" />
|
||||||
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
<option name="emulateTerminal" value="true" />
|
<option name="emulateTerminal" value="true" />
|
||||||
<option name="channel" value="DEFAULT" />
|
<option name="channel" value="DEFAULT" />
|
||||||
|
@ -66,12 +66,17 @@ impl FileEntry {
|
|||||||
|
|
||||||
impl From<&DirEntry> for FileEntry {
|
impl From<&DirEntry> for FileEntry {
|
||||||
fn from(entry: &DirEntry) -> Self {
|
fn from(entry: &DirEntry) -> Self {
|
||||||
return Self::new(entry.path(), Some(entry.file_name()), entry.metadata().as_ref());
|
let path = entry.path();
|
||||||
|
let path = path.canonicalize().unwrap_or(path);
|
||||||
|
return Self::new(path, Some(entry.file_name()), entry.metadata().as_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Path> for FileEntry {
|
impl From<&Path> for FileEntry {
|
||||||
fn from(path: &Path) -> Self {
|
fn from(path: &Path) -> Self {
|
||||||
return Self::new(path.to_path_buf(), path.file_name().map(|n| n.to_os_string()), path.metadata().as_ref());
|
let path = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
|
||||||
|
let name = path.file_name().map(OsStr::to_os_string);
|
||||||
|
let metadata = path.metadata();
|
||||||
|
return Self::new(path, name, metadata.as_ref());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
src/main.rs
22
src/main.rs
@ -1,6 +1,8 @@
|
|||||||
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
use std::path::Path;
|
use std::path::PathBuf;
|
||||||
|
use std::process::ExitCode;
|
||||||
|
|
||||||
use crossterm::{cursor, QueueableCommand, terminal};
|
use crossterm::{cursor, QueueableCommand, terminal};
|
||||||
|
|
||||||
@ -13,7 +15,19 @@ mod file;
|
|||||||
mod gui;
|
mod gui;
|
||||||
mod state;
|
mod state;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<ExitCode, Box<dyn Error>> {
|
||||||
|
let args = env::args_os().skip(1).collect::<Vec<_>>();
|
||||||
|
if args.len() > 1 {
|
||||||
|
println!("Too many arguments!");
|
||||||
|
return Ok(ExitCode::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = args.get(0).map(PathBuf::from).or_else(|| env::current_dir().ok());
|
||||||
|
if path.is_none() {
|
||||||
|
println!("Invalid path!");
|
||||||
|
return Ok(ExitCode::FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
terminal::enable_raw_mode()?;
|
terminal::enable_raw_mode()?;
|
||||||
stdout().queue(terminal::EnterAlternateScreen)?;
|
stdout().queue(terminal::EnterAlternateScreen)?;
|
||||||
stdout().queue(cursor::Hide)?;
|
stdout().queue(cursor::Hide)?;
|
||||||
@ -22,7 +36,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let mut view = View::stdout();
|
let mut view = View::stdout();
|
||||||
let actions = ActionMap::new();
|
let actions = ActionMap::new();
|
||||||
|
|
||||||
let mut state = State::with_root_path(Path::new("/"));
|
let mut state = State::with_root_path(&path.unwrap());
|
||||||
state.tree.expand(state.tree.root_id);
|
state.tree.expand(state.tree.root_id);
|
||||||
|
|
||||||
'render: loop {
|
'render: loop {
|
||||||
@ -46,5 +60,5 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
stdout().flush()?;
|
stdout().flush()?;
|
||||||
terminal::disable_raw_mode()?;
|
terminal::disable_raw_mode()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(ExitCode::SUCCESS)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user