Skip to content

Commit

Permalink
remove dependencies on rust nightly
Browse files Browse the repository at this point in the history
This commit comprises changes made by @bhavidsharma in PR rabite0#91 without
the other formatting changes.
rabite0#91

It took quite a while to scroll through and pick out the important bits.

This commit wasn't written with Bhavit but I thought it important to
include them as a co-author as it was originally their changes.

Co-authored-by: bhavidsharma <bhavitsharma@google.com>
  • Loading branch information
06kellyjac and bhavidsharma committed Oct 6, 2020
1 parent 355d9a3 commit c21bb7a
Show file tree
Hide file tree
Showing 24 changed files with 151 additions and 160 deletions.
16 changes: 0 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
extern crate termion;
extern crate rustc_version;

use rustc_version::{version_meta, Channel};

// use std::process::Command;


fn main() -> Result<(),()> {
// Bail out if compiler isn't a nightly
if let Ok(false) = version_meta().map(|m| m.channel == Channel::Nightly) {
eprint!("{}", termion::color::Fg(termion::color::Red));
eprint!("{}", termion::style::Bold);
eprint!("{}", termion::style::Underline);
eprintln!("NIHGTLY COMPILER required");
eprintln!("Please install a nighlty compiler to proceed: https://rustup.rs/");
eprint!("{}", termion::style::Reset);
eprintln!("rustup toolchain install nightly");
eprintln!("source ~/.cargo/env");

return Err(());
}

// crates.io doesn't allow question marks in file names
// So we just stuff that in an archive for distribution

Expand Down
8 changes: 4 additions & 4 deletions src/bookmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Bookmarks {
Ok(())
}
pub fn get(&self, key: char) -> HResult<&String> {
let path = self.mapping.get(&key)?;
let path = self.mapping.get(&key).ok_or_else(|| HError::NoneError)?;
Ok(path)
}
pub fn load(&mut self) -> HResult<()> {
Expand Down Expand Up @@ -105,7 +105,7 @@ impl BMPopup {
self.get_core()?.clear()?;

let bookmark = self.bookmark_path.take();
Ok(bookmark?)
Ok(bookmark.ok_or_else(|| HError::NoneError)?)
}

pub fn add(&mut self, path: &str) -> HResult<()> {
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Widget for BMPopup {
let mut drawlist = String::new();

if !self.add_mode {
let cwd = self.bookmark_path.as_ref()?;
let cwd = self.bookmark_path.as_ref().ok_or_else(|| HError::NoneError)?;
drawlist += &self.render_line(ypos, &'`', cwd);
}

Expand All @@ -191,7 +191,7 @@ impl Widget for BMPopup {
Key::Char('`') => return HError::popup_finnished(),
Key::Char(key) => {
if self.add_mode {
let path = self.bookmark_path.take()?;
let path = self.bookmark_path.take().ok_or_else(|| HError::NoneError)?;
self.bookmarks.add(key, &path)?;
self.add_mode = false;
self.bookmarks.save().log();
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub struct Config {
pub media_mute: bool,
pub media_previewer: String,
pub media_previewer_exists: bool,
pub ratios: Vec::<usize>,
pub ratios: Vec<usize>,
pub graphics: String,
pub keybinds: KeyBinds,
}
Expand Down
4 changes: 2 additions & 2 deletions src/config_installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn has_config() -> HResult<bool> {

fn install_config_all() -> HResult<()> {
let hunter_dir = crate::paths::hunter_path()?;
let config_dir = hunter_dir.parent()?;
let config_dir = hunter_dir.parent().ok_or_else(|| HError::NoneError)?;

if !hunter_dir.exists() {
// create if non-existing
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn update_config(core: WidgetCore, force: bool) -> HResult<()> {
fn update_dir<P: AsRef<Path>>(source: P, target: P) -> HResult<()> {
for file in std::fs::read_dir(source)? {
let file_path = file?.path();
let file_name = file_path.file_name()?;
let file_name = file_path.file_name().ok_or_else(|| HError::NoneError)?;
let target_path = target.as_ref().join(file_name);

if file_path.is_dir() {
Expand Down
12 changes: 6 additions & 6 deletions src/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ impl<T> From<std::sync::TryLockError<T>> for HError {
}
}

impl From<std::option::NoneError> for HError {
fn from(_error: std::option::NoneError) -> Self {
let err = HError::NoneError;
err
}
}
// impl From<std::option::NoneError> for HError {
// fn from(_error: std::option::NoneError) -> Self {
// let err = HError::NoneError;
// err
// }
// }

impl From<std::path::StripPrefixError> for HError {
fn from(error: std::path::StripPrefixError) -> Self {
Expand Down
33 changes: 17 additions & 16 deletions src/file_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ impl FileBrowser {
.take(1)
.map(|path| {
std::path::PathBuf::from(path)
}).last()?;
}).last()
.ok_or_else(|| HError::NoneError)?;
let left_path = main_path.parent().map(|p| p.to_path_buf());

let cache = fs_cache.clone();
Expand Down Expand Up @@ -433,7 +434,7 @@ impl FileBrowser {
.find(|&file| file.is_dir())
.cloned();

self.main_widget_goto(&next_dir?).log();
self.main_widget_goto(&next_dir.ok_or_else(|| HError::NoneError)?).log();

Ok(())
}
Expand All @@ -450,7 +451,7 @@ impl FileBrowser {
.find(|&file| file.is_dir())
.cloned();

self.main_widget_goto(&next_dir?).log();
self.main_widget_goto(&next_dir.ok_or_else(|| HError::NoneError)?).log();

Ok(())
}
Expand Down Expand Up @@ -612,7 +613,7 @@ impl FileBrowser {
}

pub fn goto_prev_cwd(&mut self) -> HResult<()> {
let prev_cwd = self.prev_cwd.take()?;
let prev_cwd = self.prev_cwd.take().ok_or_else(|| HError::NoneError)?;
self.main_widget_goto(&prev_cwd)?;
Ok(())
}
Expand Down Expand Up @@ -820,7 +821,7 @@ impl FileBrowser {
}

pub fn main_async_widget_mut(&mut self) -> HResult<&mut AsyncWidget<ListView<Files>>> {
let widget = self.columns.active_widget_mut()?;
let widget = self.columns.active_widget_mut().ok_or_else(|| HError::NoneError)?;

let widget = match widget {
FileBrowserWidgets::FileList(filelist) => filelist,
Expand All @@ -830,7 +831,7 @@ impl FileBrowser {
}

pub fn main_widget(&self) -> HResult<&ListView<Files>> {
let widget = self.columns.active_widget()?;
let widget = self.columns.active_widget().ok_or_else(|| HError::NoneError)?;

let widget = match widget {
FileBrowserWidgets::FileList(filelist) => filelist.widget(),
Expand All @@ -840,7 +841,7 @@ impl FileBrowser {
}

pub fn main_widget_mut(&mut self) -> HResult<&mut ListView<Files>> {
let widget = self.columns.active_widget_mut()?;
let widget = self.columns.active_widget_mut().ok_or_else(|| HError::NoneError)?;

let widget = match widget {
FileBrowserWidgets::FileList(filelist) => filelist.widget_mut(),
Expand All @@ -850,38 +851,38 @@ impl FileBrowser {
}

pub fn left_async_widget_mut(&mut self) -> HResult<&mut AsyncWidget<ListView<Files>>> {
let widget = match self.columns.widgets.get_mut(0)? {
let widget = match self.columns.widgets.get_mut(0).ok_or_else(|| HError::NoneError)? {
FileBrowserWidgets::FileList(filelist) => filelist,
_ => { return HError::wrong_widget("previewer", "filelist"); }
};
Ok(widget)
}

pub fn left_widget(&self) -> HResult<&ListView<Files>> {
let widget = match self.columns.widgets.get(0)? {
let widget = match self.columns.widgets.get(0).ok_or_else(|| HError::NoneError)? {
FileBrowserWidgets::FileList(filelist) => filelist.widget(),
_ => { return HError::wrong_widget("previewer", "filelist"); }
};
widget
}

pub fn left_widget_mut(&mut self) -> HResult<&mut ListView<Files>> {
let widget = match self.columns.widgets.get_mut(0)? {
let widget = match self.columns.widgets.get_mut(0).ok_or_else(|| HError::NoneError)? {
FileBrowserWidgets::FileList(filelist) => filelist.widget_mut(),
_ => { return HError::wrong_widget("previewer", "filelist"); }
};
widget
}

pub fn preview_widget(&self) -> HResult<&Previewer> {
match self.columns.widgets.get(2)? {
match self.columns.widgets.get(2).ok_or_else(|| HError::NoneError)? {
FileBrowserWidgets::Previewer(previewer) => Ok(previewer),
_ => { return HError::wrong_widget("filelist", "previewer"); }
}
}

pub fn preview_widget_mut(&mut self) -> HResult<&mut Previewer> {
match self.columns.widgets.get_mut(2)? {
match self.columns.widgets.get_mut(2).ok_or_else(|| HError::NoneError)? {
FileBrowserWidgets::Previewer(previewer) => Ok(previewer),
_ => { return HError::wrong_widget("filelist", "previewer"); }
}
Expand Down Expand Up @@ -938,11 +939,11 @@ impl FileBrowser {
format!("\"{}\" ", &f.path.to_string_lossy())
}).collect::<String>();

let mut filepath = dirs_2::home_dir()?;
let mut filepath = dirs_2::home_dir().ok_or_else(|| HError::NoneError)?;
filepath.push(".hunter_cwd");

let output = format!("HUNTER_CWD=\"{}\"\nF=\"{}\"\nMF=({})\n",
cwd.to_str()?,
cwd.to_str().ok_or_else(|| HError::NoneError)?,
selected_file,
selected_files);

Expand Down Expand Up @@ -1174,7 +1175,7 @@ impl FileBrowser {
continue;
}

let dir_path = file_path.parent()?;
let dir_path = file_path.parent().ok_or_else(|| HError::NoneError)?;
if self.cwd.path != dir_path {
let file_dir = File::new_from_path(&dir_path);

Expand Down Expand Up @@ -1555,7 +1556,7 @@ impl Widget for FileBrowser {
return Ok(());
}
(_, Some(2)) => {
self.columns.active_widget_mut()?.on_key(key)?;
self.columns.active_widget_mut().ok_or_else(|| HError::NoneError)?.on_key(key)?;
return Ok(());
}
_ => {}
Expand Down
Loading

0 comments on commit c21bb7a

Please sign in to comment.