hackerb9 / lsix

Like "ls", but for images. Shows thumbnails in terminal using sixel graphics.
GNU General Public License v3.0
3.99k stars 129 forks source link

Get this to work on MacOS #4

Closed sdushantha closed 4 years ago

sdushantha commented 6 years ago

When i run this i get an error saying that the commands mapfile , montage , convert .

hope it is possible to fix this

hackerb9 commented 6 years ago

You need to have ImageMagick installed for montage and convert. I don't have MacOS at the moment, but I believe "brew" is the standard way to do that. Here's a random site I found on the web which claims it is easy to do: http://lookalive.co.uk/blog/installing-imagemagick-mac-os-easily

The mapfile error is odd. Several other MacOS users had said lsix worked for them. Mapfile is a built-in command in bash. Apple is years behind on the version that they ship with MacOS. Does typing help mapfile at the command line give you an error? What about help readarray?

By the way, I'm not sure if the default terminal Apple ships can handle sixel graphics, so you may need to install another one.

hackerb9 commented 6 years ago

@sdushantha I'd like to help you with your problem, but I cannot without more information. Are you able to answer the questions I asked? It will help out not just you, but everyone who uses MacOS if we can make sure that it works easily. Thanks.

sdushantha commented 6 years ago

@hackerb9 Sorry for the late reply.

My Mac is a school laptop so I am not able to install brew. Therefor, I cant install ImageMagick

hackerb9 commented 6 years ago

I see. That makes it harder but not impossible. ImageMagick can be installed and run in your home directory, same as lsix. I found a MacOS binary that might work for you here: https://legacy.imagemagick.org/script/binary-releases.php#macosx

Alternately, get a bootable USB drive (or DVD) and run Debian Live or Ubuntu. (IIRC, you can hold down Option (Alt) while your laptop turns on). I found a random webpage that may help live booting.

Live booting GNU/Linux would give you ImageMagick and also ensure you have a compatible sixel terminal pre-installed (xterm -ti vt340). And you won't have any problems from Apple's old version of bash.

P.S. My opinion is that locks are there to learn from. School locks can be especially educational.

hackerb9 commented 6 years ago

@sdushantha: Any progress?

sdushantha commented 6 years ago

Haven't had time to download an ISO of debain. Will try to do it. I've got a lot work so I'll do it when i have time

seclorum commented 5 years ago

Out of the box, doesn't work for me on MacOS - I have home-brew installed, Imagemagick, etc. I tried using it on a known good image, and get the message:

$ ./lsix moaigalaxy.jpg
Fontconfig warning: ignoring UTF-8: not a valid region tag

iTerm2 3.2.6 - maybe this doesn't support sixel graphics? Tried it with xterm too, same exact result .. not sure I have the chops to debug this further, but maybe you have some clues?

EDIT: just to add - xterm was started per the README:

$ xterm -ti vt340
mtyurt commented 5 years ago

I can't get it working in macOS as well. I have imagemagick and bash 4.4 installed. The error I get is:

mapfile: command not found

I have mapfile and readarray installed, commands are working, but they don't exist in root path. I don't know if it's related here.

$ mapfile -h
-bash: mapfile: -h: invalid option
mapfile: usage: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
$ sudo mapfile -h
sudo: mapfile: command not found

When I run sudo su, it opens the shell with sh, which is at version 3.2.

nic611 commented 5 years ago

image

/usr/local/bin/lsix: line 128: readarray: command not found sed: RE error: illegal byte sequence

the same problem I met...

hackerb9 commented 5 years ago

Out of the box, doesn't work for me on MacOS - I have home-brew installed, Imagemagick, etc. I tried using it on a known good image, and get the message: Fontconfig warning: ignoring UTF-8: not a valid region tag

Seclorum, I think your error may be different than the original poster as you are getting different error messages. I know nothing about iterm, but I do know that MacOS comes with ancient versions of all the standard UNIX tools. Xterm added Sixel support in 2013, somewhere around version 300. (The current version is 341).

Can you please run xterm -v to find out what Apple is shipping these days? Also, let me know which version of MacOS you're using. Thanks.

maddie commented 5 years ago

If installing bash from Homebrew via brew install bash, then change the shebang in lsix to #!/usr/bin/env bash, it will use the newer version from Homebrew, which has mapfile builtin.

mapfile was introduced in Bash 4, but the included bash from Apple (I'm on Mojave) is 3.2.57.

But even though the errors are eliminated (mapfile, ImageMagick), lsix will just run for a while (for about 10 seconds) then output nothing, like this.

EDIT: xterm -v returns XTerm(326).

hackerb9 commented 5 years ago

mapfile was introduced in Bash 4, but the included bash from Apple (I'm on Mojave) is 3.2.57.

Thanks, I forgot about that. I've pushed an update to lsix that uses readarray instead of mapfile. Please let me know if that works with Apple's default version of Bash.

But even though the errors are eliminated (mapfile, ImageMagick), lsix will just run for a while (for about 10 seconds) then output nothing, like this.

EDIT: xterm -v returns XTerm(326).

That's odd. That sounds exactly like what happens on a terminal that doesn't handle Sixel. You ran xterm using xterm -ti vt340, right?

maddie commented 5 years ago

Thanks, I forgot about that. I've pushed an update to lsix that uses readarray instead of mapfile. Please let me know if that works with Apple's default version of Bash.

Still doesn't work:

lsix: line 121: readarray: command not found
sed: RE error: illegal byte sequence

And BTW, sed on macOS is not the same as the Linux one, I changed to use gsed from gnu-sed package in Homebrew.

That's odd. That sounds exactly like what happens on a terminal that doesn't handle Sixel. You ran xterm using xterm -ti vt340, right?

I was running the command in iTerm, but with xterm -ti vt340 (which opens a new xterm terminal for me) it behaves the same.

SecondDog commented 5 years ago

/usr/local/bin/lsix: line 121: readarray: command not found

hackerb9 commented 5 years ago

Yuck. Perhaps the Apple version of bash doesn't even have arrays.

Thanks for letting me know about the sed problem, though I don't recall using anything particularly fancy for that. So, when brew installs GNU sed, it calls it gsed? I think I can work around that pretty easily if that's the case.

maddie commented 5 years ago

Yuck. Perhaps the Apple version of bash doesn't even have arrays.

That's what I thought too.

Thanks for letting me know about the sed problem, though I don't recall using anything particularly fancy for that. So, when brew installs GNU sed, it calls it gsed? I think I can work around that pretty easily if that's the case.

Yeah, it's called gsed so it won't interfere with the included sed, since some system tools might depend on it. Not sure using gsed is the way to go, since that would introduce yet another dependency for macOS users, but we have to install other things like ImageMagick anyways, might just also install bash from Homebrew as well so the mapfile/readarray problem can be solved too.

The sed error given seems to be because of the different regular expression format used by GNU sed and Apple sed, there's probably an easy fix for this to make it compatible between these two, but I'm not too sure about that.

hackerb9 commented 5 years ago

I've uploaded a patch that should check for gsed in the path and use that if it exists. Please let me know if that solves the sed problem.

As for the Bash version problem, would it be acceptable to have a fork specifically for MacOS whose only change is using #!/usr/local/bin/bash (or wherever it is brew installs bash)? I have a minor bias against using /usr/bin/env to run the shell.

hackerb9 commented 5 years ago

I've just checked in a patch that should give a warning on MacOS if bash4 isn't installed and should work fine if it is. Could someone please check for me that both of these cases are true?

vv111y commented 5 years ago

can confirm it does not work in iterm2. There is a feature request, last post 6 months ago:

Investigate SIXEL support

and iterm2 docs on images

documentation-images

dmose commented 5 years ago

I wonder if it would work on https://www.macterm.net/, which says it has SIXEL support.

hackerb9 commented 5 years ago

I wonder if it would work on https://www.macterm.net/, which says it has SIXEL support.

So, anyone with a Macintosh tried macterm, yet? Also, has anyone tried the latest version using Apple's xterm -ti vt340?

I think both should work now, but if they don't, I want to know.

maddie commented 5 years ago

With xterm -ti vt340 and macterm, and master branch of lsix, both gives:

Error: Your terminal does not appear to support sixel graphics.

Please use a sixel capable terminal, such as xterm -ti vt340, or
ask your terminal manufacturer to add sixel support.

If your terminal actually does support sixel, please file a bug
report at http://github.com/hackerb9/lsix/issues
hackerb9 commented 5 years ago

I'm guessing Apple is not properly enabling SIXEL support when they compile XTerm. If you have a three button mouse, could you please check something for me? When you hold down the CTRL key and press and hold the middle mouse button in the XTerm window, does the menu that appears mention anything about SIXEL scrolling? It should, near the bottom of the list.

I've left a bug report for the MacTerm team as their project clearly states they support SIXEL but the terminal must not be reporting it correctly. In the meantime, would you please let me know if the following works to view an image:

convert foo.jpg -geometry 800x480 sixel:-

Thanks.

maddie commented 5 years ago

Ctrl+Middle Click in xterm doesn't have anything related to SIXEL in the popup menu. And the convert command ran in macterm outputs gibberish instead of an image.

hackerb9 commented 5 years ago

Thanks again, Maddie. So, it appears Apple's XTerm doesn't have SIXEL support compiled in, at least with Mojave. That's a bummer and I think it'll only change if Apple's users let the company know that they'd like that option enabled. (It'd be trivial for Apple to do.) As a workaround, is there a brew version of XTerm?

I don't know what to say about MacTerm outputting gibberish. That should not happen unless the SIXEL interpreter in MacTerm is broken. (Even if it didn't support SIXEL, it should just silently discard the data, not splat it on the screen.)

Googling around, I found a reference on ycombinator that it works for the author of MacTerm but that may be because he's using version 7 of ImageMagick instead of 6. Could you please try convert --version?

maddie commented 5 years ago

Sorry for the late response. convert --version gives below output:

Version: ImageMagick 7.0.8-24 Q16 x86_64 2019-01-18 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib freetype jng jp2 jpeg lcms ltdl lzma png tiff webp xml zlib

And I believe the ImageMagick I'm using is provided by Homebrew.

Mouvedia commented 5 years ago

Mapfile is a built-in command in bash.

I am currently using Bash version 5 and I am still getting line 121: mapfile: command not found.

dmose commented 5 years ago

As per a recent comment in the iTerm2 bug, lsix works in iTerm2 3.3.0beta7.

Mouvedia commented 5 years ago

I am using Build 3.3.20190508-nightly with bash 5 and it's partially working.

hackerb9 commented 4 years ago

Closing as I believe lsix should work by default on MacOS now and, if it is missing anything, it should give an appropriate message. Please let me know if that is not the case.