pazz / alot

Terminal-based Mail User Agent
GNU General Public License v3.0
696 stars 164 forks source link

Edit mail in a different terminal tabs than the main alot windows #1560

Closed psic closed 3 years ago

psic commented 3 years ago

Describe the bug I don't know if it is really a bug, a misconfiguration by myself or ... a feature request. I'd like to write my email (create or respond) in a different (new one for each mail) terminal tab than the main tab of alot. It's pretty easy to setup for opening or creating a mail in a new tab with the header, and edit the mail with vim or nano. I try with tmux, screen , kitty and other terminal. Each time, whatever the terminal I used, when I close the editor (and the mail is really in the temp file) and normally come back to main windows, the previously edited mail is empty/not showed.

Subsidiary question, is there any way to ask for configuration tips ? any mailing list ? reddit sub or else ?

Software Versions

lucc commented 3 years ago

Can you post your config (especially terminal_cmd, editor_in_thread, editor_spawn, editor_cmd/$EDITOR) so that we can better understand your question.

I would assume that you need to set terminal_cmd to something like myTerminal --open-new-tab --forground --execute. The foreground part is important. If the terminal command that alot executes returns right after it was executed and the terminal window/tab runs in a background process then alot thinks you are done editing already (but you did not even start yet).

Did you have success with new terminal windows (instead of tabs)? In this case you might be able to see the main alot terminal and your editor terminal side by side and spot some hints on what is going on in which order.

lucc commented 3 years ago

There is the #alot IRC channel on freenode.net, I do not know of any other forums or mailing lists.

psic commented 3 years ago

Your assumption is right, but I was aware about the foreground part. editor_in_thread and editor_spawn are always set to True. editor_in_thread=True editor_spawn=True editor_cmd="nano -Y alot -m +4" To start nano with an alot custom style, with the cursor on the fourth line, just under the header. terminal_cmd="screen -S alot -X screen " for screen using st as terminal terminal_cmd="kitty @ launch --type=tab" for the kitty terminal terminal_cmd="tmux new-window " for tmux using st as terminal No problem to work with terminal in new window.

lucc commented 3 years ago

I tested your terminal_cmd (the tmux and kitty version) and both return immediately (after <1sec). (NB: the shell command that starts the new tab/window returns but the tab/window lives on; but alot only knows about the shell command that started the tab/window) That means alot sees the command as finished and then reads back the tmp file.

You need to find a version of your commands that only return when the tab/window they opened is closed (or wrap them in some shell script to do that manually).

psic commented 3 years ago

Thanks for the test. How do you test it ? How do you know the shell command returns immediatly. I've never noticed this behaviour.

lucc commented 3 years ago

I open a kitty or tmux and then type the respective command. You will be put in the new tab/window but if you navigate back you can see that the shell command you executed did already finish and you have a command prompt in your original window. You can even execute more commands there with the new tab still alive. If you close the new tab (exit) you will see no indication of this in the original tab.

You can also try to execute time tmux new-window sleep 10 in tmux or time kitty @ launch --type=tab sleep 10. Your new tab will be open for 10 seconds but time will report that the command to open the tab returned after <1sec.

To come back to what I said in https://github.com/pazz/alot/issues/1560#issuecomment-757128228: You have to find some kind of --foreground option to make the tmux/kitty command wait for the tab. Only when the tab is closed should the original command that started it return.

lucc commented 3 years ago

You might have to write some small wrapper shell script like this: https://stackoverflow.com/questions/60365501/run-command-in-new-background-tmux-window-and-wait-for-process-to-finish

psic commented 3 years ago

Thnaks alot ! I understand something today. Sorry to open an issue for that.

cjpbirkbeck commented 3 years ago

For future reference, for anybody looking at this thread in the future, here's an implementation of such a wrapper script for composing an email in a tmux pane. Works for me, but I would welcome any corrections or improvements. As a bonus, it also opens a terminal if alot isn't running inside of tmux.

IFS=' '

if [ -n "$TMUX" ]; then
    # Use new-window to create a new window instead.
    tmux split-window "${*}; tmux wait-for -S finished"
    tmux wait-for "finished"
else
    # You can replace xterm with your preferred terminal emulator.
    xterm -e "${*}"
fi

alot configuration:

# Default editor command works too, as does any other editor command,
# just remember to properly quote your editor command.
editor_cmd = "nvim -c \"normal! }j\""
terminal_cmd = ~/path/to/script.sh
editor_in_thread = True
editor_spawn = True