summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrabite <rabite@posteo.de>2019-06-19 19:17:25 +0200
committerrabite <rabite@posteo.de>2019-06-19 19:30:11 +0200
commitfc32c58c9d2128b1337d9604dc5a542f618c9c3e (patch)
tree7ca8a31481e323e19204dd16d5adb258518054e4
parent89260e4312e79ac2e0623c6e7f18ee9a55e5bb08 (diff)
added auto-installer for configs
-rw-r--r--extra/config7
-rwxr-xr-xextra/previewers/7z3
-rwxr-xr-xextra/previewers/Z3
-rwxr-xr-xextra/previewers/bz3
-rwxr-xr-xextra/previewers/bz23
-rwxr-xr-xextra/previewers/cab3
-rwxr-xr-xextra/previewers/cpio3
-rwxr-xr-xextra/previewers/deb3
-rwxr-xr-xextra/previewers/definitions/archive3
-rwxr-xr-xextra/previewers/definitions/archive~3
-rwxr-xr-xextra/previewers/definitions/html6
-rw-r--r--extra/previewers/definitions/html~6
-rw-r--r--extra/previewers/definitions/openoffice3
-rwxr-xr-xextra/previewers/definitions/pdf5
-rwxr-xr-xextra/previewers/definitions/pdf~5
-rwxr-xr-xextra/previewers/definitions/text7
-rwxr-xr-xextra/previewers/gz3
-rwxr-xr-xextra/previewers/jar3
-rwxr-xr-xextra/previewers/lha3
-rwxr-xr-xextra/previewers/lzma3
-rwxr-xr-xextra/previewers/lzo3
-rwxr-xr-xextra/previewers/pdf5
-rwxr-xr-xextra/previewers/rar3
-rwxr-xr-xextra/previewers/rpm3
-rwxr-xr-xextra/previewers/tar3
-rwxr-xr-xextra/previewers/xpi3
-rwxr-xr-xextra/previewers/zip3
-rwxr-xr-xextra/scope.sh217
-rw-r--r--src/bookmarks.rs2
-rw-r--r--src/config.rs1
-rw-r--r--src/fail.rs7
-rw-r--r--src/file_browser.rs8
-rw-r--r--src/main.rs1
-rw-r--r--src/minibuffer.rs4
-rw-r--r--src/paths.rs2
-rw-r--r--src/tabview.rs10
-rw-r--r--src/term.rs11
-rw-r--r--src/widget.rs10
38 files changed, 141 insertions, 233 deletions
diff --git a/extra/config b/extra/config
new file mode 100644
index 0000000..c36e505
--- /dev/null
+++ b/extra/config
@@ -0,0 +1,7 @@
+animation=on
+show_hidden=off
+select_cmd=find -type f | fzf -m
+cd_cmd=find -type d | fzf
+icons=off
+media_autostart=off
+media_mute=off
diff --git a/extra/previewers/7z b/extra/previewers/7z
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/7z
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/Z b/extra/previewers/Z
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/Z
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/bz b/extra/previewers/bz
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/bz
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/bz2 b/extra/previewers/bz2
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/bz2
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/cab b/extra/previewers/cab
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/cab
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/cpio b/extra/previewers/cpio
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/cpio
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/deb b/extra/previewers/deb
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/deb
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/definitions/archive b/extra/previewers/definitions/archive
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/definitions/archive
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/definitions/archive~ b/extra/previewers/definitions/archive~
new file mode 100755
index 0000000..b367cdb
--- /dev/null
+++ b/extra/previewers/definitions/archive~
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z -l -p -- "${1}" \ No newline at end of file
diff --git a/extra/previewers/definitions/html b/extra/previewers/definitions/html
new file mode 100755
index 0000000..0f5e48a
--- /dev/null
+++ b/extra/previewers/definitions/html
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+w3m -dump "${1}" ||
+links -dump "${1}" ||
+elinks -dump "${1}" ||
+lynx -dump "${1}" \ No newline at end of file
diff --git a/extra/previewers/definitions/html~ b/extra/previewers/definitions/html~
new file mode 100644
index 0000000..fc0dbfe
--- /dev/null
+++ b/extra/previewers/definitions/html~
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+w3m -dump ||
+elinks -dump ||
+links -dump ||
+lynx -dump \ No newline at end of file
diff --git a/extra/previewers/definitions/openoffice b/extra/previewers/definitions/openoffice
new file mode 100644
index 0000000..91e56b0
--- /dev/null
+++ b/extra/previewers/definitions/openoffice
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+odt2text "${1}" 2> /dev/null \ No newline at end of file
diff --git a/extra/previewers/definitions/pdf b/extra/previewers/definitions/pdf
new file mode 100755
index 0000000..162edba
--- /dev/null
+++ b/extra/previewers/definitions/pdf
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+pdftotext -l 10 -layout -nopgbrk -q "${1}" -||
+mutool draw -F txt -i -- "${1}" ||
+exiftool "${1}" 2> /dev/null
diff --git a/extra/previewers/definitions/pdf~ b/extra/previewers/definitions/pdf~
new file mode 100755
index 0000000..0713675
--- /dev/null
+++ b/extra/previewers/definitions/pdf~
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+pdftotext -l 10 -layout -nopgbrk -q "${1}" - 2> /dev/null ||
+mutool draw -F txt -i -- "${FILE_PATH}" 1-10 2> /dev/null ||
+exiftool "${FILE_PATH}" 2> /dev/null
diff --git a/extra/previewers/definitions/text b/extra/previewers/definitions/text
new file mode 100755
index 0000000..88b8147
--- /dev/null
+++ b/extra/previewers/definitions/text
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+bat --plain --color=always --paging=never "${1}" --line-range 1:100 --tabs 8
+2>/dev/null && exit 5
+
+highlight --replace-tabs=4 --force -- "${1}"
+2>/dev/null && exit 5 \ No newline at end of file
diff --git a/extra/previewers/gz b/extra/previewers/gz
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/gz
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/jar b/extra/previewers/jar
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/jar
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/lha b/extra/previewers/lha
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/lha
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/lzma b/extra/previewers/lzma
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/lzma
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/lzo b/extra/previewers/lzo
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/lzo
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/pdf b/extra/previewers/pdf
new file mode 100755
index 0000000..162edba
--- /dev/null
+++ b/extra/previewers/pdf
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+pdftotext -l 10 -layout -nopgbrk -q "${1}" -||
+mutool draw -F txt -i -- "${1}" ||
+exiftool "${1}" 2> /dev/null
diff --git a/extra/previewers/rar b/extra/previewers/rar
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/rar
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/rpm b/extra/previewers/rpm
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/rpm
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/tar b/extra/previewers/tar
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/tar
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/xpi b/extra/previewers/xpi
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/xpi
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/previewers/zip b/extra/previewers/zip
new file mode 100755
index 0000000..25ee10d
--- /dev/null
+++ b/extra/previewers/zip
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+7z l -p -- "${1}"
diff --git a/extra/scope.sh b/extra/scope.sh
deleted file mode 100755
index 0edac07..0000000
--- a/extra/scope.sh
+++ /dev/null
@@ -1,217 +0,0 @@
-#!/usr/bin/env bash
-
-set -o noclobber -o noglob -o nounset -o pipefail
-IFS=$'\n'
-
-# If the option `use_preview_script` is set to `true`,
-# then this script will be called and its output will be displayed in ranger.
-# ANSI color codes are supported.
-# STDIN is disabled, so interactive scripts won't work properly
-
-# This script is considered a configuration file and must be updated manually.
-# It will be left untouched if you upgrade ranger.
-
-# Meanings of exit codes:
-# code | meaning | action of ranger
-# -----+------------+-------------------------------------------
-# 0 | success | Display stdout as preview
-# 1 | no preview | Display no preview at all
-# 2 | plain text | Display the plain content of the file
-# 3 | fix width | Don't reload when width changes
-# 4 | fix height | Don't reload when height changes
-# 5 | fix both | Don't ever reload
-# 6 | image | Display the image `$IMAGE_CACHE_PATH` points to as an image preview
-# 7 | image | Display the file directly as an image
-
-# Script arguments
-FILE_PATH="${1}" # Full path of the highlighted file
-PV_WIDTH="${2}" # Width of the preview pane (number of fitting characters)
-PV_HEIGHT="${3}" # Height of the preview pane (number of fitting characters)
-IMAGE_CACHE_PATH="${4}" # Full path that should be used to cache image preview
-PV_IMAGE_ENABLED="${5}" # 'True' if image previews are enabled, 'False' otherwise.
-
-FILE_EXTENSION="${FILE_PATH##*.}"
-FILE_EXTENSION_LOWER=$(echo ${FILE_EXTENSION} | tr '[:upper:]' '[:lower:]')
-
-# Settings
-HIGHLIGHT_SIZE_MAX=262143 # 256KiB
-HIGHLIGHT_TABWIDTH=8
-HIGHLIGHT_STYLE='pablo'
-PYGMENTIZE_STYLE='autumn'
-
-
-handle_extension() {
- case "${FILE_EXTENSION_LOWER}" in
- # Archive
- a|ace|bz2|xz|gz|alz|arc|arj|cab|cpio|deb|jar|lha|lz|lzh|lzma|lzo|\
- rpm|rz|t7z|tar|tlz|txz|tZ|tzo|war|xpi|Z|zip)
- 7z l -p -- "${FILE_PATH}" && exit 5
- #atool --list -- "${FILE_PATH}" && exit 5
- #bsdtar --list --file "${FILE_PATH}" && exit 5
- exit 1;;
- rar)
- # Avoid password prompt by providing empty password
- unrar lt -p- -- "${FILE_PATH}" && exit 5
- exit 1;;
- 7z)
- # Avoid password prompt by providing empty password
- 7z l -p -- "${FILE_PATH}" && exit 5
- exit 1;;
-
- # PDF
- pdf)
- # Preview as text conversion
- pdftotext -l 10 -nopgbrk -q -- "${FILE_PATH}" - | fmt -w ${PV_WIDTH} && exit 5
- mutool draw -F txt -i -- "${FILE_PATH}" 1-10 | fmt -w ${PV_WIDTH} && exit 5
- exiftool "${FILE_PATH}" && exit 5
- exit 1;;
-
- # BitTorrent
- torrent)
- transmission-show -- "${FILE_PATH}" && exit 5
- exit 1;;
-
- # OpenDocument
- odt|ods|odp|sxw)
- # Preview as text conversion
- odt2txt "${FILE_PATH}" && exit 5
- exit 1;;
-
- # HTML
- htm|html|xhtml)
- # Preview as text conversion
- w3m -dump "${FILE_PATH}" && exit 5
- lynx -dump -- "${FILE_PATH}" && exit 5
- elinks -dump "${FILE_PATH}" && exit 5
- ;; # Continue with next handler on failure
- esac
-}
-
-handle_image() {
- local mimetype="${1}"
- case "${mimetype}" in
- # SVG
- # image/svg+xml)
- # convert "${FILE_PATH}" "${IMAGE_CACHE_PATH}" && exit 6
- # exit 1;;
-
- # Image
- image/*)
- local orientation
- orientation="$( identify -format '%[EXIF:Orientation]\n' -- "${FILE_PATH}" )"
- # If orientation data is present and the image actually
- # needs rotating ("1" means no rotation)...
- if [[ -n "$orientation" && "$orientation" != 1 ]]; then
- # ...auto-rotate the image according to the EXIF data.
- convert -- "${FILE_PATH}" -auto-orient "${IMAGE_CACHE_PATH}" && exit 6
- fi
-
- # `w3mimgdisplay` will be called for all images (unless overriden as above),
- # but might fail for unsupported types.
- exit 7;;
-
- # Video
- # video/*)
- # # Thumbnail
- # ffmpegthumbnailer -i "${FILE_PATH}" -o "${IMAGE_CACHE_PATH}" -s 0 && exit 6
- # exit 1;;
- # PDF
- # application/pdf)
- # pdftoppm -f 1 -l 1 \
- # -scale-to-x 1920 \
- # -scale-to-y -1 \
- # -singlefile \
- # -jpeg -tiffcompression jpeg \
- # -- "${FILE_PATH}" "${IMAGE_CACHE_PATH%.*}" \
- # && exit 6 || exit 1;;
-
- # Preview archives using the first image inside.
- # (Very useful for comic book collections for example.)
- # application/zip|application/x-rar|application/x-7z-compressed|\
- # application/x-xz|application/x-bzip2|application/x-gzip|application/x-tar)
- # local fn=""; local fe=""
- # local zip=""; local rar=""; local tar=""; local bsd=""
- # case "${mimetype}" in
- # application/zip) zip=1 ;;
- # application/x-rar) rar=1 ;;
- # application/x-7z-compressed) ;;
- # *) tar=1 ;;
- # esac
- # { [ "$tar" ] && fn=$(tar --list --file "${FILE_PATH}"); } || \
- # { fn=$(bsdtar --list --file "${FILE_PATH}") && bsd=1 && tar=""; } || \
- # { [ "$rar" ] && fn=$(unrar lb -p- -- "${FILE_PATH}"); } || \
- # { [ "$zip" ] && fn=$(zipinfo -1 -- "${FILE_PATH}"); } || return
- #
- # fn=$(echo "$fn" | python -c "import sys; import mimetypes as m; \
- # [ print(l, end='') for l in sys.stdin if \
- # (m.guess_type(l[:-1])[0] or '').startswith('image/') ]" |\
- # sort -V | head -n 1)
- # [ "$fn" = "" ] && return
- # [ "$bsd" ] && fn=$(printf '%b' "$fn")
- #
- # [ "$tar" ] && tar --extract --to-stdout \
- # --file "${FILE_PATH}" -- "$fn" > "${IMAGE_CACHE_PATH}" && exit 6
- # fe=$(echo -n "$fn" | sed 's/[][*?\]/\\\0/g')
- # [ "$bsd" ] && bsdtar --extract --to-stdout \
- # --file "${FILE_PATH}" -- "$fe" > "${IMAGE_CACHE_PATH}" && exit 6
- # [ "$bsd" ] || [ "$tar" ] && rm -- "${IMAGE_CACHE_PATH}"
- # [ "$rar" ] && unrar p -p- -inul -- "${FILE_PATH}" "$fn" > \
- # "${IMAGE_CACHE_PATH}" && exit 6
- # [ "$zip" ] && unzip -pP "" -- "${FILE_PATH}" "$fe" > \
- # "${IMAGE_CACHE_PATH}" && exit 6
- # [ "$rar" ] || [ "$zip" ] && rm -- "${IMAGE_CACHE_PATH}"
- # ;;
- esac
-}
-
-handle_mime() {
- local mimetype="${1}"
- case "${mimetype}" in
- # Text
- text/* | */xml)
- # Syntax highlight
- if [[ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
- exit 2
- fi
- if [[ "$( tput colors )" -ge 256 ]]; then
- local pygmentize_format='terminal256'
- local highlight_format='xterm256'
- else
- local pygmentize_format='terminal'
- local highlight_format='ansi'
- fi
- highlight --replace-tabs="${HIGHLIGHT_TABWIDTH}" --out-format="${highlight_format}" \
- --style="${HIGHLIGHT_STYLE}" --force -- "${FILE_PATH}" && exit 5
- # pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}" -- "${FILE_PATH}" && exit 5
- exit 2;;
-
- # Image
- image/*)
- # Preview as text conversion
- # img2txt --gamma=0.6 --width="${PV_WIDTH}" -- "${FILE_PATH}" && exit 4
- exiftool "${FILE_PATH}" && exit 5
- exit 1;;
-
- # Video and audio
- video/* | audio/*)
- mediainfo "${FILE_PATH}" && exit 5
- exiftool "${FILE_PATH}" && exit 5
- exit 1;;
- esac
-}
-
-handle_fallback() {
- echo '----- File Type Classification -----' && file --dereference --brief -- "${FILE_PATH}" && exit 5
- exit 1
-}
-
-
-MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )"
-if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then
- handle_image "${MIMETYPE}"
-fi
-handle_extension
-handle_mime "${MIMETYPE}"
-handle_fallback
-
-exit 1
diff --git a/src/bookmarks.rs b/src/bookmarks.rs
index 8f0b649..208ace0 100644
--- a/src/bookmarks.rs
+++ b/src/bookmarks.rs
@@ -15,7 +15,7 @@ pub struct Bookmarks {
impl Bookmarks {
pub fn new() -> Bookmarks {
let mut bm = Bookmarks { mapping: HashMap::new() };
- bm.load().log();
+ bm.load().or_else(|_| HError::log("Couldn't load bookmarks!")).ok();
bm
}
pub fn add(&mut self, key: char, path: &str) -> HResult<()> {
diff --git a/src/config.rs b/src/config.rs
index 2803e3d..24bc995 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,6 +7,7 @@ use crate::paths;
use crate::fail::{HError, HResult, ErrorLog};
+
#[derive(Clone)]
// These are options, so we know if they have been set or not
struct ArgvConfig {
diff --git a/src/fail.rs b/src/fail.rs
index 0590ce5..0102fa0 100644
--- a/src/fail.rs
+++ b/src/fail.rs
@@ -104,8 +104,8 @@ pub enum HError {
}
impl HError {
- pub fn log<T>(log: String) -> HResult<T> {
- Err(HError::Log(log))
+ pub fn log<T>(log: &str) -> HResult<T> {
+ Err(HError::Log(String::from(log))).log_and()
}
pub fn quit() -> HResult<()> {
Err(HError::Quit)
@@ -243,7 +243,8 @@ impl From<std::io::Error> for HError {
impl From<failure::Error> for HError {
fn from(error: failure::Error) -> Self {
let err = HError::Error(format!("{}", error),
- Backtrace::new_arced());
+ Backtrace::new_arced()
+ );
err
}
}
diff --git a/src/file_browser.rs b/src/file_browser.rs
index 6d75f7d..019b77f 100644
--- a/src/file_browser.rs
+++ b/src/file_browser.rs
@@ -87,6 +87,14 @@ pub struct FileBrowser {
}
impl Tabbable for TabView<FileBrowser> {
+ fn on_new(&mut self) -> HResult<()> {
+ let core = self.core.clone();
+ std::thread::spawn(move || {
+ crate::config_installer::ensure_config(core).log();
+ });
+ Ok(())
+ }
+
fn new_tab(&mut self) -> HResult<()> {
let cur_tab = self.active_tab_();
diff --git a/src/main.rs b/src/main.rs
index c067e55..bc949fe 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -58,6 +58,7 @@ mod stats;
mod icon;
mod quick_actions;
mod trait_ext;
+mod config_installer;
#[cfg(feature = "img")]
mod imgview;
diff --git a/src/minibuffer.rs b/src/minibuffer.rs
index f7e0229..5c7ffcf 100644
--- a/src/minibuffer.rs
+++ b/src/minibuffer.rs
@@ -70,7 +70,7 @@ impl History {
}
fn add(&mut self, htype: &str, input: &str) {
- self.load().log();
+ self.load().ok();
let history = match self.history.get_mut(htype) {
Some(history) => history,
None => {
@@ -498,7 +498,7 @@ impl Widget for MiniBuffer {
}
fn after_draw(&self) -> HResult<()> {
- let cursor_pos = self.query.len() +
+ let cursor_pos = crate::term::string_len(&self.query) +
": ".len() +
self.position;
diff --git a/src/paths.rs b/src/paths.rs
index 2818604..fb5ac02 100644
--- a/src/paths.rs
+++ b/src/paths.rs
@@ -24,11 +24,9 @@ pub fn hunter_path() -> HResult<PathBuf> {
#[cfg(target_os = "macos")]
pub fn hunter_path() -> HResult<PathBuf> {
- dbg!("Finding path for macOS");
let mut hunter_path = home_path()?;
hunter_path.push(".config/");
hunter_path.push("hunter/");
- dbg!(&hunter_path);
Ok(hunter_path)
}
diff --git a/src/tabview.rs b/src/tabview.rs
index 8b87552..6afa10d 100644
--- a/src/tabview.rs
+++ b/src/tabview.rs
@@ -27,7 +27,7 @@ pub trait Tabbable {
}
fn on_refresh(&mut self) -> HResult<()> { Ok(()) }
fn on_config_loaded(&mut self) -> HResult<()> { Ok(()) }
-
+ fn on_new(&mut self) -> HResult<()> { Ok(()) }
}
@@ -41,11 +41,15 @@ pub struct TabView<T> where T: Widget, TabView<T>: Tabbable {
impl<T> TabView<T> where T: Widget, TabView<T>: Tabbable {
pub fn new(core: &WidgetCore) -> TabView<T> {
- TabView {
+ let mut tabview = TabView {
widgets: vec![],
active: 0,
core: core.clone()
- }
+ };
+
+ Tabbable::on_new(&mut tabview).log();
+
+ tabview
}
pub fn push_widget(&mut self, widget: T) -> HResult<()> {
diff --git a/src/term.rs b/src/term.rs
index 2d32773..088f026 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -251,6 +251,17 @@ fn get_tokens(string: &str) -> Vec<Token> {
tokens.0
}
+pub fn string_len(string: &str) -> usize {
+ let tokens = get_tokens(&string);
+
+ tokens.iter().fold(0, |len, token| {
+ match token {
+ Token::Text(text) => len + text.len(),
+ _ => len
+ }
+ })
+}
+
pub fn sized_string_u(string: &str, xsize: usize) -> String {
let tokens = get_tokens(&string);
diff --git a/src/widget.rs b/src/widget.rs
index 43c1fdf..6cb19eb 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -75,10 +75,10 @@ impl WidgetCore {
let (sender, receiver) = channel();
let status_bar_content = Arc::new(Mutex::new(None));
- let mut config = Async::new(|_| Ok(Config::load()?));
- let confsender = Arc::new(Mutex::new(sender.clone()));
+ let mut config = Async::new(move |_| Ok(Config::load()?));
+ let confsender = sender.clone();
config.on_ready(move |_, _| {
- confsender.lock().map(|s| s.send(Events::ConfigLoaded)).ok();
+ confsender.send(Events::ConfigLoaded).ok();
Ok(())
}).log();
config.run().log();
@@ -123,7 +123,7 @@ impl WidgetCore {
}
pub fn show_status(&self, status: &str) -> HResult<()> {
- HError::log::<()>(status.to_string()).log();
+ HError::log::<()>(status).ok();
{
let mut status_content = self.status_bar_content.lock()?;
*status_content = Some(status.to_string());
@@ -466,7 +466,7 @@ pub trait Widget {
self.get_core()?.screen()?.clear().log();
}
Events::ConfigLoaded => {
- self.get_core_mut()?.config.write()?.pull_async()?;
+ self.get_core_mut()?.config.write()?.pull_async().ok();
self.config_loaded().log();
}
_ => {}