You are not logged in.

#1601 2013-02-14 14:55:04

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

@bslackr, the same for me.
Here is my python script to replace rifle_sxiv.sh. Obviously, you should edit the last line to make yourself comfortable.

#!/usr/bin/env python3

from os  import listdir
from os  import path
from sys import argv
from subprocess import Popen

filename   = argv[1]
extensions = {'.jpg', '.jpeg', '.png', '.gif', '.tif'}
images  = []

basename = path.basename(filename)
dirname  = path.dirname(filename)

for item in listdir(dirname):
    extension = path.splitext(item)[1]
    if extension.lower() in extensions:
        images.append(item)

images.sort(key=str.lower)
position  = str(images.index(basename) + 1)
images = [path.join(dirname, filename) for filename in images]
Popen(['sxiv', '-Fqdg', '+0+12', '-n', position] + images)

Last edited by loop (2013-02-14 14:56:54)

Offline

#1602 2013-02-14 15:25:48

bslackr
Member
Registered: 2012-01-27
Posts: 131

Re: Ranger, a textbased filemanager

Awesome, got this to work. Thanks.

Offline

#1603 2013-02-14 19:04:19

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

loop wrote:

As opposed to :find, :travel executes directories only, but not files, right?

It's not quite that simple. You can execute two ways, automatically and manually.

If it's automatic, as in there's only one file or folder left displayed, it will attempt to cd to that file or folder. This fails silently with files, evidently.

Otherwise, you've pressed ENTER (or equivalent) and then :travel will use "self.fm.move(right=1)" which normally equates to pressing the right button on your keyboard. This will either enter a directory or run a file, but keep the :travel prompt open.

Please note that the implementation a few posts above is broken in a few key ways, as I was "testing" in a very hurried way:

When I updated this last time, I did it too fast and a couple of easy-to-spot errors came through*. And then hut updated Ranger again, reversing a fix I applied to this so that on the newest newest Ranger it didn't work although the older one did...

Basically, get this and update Ranger again and you should have a much more fun time than with any of the older ones.

from ranger.fsobject import directory

old_accept_file = directory.accept_file

directory.tmp_filter = ""
directory.tmp_filter_dir = ""

def accept_file(fname, dirname, hidden_filter, name_filter):
    # Apply all of the old filters
    if old_accept_file(fname, dirname, hidden_filter, name_filter):

        if dirname != directory.tmp_filter_dir:
            return True

        try:
            ifname = iter(fname)
            for letter in directory.tmp_filter:
                # Scan across ifname for letter
                while True:
                    # if lowercase, don't be case sensitive
                    if letter.islower():
                        if letter == next(ifname).lower():
                            break

                    else:
                        if letter == next(ifname):
                            break

            # tmp_filter has ended before ifname, so is contained sequentially in ifname
            return True

        # ifname has ended before tmp_filter, so doesn't contain all of tmp_filter sequentially
        except StopIteration:
            return False

    return False

directory.accept_file = accept_file

class narrow(Command):
    """
    :narrow <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection and removes the filter.
    """

    def execute(self):
        self.cancel() # Clean up
        self.fm.move(right=1)

    def cancel(self):
        directory.tmp_filter = ""
        self.fm.thisdir.load_content(schedule=False)

    def quick(self):
        directory.tmp_filter = self.rest(1)
        directory.tmp_filter_dir = self.fm.thisdir.path
        self.fm.thisdir.load_content(schedule=False)

    def tab(self):
        if self.fm.env.cwd.files[-1] is not self.fm.env.cf:
            self.fm.move(down=1)
        else:
            self.fm.move(to=0)

class travel(Command):
    """
    :travel <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection, removes the filter and starts another :travel command.
    """

    def execute(self, *, special=False):
        self.cancel() # Clean

        if special:
            self.fm.cd(special)

            # Don't block ".." to allow chaining
            if special != "..":
                self.fm.block_input(0.5)

            special = False

        else:
            self.fm.move(right=1)

        self.fm.open_console(self.__class__.__name__ + " ")

    def cancel(self):
        directory.tmp_filter = ""
        self.fm.thisdir.load_content(schedule=False)

    def quick(self):
        arg = self.rest(1)

        directory.tmp_filter = arg
        directory.tmp_filter_dir = self.fm.thisdir.path
        self.fm.thisdir.load_content(schedule=False)

        if arg == ".":
            return # Make sure we can always use ".."

        elif arg == "..":
            return self.execute(special="..")

        # Quick-travel
        elif len(self.fm.env.cwd.files) == 1:
            return self.execute(special=self.fm.env.cwd.files[0].basename)

    def tab(self):
        if self.fm.env.cwd.files[-1] is self.fm.env.cf:
            # We're at the bottom, so wrap
            self.fm.move(to=0)
        else:
            self.fm.move(down=1)

* Notably lowercase letters in your search had a 50% chance of not matching uppercase letters (wuu?!), :travel didn't always chain properly (depending on the time of day ;P) and directories other than the current one could be filtered (this was such an obvious error :/).

~~PSHHSKK~~I apologize for the added hackiness of the code in this latest update~~PPSHKKKSH~~

Offline

#1604 2013-02-14 21:36:55

mkaito
Member
From: Spain
Registered: 2010-06-12
Posts: 126
Website

Re: Ranger, a textbased filemanager

Is there some way to keep these nifty little commands in separate modules? I don't want to copy and edit commands.py if I'm not overriding anything from the default config. It'll just cause me trouble if the stock config is updated down the line.


Fear me! I have root! Sometimes...

Offline

#1605 2013-02-15 01:22:11

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

mkaito wrote:

Is there some way to keep these nifty little commands in separate modules? I don't want to copy and edit commands.py if I'm not overriding anything from the default config. It'll just cause me trouble if the stock config is updated down the line.

You can actually keep a mostly blank commands.py, as the default and "new" ones are amalgamated.

You'll probably want

from ranger.api.commands import *

at the top of your commands.py (it lets you define commands), but other than that it can contain nothing but the new stuff.

My commands.py as an example (paraphrased):

from ranger.api.commands import *

# SORTY STUFF
from ranger.fsobject.directory import Directory
def sort_by_extension(path): ...
def join_sorts(*sort_functions): ...
Directory.sort_dict["e"] = join_sorts(sort_by_extension, Directory.sort_dict["basename"])

# HACKY STUFF FOR COMMANDY STUFF
from ranger.fsobject import directory
def accept_file(fname, dirname, hidden_filter, name_filter): ...
directory.accept_file = accept_file

# COMMANDY STUFF
class narrow(Command): ...
class travel(Command): ...
class delete(Command): ...

Offline

#1606 2013-02-15 03:23:27

mkaito
Member
From: Spain
Registered: 2010-06-12
Posts: 126
Website

Re: Ranger, a textbased filemanager

That's great smile Thanks!


Fear me! I have root! Sometimes...

Offline

#1607 2013-02-15 16:18:39

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

loop wrote:

Hello everybody!
Recently I've tried 'extracthere' command from https://wiki.archlinux.org/index.php/Ranger#Extraction and there is a problem with  ranger-master 1.5.5.  When I extract a big rar archive (about 700 Mb) only about first 140 Mb are extracted, then the task hangs untill be removed manually. But with '1l' hotkey (aunpack -- "$@") all works fine. Is the code of 'extracthere' obsolete?

Some updates:
Even when the extraction task is killed with 'dd' in taskview, the aunpack process still exists. After some seconds aunpack successfully extracts the remain part of the archive.

It's not obsolete as far as I can see. It works fine for me on ranger-git. The problem that "dd" doesn't kill the process seems to be a bug in aunpack: when you kill aunpack, the process that extracts the stuff continues to run.


Army wrote:
hut wrote:

@Army: videos? are you drunk? smile I think gifs are supported theoretically, see http://w3m.cvs.sourceforge.net/viewvc/w … README.img

I hope I was sober wink No I just didn't express myself right, I thought of preview thumbnails, e.g. call a script which creates an image which then is being displayed.

That's a great way to slow down ranger^UThat's a great idea, this way you could display previews of PDFs in color, html documents, videos, sound files by analyzing the spectrum, and so on smile I'll keep it in mind.


Veedrac wrote:

I'd like to add a request too. Can you skip the previewing of images > 1MB or so? I'll put in a feature request if others agree.

I plan to implement loading of images in the background, so big images should be no problem.

OK100 wrote:

If I write window dimensions directly into the function like this:

def _get_font_dimensions():
    """
    Get the height and width of a character displayed in the terminal in
    pixels.
    """
    s = struct.pack("HHHH", 0, 0, 0, 0)
    fd_stdout = sys.stdout.fileno()
    x = fcntl.ioctl(fd_stdout, termios.TIOCGWINSZ, s)
    rows, cols, xpixels, ypixels = struct.unpack("HHHH", x)

    xpixels, ypixels = (1024, 584)

    return (xpixels // cols), (ypixels // rows)

the image is displayed correctly:
http://ompldr.org/taGZsZw

That's good to hear, though it doesn't solve the problem of automatically determining the window dimensions

bslackr wrote:

I'm trying to get sxiv to open all the images in the current directory starting with the current file (like it says in the documentation), but sxiv only opens the one file. I put

mime^image,              X, flag f = ~/.config/ranger/rifle_sxiv.sh "$@"

in my rifle.conf and downloaded the script and put it in the right place, but it's a no go.

~ % ranger --version
ranger-master 1.5.5

Python 3.3.0 (default, Dec 22 2012, 21:02:07) 
[GCC 4.7.2]

It works for me, am I missing something? Does it work when you simply run "~/.config/ranger/rifle_sxiv.sh /path/to/some/image.jpg"?

Veedrac wrote:
from ranger.fsobject import directory

old_accept_file = directory.accept_file

directory.tmp_filter = ""
directory.tmp_filter_dir = ""

def accept_file(fname, dirname, hidden_filter, name_filter):
    # Apply all of the old filters
    if old_accept_file(fname, dirname, hidden_filter, name_filter):

        if dirname != directory.tmp_filter_dir:
            return True

        try:
            ifname = iter(fname)
            for letter in directory.tmp_filter:
                # Scan across ifname for letter
                while True:
                    # if lowercase, don't be case sensitive
                    if letter.islower():
                        if letter == next(ifname).lower():
                            break

                    else:
                        if letter == next(ifname):
                            break

            # tmp_filter has ended before ifname, so is contained sequentially in ifname
            return True

        # ifname has ended before tmp_filter, so doesn't contain all of tmp_filter sequentially
        except StopIteration:
            return False

    return False

directory.accept_file = accept_file

class narrow(Command):
    """
    :narrow <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection and removes the filter.
    """

    def execute(self):
        self.cancel() # Clean up
        self.fm.move(right=1)

    def cancel(self):
        directory.tmp_filter = ""
        self.fm.thisdir.load_content(schedule=False)

    def quick(self):
        directory.tmp_filter = self.rest(1)
        directory.tmp_filter_dir = self.fm.thisdir.path
        self.fm.thisdir.load_content(schedule=False)

    def tab(self):
        if self.fm.env.cwd.files[-1] is not self.fm.env.cf:
            self.fm.move(down=1)
        else:
            self.fm.move(to=0)

class travel(Command):
    """
    :travel <string>

    Displays only the files which contain <string> in their basename.
    Unlike :filter, this updates in real-time and, when executed, executes the selection, removes the filter and starts another :travel command.
    """

    def execute(self, *, special=False):
        self.cancel() # Clean

        if special:
            self.fm.cd(special)

            # Don't block ".." to allow chaining
            if special != "..":
                self.fm.block_input(0.5)

            special = False

        else:
            self.fm.move(right=1)

        self.fm.open_console(self.__class__.__name__ + " ")

    def cancel(self):
        directory.tmp_filter = ""
        self.fm.thisdir.load_content(schedule=False)

    def quick(self):
        arg = self.rest(1)

        directory.tmp_filter = arg
        directory.tmp_filter_dir = self.fm.thisdir.path
        self.fm.thisdir.load_content(schedule=False)

        if arg == ".":
            return # Make sure we can always use ".."

        elif arg == "..":
            return self.execute(special="..")

        # Quick-travel
        elif len(self.fm.env.cwd.files) == 1:
            return self.execute(special=self.fm.env.cwd.files[0].basename)

    def tab(self):
        if self.fm.env.cwd.files[-1] is self.fm.env.cf:
            # We're at the bottom, so wrap
            self.fm.move(to=0)
        else:
            self.fm.move(down=1)

* Notably lowercase letters in your search had a 50% chance of not matching uppercase letters (wuu?!), :travel didn't always chain properly (depending on the time of day ;P) and directories other than the current one could be filtered (this was such an obvious error hmm).

~~PSHHSKK~~I apologize for the added hackiness of the code in this latest update~~PPSHKKKSH~~

I'm gonna add a modified version of this to ranger-git today.


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1608 2013-02-15 17:08:17

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

hut wrote:
loop wrote:

Hello everybody!
Recently I've tried 'extracthere' command from https://wiki.archlinux.org/index.php/Ranger#Extraction and there is a problem with  ranger-master 1.5.5.  When I extract a big rar archive (about 700 Mb) only about first 140 Mb are extracted, then the task hangs untill be removed manually. But with '1l' hotkey (aunpack -- "$@") all works fine. Is the code of 'extracthere' obsolete?

Some updates:
Even when the extraction task is killed with 'dd' in taskview, the aunpack process still exists. After some seconds aunpack successfully extracts the remain part of the archive.

It's not obsolete as far as I can see. It works fine for me on ranger-git. The problem that "dd" doesn't kill the process seems to be a bug in aunpack: when you kill aunpack, the process that extracts the stuff continues to run.

Ok, got it. Maybe that was my unlucky day with exactly that archive.

hut wrote:

It works for me, am I missing something? Does it work when you simply run "~/.config/ranger/rifle_sxiv.sh /path/to/some/image.jpg"?

Checked it. There wasn't 'realpath' utility installed in my case.

Offline

#1609 2013-02-15 18:32:56

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

hut wrote:
Army wrote:
hut wrote:

@Army: videos? are you drunk? smile I think gifs are supported theoretically, see http://w3m.cvs.sourceforge.net/viewvc/w … README.img

I hope I was sober wink No I just didn't express myself right, I thought of preview thumbnails, e.g. call a script which creates an image which then is being displayed.

That's a great way to slow down ranger^UThat's a great idea, this way you could display previews of PDFs in color, html documents, videos, sound files by analyzing the spectrum, and so on smile I'll keep it in mind.

I can't tell how serious *any* of that was wink.

The command I gave to get an image preview (ffmpeg -loglevel quiet -i INPUTFILE -f mjpeg -t 0.0001 -ss 0 -y OUTPUTFILE) took this long for four different files:

0.32s user 0.12s system 23% cpu 1.850 total
0.34s user 0.06s system 114% cpu 0.353 total
0.27s user 0.09s system 84% cpu 0.436 total
0.30s user 0.07s system 90% cpu 0.405 total

That'd be completely bearable as a background process.
It takes 10 times as long if you use "-t 5", though, so you'll want to stick with previewing only the first frame.
As an extra point of data, quite a few graphical file managers make previews for all of their videos, and some even have an animation-on-hover effect. I'm not sure how they make those previews but it can't be too resource intensive, obviously.

On a second note, for pdfs:

pdftoppm -singlefile -png FILE.pdf -scale-to 450

As long as "-scale-to" is low-ish, this is quite fast.

I don't like the idea of html or sound image previews, personally, and I couldn't find an easy way to do them.

For svgs:

rsvg-convert -w 500 FILE.svg

also takes < 0.5s for simple-ish svgs.

And I bet there are more!

hut wrote:
Veedrac wrote:

I'd like to add a request too. Can you skip the previewing of images > 1MB or so? I'll put in a feature request if others agree.

I plan to implement loading of images in the background, so big images should be no problem.

Thank you, that'll do fine! ^^

Offline

#1610 2013-02-15 19:07:43

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

Veedrac wrote:
hut wrote:
Army wrote:

I hope I was sober wink No I just didn't express myself right, I thought of preview thumbnails, e.g. call a script which creates an image which then is being displayed.

That's a great way to slow down ranger^UThat's a great idea, this way you could display previews of PDFs in color, html documents, videos, sound files by analyzing the spectrum, and so on smile I'll keep it in mind.

I can't tell how serious *any* of that was wink.

The last part was serious. I wrote the first part because the idea does sound silly at first, but when you think about it, all ranger needs to do is to provide an interface for a shell script (like scope.sh), the actual work is done by programs that are already out there. smile So it's actually a pretty good idea.


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

#1611 2013-02-16 00:38:58

mkaito
Member
From: Spain
Registered: 2010-06-12
Posts: 126
Website

Re: Ranger, a textbased filemanager

I've been playing with the new :narrow and :travel commands. I have a question, and an idea:

  • What exactly is the difference between these two?

  • Could either or both set the mark on all visible files upon execution, perhaps with a flag? Think narrowing down a bunch of video files, then sending all of them to mplayer kinda use case. On the fly playlists on steroids.


Fear me! I have root! Sometimes...

Offline

#1612 2013-02-16 01:12:18

bslackr
Member
Registered: 2012-01-27
Posts: 131

Re: Ranger, a textbased filemanager

hut wrote:
bslackr wrote:

I'm trying to get sxiv to open all the images in the current directory starting with the current file (like it says in the documentation), but sxiv only opens the one file. I put

mime^image,              X, flag f = ~/.config/ranger/rifle_sxiv.sh "$@"

in my rifle.conf and downloaded the script and put it in the right place, but it's a no go.

~ % ranger --version
ranger-master 1.5.5

Python 3.3.0 (default, Dec 22 2012, 21:02:07) 
[GCC 4.7.2]

It works for me, am I missing something? Does it work when you simply run "~/.config/ranger/rifle_sxiv.sh /path/to/some/image.jpg"?

No, I was missing something ... a space between mime and ^image. tongue

Offline

#1613 2013-02-16 11:25:17

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Ranger, a textbased filemanager

hut wrote:

That's a great way to slow down ranger^UThat's a great idea, this way you could display previews of PDFs in color, html documents, videos, sound files by analyzing the spectrum, and so on smile I'll keep it in mind.

I disabled previews because it made ranger slow. Now I only get a preview hitting F3. This way, there's no problem with those commands.

But as you said, it's just an idea. If it makes sense or not to implement it, is your choice.

Offline

#1614 2013-02-16 12:12:37

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Just in case, sxiv can cache images thumbnails. Maybe it can be used.

Offline

#1615 2013-02-16 21:20:18

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

mkaito wrote:

I've been playing with the new :narrow and :travel commands. I have a question, and an idea:

  • What exactly is the difference between these two?

:travel automatically chains, so you can only quit it with ESC.
:travel automatically goes into directories if there is only one left displayed.
:travel activates ".." automatically, :narrow waits for execution

mkaito wrote:
  • Could either or both set the mark on all visible files upon execution, perhaps with a flag? Think narrowing down a bunch of video files, then sending all of them to mplayer kinda use case. On the fly playlists on steroids.

That sounds really fun. It, I think, would be a new command (:multimark or something) as opposed to a flag. It should be easy, methinks, given how much power Ranger's commands have.

Army wrote:

I disabled previews because it made ranger slow. Now I only get a preview hitting F3.

That actually gives me quite a good idea.
There should be "use_preview_script_only_on_full_preview" option, so it does plain text previews (fast) until you ask for more (F3 or "i").

Last edited by Veedrac (2013-02-16 22:48:26)

Offline

#1616 2013-02-16 22:54:19

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

Veedrac wrote:
mkaito wrote:
  • Could either or both set the mark on all visible files upon execution, perhaps with a flag? Think narrowing down a bunch of video files, then sending all of them to mplayer kinda use case. On the fly playlists on steroids.

That sounds really fun. It, I think, would be a new command (:multimark or something) as opposed to a flag. It should be easy, methinks, given how much power Ranger's commands have.

Jeez, that was easy.

Just add this to your commands.py:

class multimark(narrow):
    def execute(self):
        self.fm.execute_console("mark_files all=True val=True")
        self.cancel() # Clean up

Note that this assumes you're using the newest, newest, newest Ranger from git which has these commands built-in, but it should (maybe ;P) work on the one I've posted on these forums. Ranger's been changing fast, these days.

Last edited by Veedrac (2013-02-16 22:57:45)

Offline

#1617 2013-02-17 06:15:32

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Hello, everybody!

While traveling with fancy :travel command I'm trying to get console closed with </> key (as it's much closer to my fingers than <Esc> key is). So, I modified the 'quick' function from 'narrow' class like this:

def quick(self):
    self.fm.thisdir.temporary_filter = self.build_regex(self.rest(1))
    self.fm.thisdir.load_content(schedule=False)
    if self.rest(1) == '/':
        self.fm.ui.console.close()

But 'self.fm.ui.console.close()' crashes ranger. Is there a simple way to solve the problem, or I should just train my fingers to get them longer? smile

Offline

#1618 2013-02-17 06:45:38

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

loop wrote:

Hello, everybody!

While traveling with fancy :travel command I'm trying to get console closed with </> key (as it's much closer to my fingers than <Esc> key is). So, I modified the 'quick' function from 'narrow' class like this:

def quick(self):
    self.fm.thisdir.temporary_filter = self.build_regex(self.rest(1))
    self.fm.thisdir.load_content(schedule=False)
    if self.rest(1) == '/':
        self.fm.ui.console.close()

But 'self.fm.ui.console.close()' crashes ranger. Is there a simple way to solve the problem, or I should just train my fingers to get them longer? smile

I'd do it like this. Add:

if self.rest(1).endswith("/"): return True

or

if self.rest(1) == "/": return True

to both the end of "quick" and the start of "execute" (but after "self.cancel()").

Offline

#1619 2013-02-17 08:12:10

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Veedrac wrote:

I'd do it like this. Add:

if self.rest(1).endswith("/"): return True

or

if self.rest(1) == "/": return True

to both the end of "quick" and the start of "execute" (but after "self.cancel()").

So, I've changed the code to this:

class narrow(Command):
...
    def execute(self):
        self.cancel() # Clean up
        if self.rest(1) == "/":
            return True
        elif self.rest(1) == "..":
            self.fm.move(left=1)
        else:
            self.fm.move(right=1)
....
    def quick(self):
        self.fm.thisdir.temporary_filter = self.build_regex(self.rest(1))
        self.fm.thisdir.load_content(schedule=False)
        if self.rest(1) == "/":
           return True

And now I can escape with </> key from :narrow command, but :travel command not escapes and tries to filter filenames having "/".
May it be caused that your recommendations are based on your version of :narrow and :travel commands, while I'm using @hut's version from ranger-git?
Anyway, thank you for help smile

Offline

#1620 2013-02-17 08:20:38

Sirsurthur
Member
Registered: 2009-02-02
Posts: 124

Re: Ranger, a textbased filemanager

Hello Hut,

Since the latest pull in git, it looks like the preview with w3m is not working for me anymore (great new feature by the way !).

When I select a picture, I get the following output : 'str' does not support the buffer interface ?

Best regards,

Offline

#1621 2013-02-17 14:33:52

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

loop wrote:
Veedrac wrote:

I'd do it like this. Add:

if self.rest(1).endswith("/"): return True

or

if self.rest(1) == "/": return True

to both the end of "quick" and the start of "execute" (but after "self.cancel()").

So, I've changed the code to this:

class narrow(Command):
...
    def execute(self):
        self.cancel() # Clean up
        if self.rest(1) == "/":
            return True
        elif self.rest(1) == "..":
            self.fm.move(left=1)
        else:
            self.fm.move(right=1)
....
    def quick(self):
        self.fm.thisdir.temporary_filter = self.build_regex(self.rest(1))
        self.fm.thisdir.load_content(schedule=False)
        if self.rest(1) == "/":
           return True

And now I can escape with </> key from :narrow command, but :travel command not escapes and tries to filter filenames having "/".
May it be caused that your recommendations are based on your version of :narrow and :travel commands, while I'm using @hut's version from ranger-git?
Anyway, thank you for help smile

*Duh*, I forgot the whole point of this wink.

You'll need to change :travel's :quick to:

    def quick(self):
        if narrow.quick(self):
            return True

        arg = self.rest(1)

        if arg == ".":
            return False # Make sure we can always use ".."
        elif arg and len(self.fm.thisdir.files) == 1 or arg == "..":
            return True
Sirsurthur wrote:

Hello Hut,
Since the latest pull in git, it looks like the preview with w3m is not working for me anymore (great new feature by the way !).
When I select a picture, I get the following output : 'str' does not support the buffer interface ?
Best regards,

+1

Traceback:

ranger version: 1.5.5, executed with python 3.3.0
Locale: en_GB.UTF-8
Current file: /home/joshua/t.png
Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/ranger/core/main.py", line 133, in main
    fm.loop()
  File "/usr/lib/python3.3/site-packages/ranger/core/fm.py", line 266, in loop
    loader.work()
  File "/usr/lib/python3.3/site-packages/ranger/core/loader.py", line 363, in work
    self.fm.notify(err)
  File "/usr/lib/python3.3/site-packages/ranger/core/loader.py", line 357, in work
    next(item.load_generator)
  File "/usr/lib/python3.3/site-packages/ranger/core/loader.py", line 145, in generate
    process.stdin.write(self.input)
TypeError: 'str' does not support the buffer interface

ranger crashed.  Please report this traceback at:
http://savannah.nongnu.org/bugs/?group=ranger&func=additem

I'll post it to the bug tracker later.

Last edited by Veedrac (2013-02-17 14:37:53)

Offline

#1622 2013-02-17 15:12:21

loop
Member
Registered: 2011-05-06
Posts: 58

Re: Ranger, a textbased filemanager

Veedrac wrote:

*Duh*, I forgot the whole point of this wink.

You'll need to change :travel's :quick to:

Cheers, @Vee, it works. wink

Sirsurthur wrote:

Hello Hut,
Since the latest pull in git, it looks like the preview with w3m is not working for me anymore (great new feature by the way !).
When I select a picture, I get the following output : 'str' does not support the buffer interface ?
Best regards,

Works fine with python 2.7.3, btw. tongue

Offline

#1623 2013-02-17 15:47:46

Sirsurthur
Member
Registered: 2009-02-02
Posts: 124

Re: Ranger, a textbased filemanager

Not with python 3.3.0 smile :

[julien@arch ~]$ ranger --debug
ranger version: 1.5.5, executed with python 3.3.0
Locale: fr_FR.UTF-8
Current file: /home/julien/2011-06-08-210533_1920x1080_scrot.png
Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/ranger/core/main.py", line 133, in main
    fm.loop()
  File "/usr/lib/python3.3/site-packages/ranger/core/fm.py", line 266, in loop
    loader.work()
  File "/usr/lib/python3.3/site-packages/ranger/core/loader.py", line 363, in work
    self.fm.notify(err)
  File "/usr/lib/python3.3/site-packages/ranger/core/loader.py", line 357, in work
    next(item.load_generator)
  File "/usr/lib/python3.3/site-packages/ranger/core/loader.py", line 145, in generate
    process.stdin.write(self.input)
TypeError: 'str' does not support the buffer interface

ranger crashed.  Please report this traceback at:
http://savannah.nongnu.org/bugs/?group= … nc=additem

Offline

#1624 2013-02-17 19:05:51

Veedrac
Member
Registered: 2011-07-19
Posts: 81

Re: Ranger, a textbased filemanager

Sirsurthur wrote:

Hello Hut,
Since the latest pull in git, it looks like the preview with w3m is not working for me anymore (great new feature by the way !).
When I select a picture, I get the following output : 'str' does not support the buffer interface ?
Best regards,

A quick fix is just changing line 145 of ranger/core/loader.py to

process.stdin.write(self.input.encode("UTF8"))

Please check that it works in Python 2.7, though.

Last edited by Veedrac (2013-02-17 19:06:29)

Offline

#1625 2013-02-17 19:09:03

hut
Member
From: Hanover, Germany
Registered: 2010-03-12
Posts: 569
Website

Re: Ranger, a textbased filemanager

loop wrote:
hut wrote:

It works for me, am I missing something? Does it work when you simply run "~/.config/ranger/rifle_sxiv.sh /path/to/some/image.jpg"?

Checked it. There wasn't 'realpath' utility installed in my case.

My bad. I'll remove the "realpath" dependency.

Army wrote:
hut wrote:

That's a great way to slow down ranger^UThat's a great idea, this way you could display previews of PDFs in color, html documents, videos, sound files by analyzing the spectrum, and so on smile I'll keep it in mind.

I disabled previews because it made ranger slow. Now I only get a preview hitting F3. This way, there's no problem with those commands.

Images load in the background now BTW

Sirsurthur wrote:

When I select a picture, I get the following output : 'str' does not support the buffer interface ?

Yeah, I overlooked a difference in the standard libs of python2 and python3. It's fixed now.


"hut_" or "h00th00t" in irc.freenode.net #archlinux
Ranger Mailing List: https://lists.nongnu.org/mailman/listinfo/ranger-users

Offline

Board footer

Powered by FluxBB