Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mutt + w3mimgdisplay + urxvt
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Thu Mar 30, 2017 12:39 am    Post subject: mutt + w3mimgdisplay + urxvt Reply with quote

I am trying to render inline images on a terminal. I apologize if the post is long, I prefer to be thorough.
Code:

$ emerge -pv rxvt-unicode
[ebuild   R    ] x11-terms/rxvt-unicode-9.21::gentoo  USE="256-color focused-urgency font-styles mousewheel perl pixbuf vanilla xft -alt-font-width -blink -buffer-on-clear -fading-colors -iso14755 -secondary-wheel -startup-notification -unicode3 -wcwidth" 904 KiB

while reading an e-mail that contains those images in mutt
Code:

$ emerge -pv mutt
[ebuild   R    ] mail-client/mutt-1.5.24-r2::gentoo  USE="berkdb crypt gdbm gpg imap nls sasl sidebar smime smtp ssl -debug -doc (-gnutls) -idn -kerberos (-libressl) -mbox -nntp -pop -qdbm (-selinux) -slang -tokyocabinet" 3,922 KiB


I am following the approach detailed in many places like this one that consists on having a script passing the image to /usr/libexec/w3m/w3mimgdisplay, adding this script to mailcap and adding image/* to autoview.

I have an installation of w3m that can indeed render images on urxvt
Code:

$ emerge -pv w3m
[ebuild   R    ] www-client/w3m-0.5.3-r9::gentoo  USE="X gpm gtk imlib nls ssl unicode -fbcon (-libressl) -lynxkeymap -nntp -xface" L10N="-ja" 0 KiB

and both, if I run interactively something like "w3m xkcd.com" or non-interactively something like the script that mutt would call:
Code:
echo -e "2;3;\n0;1;210;20;$((80*7-250));$((24*14-100));0;0;0;0;/path/to/file.jpg\n4;\n3;" |  /usr/libexec/w3m/w3mimgdisplay &

the image is rendered in the terminal.

However when I try this within the viewer in mutt the image appears for just a split second and then it dissapears. I know that the image is being rendered cause if I simply add a sleep 20 to the script that calls w3mimgdisplay then the image stays for 20 seconds before the e-mail is displayed and overwrites the image. Hence mutt is redrawing the screen with the e-mail.

So my question is: is there a way to solve this? how did the guys in all those sites like the one posted above solved this issue?
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Thu Mar 30, 2017 10:43 am    Post subject: Reply with quote

potuz ...

well, 'echo -e' is a bashism so if /bin/sh happens not to be bash you'll get a literal '-e' along with your echo. If that is the case change the shebang to /bin/bash (in fact you should do that anyway, as it uses a non sh feature).

You didn't show your mailcap, you are closing with '%s ; copiousoutput'?

best ... khay
Back to top
View user's profile Send private message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Thu Mar 30, 2017 12:09 pm    Post subject: Reply with quote

Thanks! indeed I missed the -e, but anyway my shell is bash so no change after moving to !/bin/bash.
Here's my mailcap:
Code:

application/pdf;   mutt_bgrun zathura %s;
application/PDF;   pdftotext %s -; copiousoutput
image/jpeg;      feh -Z %s;
image/png;      feh -Z %s;
image/*; /home/user/.mutt/callw3m.sh %s; copiousoutput;
text/html;   w3m -I %{charset} -T text/html; copiousoutput;
application/msword;   mutt_bgrun abiword %s;
application/vnd.openxmlformats-officedocument.wordprocessingml.document; mutt_bgrun abiword %s;
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Thu Mar 30, 2017 8:45 pm    Post subject: Reply with quote

potuz ...

I'm not seeing any problem there, I wonder if this isn't a urxvt issue, do you have 'URxvt.depth: 32' in ~/.Xresources? If so can you comment, run xrdb (or restart your xsession), open a term/mutt and test?

best ... khay
Back to top
View user's profile Send private message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Thu Mar 30, 2017 8:56 pm    Post subject: Reply with quote

khayyam wrote:
potuz ...

I'm not seeing any problem there, I wonder if this isn't a urxvt issue, do you have 'URxvt.depth: 32' in ~/.Xresources? If so can you comment, run xrdb (or restart your xsession), open a term/mutt and test?

best ... khay
Yep, forgot to say that I have tried that already and didn't work either. But notice the part that the image is in fact being rendered, if I add a sleep then it does stay for a while. So it's mutt that is rendering the e-mail after it renders the image, hence this is an issue with the order in which mutt renders e-mails and not the terminal. I just can't see how those other guys got this working.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Fri Mar 31, 2017 7:09 am    Post subject: Reply with quote

potuz wrote:
Yep, forgot to say that I have tried that already and didn't work either. But notice the part that the image is in fact being rendered, if I add a sleep then it does stay for a while. So it's mutt that is rendering the e-mail after it renders the image, hence this is an issue with the order in which mutt renders e-mails and not the terminal. I just can't see how those other guys got this working.

potuz ... ok, it was worth a shot. If when you add a sleep the image remains, then perhaps the issue is backgrounding the w3mimgdisplay ... have you tried removing the ampersand?

best ... khay
Back to top
View user's profile Send private message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Fri Mar 31, 2017 12:23 pm    Post subject: Reply with quote

khayyam wrote:
potuz wrote:
Yep, forgot to say that I have tried that already and didn't work either. But notice the part that the image is in fact being rendered, if I add a sleep then it does stay for a while. So it's mutt that is rendering the e-mail after it renders the image, hence this is an issue with the order in which mutt renders e-mails and not the terminal. I just can't see how those other guys got this working.

potuz ... ok, it was worth a shot. If when you add a sleep the image remains, then perhaps the issue is backgrounding the w3mimgdisplay ... have you tried removing the ampersand?

best ... khay

Thanks, that I hadn't tried, still no change. What I had tried is to run it through mutt_bgrun which is a script to backgorund processes when you open them in the attachment menu. Didn't work either.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Fri Mar 31, 2017 11:12 pm    Post subject: Reply with quote

potuz wrote:
Thanks, that I hadn't tried, still no change. What I had tried is to run it through mutt_bgrun which is a script to backgorund processes when you open them in the attachment menu. Didn't work either.

potuz ... can you provide the full script ('cat -vET script.sh'), and your muttrc (anonymised).

best ... khay
Back to top
View user's profile Send private message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Sat Apr 01, 2017 3:22 am    Post subject: Reply with quote

Sure,
Code:

$ cat -vET .mutt/callw3m.sh
#!/bin/bash$
$
#### Determine size of Terminal$
height=`stty  size | awk 'BEGIN {FS = " "} {print $1;}'`$
width=`stty  size | awk 'BEGIN {FS = " "} {print $2;}'`$
$
### Display Image / offset with mutt bar$
echo -e "2;3;\n0;1;210;20;$((width*7-250));$((height*14-100));0;0;0;0;$1\n4;\n3;" |  /usr/libexec/w3m/w3mimgdisplay &$
$


Code:

$ cat -vET .mutt/muttrc
# Paths ----------------------------------------------$
set folder           = ~/.mail               # mailbox location$
set alias_file       = ~/.mutt/alias         # where to store aliases$
set header_cache     = ~/.mutt/cache/headers # where to store headers$
set message_cachedir = ~/.mutt/cache/bodies  # where to store bodies$
set certificate_file = ~/.mutt/certificates  # where to store certs$
set mailcap_path     = ~/.mutt/mailcap       # entries for filetypes$
set tmpdir           = ~/.mutt/temp          # where to keep temp files$
#set signature        = ~/.mutt/sig           # my signature file$
$
# Basic Options --------------------------------------$
folder-hook . "push <collapse-all>\n"$
set wait_key = no        # shut up, mutt$
set mbox_type = Maildir  # mailbox type$
set timeout = 3          # idle time before scanning$
set mail_check = 0       # minimum time between scans$
unset move               # gmail does that$
set delete               # don't ask, just do$
unset confirmappend      # don't ask, just do!$
set quit                 # don't ask, just do!!$
unset mark_old           # read/new is good enough for me$
set beep_new             # bell on new mails$
set pipe_decode          # strip headers and eval mimes when piping$
set thorough_search      # strip headers and eval mimes before searching$
$
# PGP Encryption$
set crypt_use_gpgme = yes$
set crypt_autosign = yes$
set pgp_mime_signature_filename = "signature.asc"$
set pgp_use_gpg_agent^I= yes$
set pgp_timeout = 28800$
$
$
# Status Bar -----------------------------------------$
set status_chars  = " *%A"$
set status_format = "M-bM-^TM-^@M-bM-^TM-^@M-bM-^TM-^@[ Folder: %f ]M-bM-^TM-^@M-bM-^TM-^@M-bM-^TM-^@[%r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? ]M-bM-^TM-^@M-bM-^TM-^@M-bM-^TM-^@%>M-bM-^TM-^@%?p?( %p postponed )?M-bM-^TM-^@M-bM-^TM-^@M-bM-^TM-^@"$
$
# Header Options -------------------------------------$
ignore *                                # ignore all headers$
unignore from: to: cc: date: subject:   # show only these$
unhdr_order *                           # some distros order things by default$
hdr_order from: to: cc: date: subject:  # and in this order$
$
# Receiving Settings -----------------------------------$
$
source ~/.mutt/muttrc.mailboxes$
folder-hook acct1 source ~/.mutt/acct1-setup$
folder-hook potuz source ~/.mutt/potuz-setup$
folder-hook gmail source ~/.mutt/gmail-setup$
set mbox_type=Maildir$
set spoolfile= "+gmail/INBOX"$
$
set editor^I^I= 'vim -c "set spell spelllang=en"'$
$
# Sending Settings ------------------------------------------$
set sendmail_wait^I= 0 # wait for sendmail to finish. $
unset record ^I^I# don't leave local copy of e-mail$
$
# Index View Options ---------------------------------$
color index yellow default *    # white normal.$
color index white default "~Q" # replied already$
color index green default "~v"   # messages in a collapsed thread$
color index red default "~U"   # unread messages$
color index brightred default "~F"  #flagged$
set date_format = "%b %d"$
set index_format = "[%Z]  %D %?M?>& ? %-20.20F  %s"$
set sort = threads                         # like gmail$
set sort_aux = reverse-last-date-received  # like gmail$
set uncollapse_jump                        # don't collapse on an unread message$
unset collapse_unread$
set strict_threads^I^I^I   # don't use only subject$
set sort_re                                # thread based on regex$
set reply_regexp = "^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\[[^]]+\] *)?)*"$
$
# Index Key Bindings ------------------------------$
bind^Iindex^IA^Igroup-reply^I$
bind^Iindex^IP^Isearch-opposite$
bind^Iindex^Il^Icollapse-thread$
bind^Iindex^I<Left>^Icollapse-thread$
bind^Iindex^I<space>^Idisplay-message$
bind ^Iindex ^II^Ilimit$
macro^Iindex^IM^I"<save-message>?<toggle-mailboxes>"^I"Move message to folder"$
macro^Iindex^Ia^I"<limit>all\n" "show all messages (undo limit)"$
$
#Attachment Keybindings$
macro attach O \$
"\$
<enter-command>unset wait_key<enter>\$
<shell-escape>rm -f /tmp/mutt-attach<enter>\$
<save-entry><kill-line>/tmp/mutt-attach<enter>\$
<shell-escape> /tmp/mutt-attach &^A\$
"$
$
#Pager View Options ---------------------------------$
#set pager_index_lines = 10 # number of index lines to show$
set pager_context = 3      # number of context lines to show$
set pager_stop             # don't go to next message automatically$
set menu_scroll            # scroll in menus$
set tilde                  # show tildes like in vim$
unset markers              # no ugly plus signs$
$
set quote_regexp = "^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"$
alternative_order text/html text/plain text/enriched$
auto_view^I  image/* text/html$
# Pager Key Bindings ------------------------------$
bind^Ipager ^I<up>^Iprevious-line$
bind^Ipager ^Ik^Iprevious-line$
bind^Ipager^IP^Isearch-opposite$
bind^Ipager^I<down>^Inext-line$
bind^Ipager^Ij^Inext-line$
bind^Ipager^IA^Igroup-reply$
bind ^Ipager^I<left>^Iprevious-undeleted$
bind^Ipager^I<right>^Inext-undeleted$
$
# Sidebar Navigation ---------------------------------$
#bind index,pager <down>   sidebar-next$
#bind index,pager <up>     sidebar-prev$
#bind index,pager <right>  sidebar-open$
$
# Contacts ----------------------------------------$
#$
set query_command="goobook query '%s'"$
bind editor <Tab> complete-query$
macro index,pager + "<pipe-message>goobook add<return>" "add the sender address to Google contacts"$
$
# Typing ----------------------------$
#$
set text_flowed=yes$
$
#mailing lists$
subscribe my-favourite-lists@googlegroups.com$
# Searching ---------------------------------------$
macro index S "<enter-command>unset wait_key<enter><shell-escape>mutt-notmuch-py ~/.mail/temporary/search<enter><change-folder-readonly>+temporary/search<enter>" "search mail (using notmuch)"$

The account setup scripts alluded above are
Code:

$ cat .mutt/potuz-setup
set from = "potuz@mydomain.net"
set realname = "Potuz"
set smtp_url = "smtp://potuz@myhost.mydomain.net:587/
source "gpg -d /path/to/my/key/smtp-potuz.gpg |"
set pgp_sign_as = MYKEYHASH
set record="/home/myuser/.mail/potuz/Sent"

And finally the sourced gpg holds the encrypted passwd:
Code:

$gpg -d /path/to/my/key/smtp-potuz.gpg
set smtp_pass = mypasswd
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Sat Apr 01, 2017 7:36 am    Post subject: Reply with quote

potuz wrote:
Code:
### Display Image / offset with mutt bar

potuz ... do you in fact have the sidebar? Is mail-client/mutt[sidebar] enabled? I'm not seeing anything else that suggests what might be going on here.

Here is a corrected script, if you're using bash you might as well use bash arrays (and save yourself having to call stty and awk twice).

Code:
#!/bin/bash
set -e

#### Determine size of Terminal
xy=($(stty size))

### Display Image / offset with mutt bar
echo -e "2;3;\n0;1;210;20;$((${xy[1]}*7-250));$((${xy[0]}*14-100));0;0;0;0;$1\n4;\n3;" | \
    /usr/libexec/w3m/w3mimgdisplay &

best ... khay
Back to top
View user's profile Send private message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Sat Apr 01, 2017 12:17 pm    Post subject: Reply with quote

No, in fact I don't use the sidebar, but I didn't mind the offset and I was going to change it only if the placement was off. Thanks for the script I didn't even know bash matrices existed! Still no change though :(
Back to top
View user's profile Send private message
potuz
Guru
Guru


Joined: 30 Jan 2010
Posts: 378

PostPosted: Sat Apr 01, 2017 12:56 pm    Post subject: Reply with quote

And by the way thanks for taking the time to look into this, I know it's silly but it's comforting to know that I'm not the only one puzzled by this.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6228
Location: Room 101

PostPosted: Sat Apr 01, 2017 2:06 pm    Post subject: Reply with quote

potuz wrote:
No, in fact I don't use the sidebar, but I didn't mind the offset and I was going to change it only if the placement was off. Thanks for the script I didn't even know bash matrices existed! Still no change though :(

potuz ... I guess what I was thinking was that when you have the sidebar mutt behaves differently wrt what it's treating as the input (ie, sidebar, pager, etc), and that this might explain why others using that same script don't exhibit the same issue (it would be the most logical explanation of what's going on). That not being the case, then I would disable everything in your config not required for accessing your mailbox and mailcap, and try to reproduce it under those conditions.

best & you're welcome ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum