whame / tmux-modal

Execute complex tmux commands in just a few keystrokes with a modal mode that is designed to be efficient, easy to remember and comfortable
MIT License
172 stars 4 forks source link

change color of statusline when tmux--modal is activated. #6

Closed morphykuffour closed 2 years ago

morphykuffour commented 2 years ago

I want a visual cue to let me know when I am in modal mode similar to the vim airline functionality where statusline changes colors depending on the different modes. This plugin is awesome but the MODAL_ICON="[=]" does not help to tell since I have to refocus my attention to the statusline.

I think grepping for the = symbol in the statusline and then changing the color of the statusline for the modal functionality would work but I don't know how to go about that for this solution.

There are also tmux hooks which actually I think would be the best implementation since the exposed functionality from tmux-modal can be used for different color highlights. The grep solution I will have more overhead since this requires an external tool.

I current have this to change the status line to blue when I press C-a [ for scrolling and searching through text in the terminal. M-a [ however does change the statusline.

# change search mode to blue
set-hook -g pane-mode-changed 'if -F "#{m/r:(copy|view)-mode,#{pane_mode}}" "set status-style bg=#0125ff" "set -u status-style"'
# change command mode to red TODO fix
set-hook -g pane-mode-changed 'if -F "#{=tmux-modal}" "set status-style bg=green" "set -u status-style"'

Any help would be appreciated in achieving this functionality.

Thank you

whame commented 2 years ago

I'm not aware for any tmux hooks that triggers on key table changes (do you know maybe?). If I understand you correctly, you want to act upon key table changes (which is what tmux-modal changes).

I think the easiest here is just to hack the script. For example:

diff --git a/tmux-modal.tmux b/tmux-modal.tmux
index 5ea9326..b223d2f 100755
--- a/tmux-modal.tmux
+++ b/tmux-modal.tmux
@@ -583,7 +583,7 @@ STATUS_LEFT=`
       `'?#{==:'$KT_PREFIX'-,'`
          `'#{='$((${#KT_PREFIX} + 1))':client_key_table}'`
         `'},'`
-       `$MODAL_ICON' ,'`
+       `'#[bg=green]'$MODAL_ICON' ,'`
      `'}'

 # We want to set the left status bar once; do it only if we can't find our

This format check is actually what you would want in a hook as well, i.e. check if client_key_table starts with ktm-, because all tmux-modal key tables starts with ktm-. Does this work for you?. You can of course change the color of different parts of the status bar. tmux-modal only changes status-left.

morphykuffour commented 2 years ago

Yes this worked for me. Prefixing $MODAL_ICON with [bg=color] works.

morphykuffour commented 2 years ago

I also tried changing the modal icon to CMD but that caused showed some weird characters in the statusline

whame commented 2 years ago

Glad it worked out! Do you mean like this:

diff --git a/tmux-modal.tmux b/tmux-modal.tmux
index 5ea9326..b88ed1f 100755
--- a/tmux-modal.tmux
+++ b/tmux-modal.tmux
@@ -577,13 +577,13 @@ tmux source-file "$KBD_FILE"

 # Prepend left status bar with MODAL_ICON if our key tables are in use.
 # Determine this by checking if current key table starts with our prefix.
-MODAL_ICON="[=]"
+MODAL_ICON="CMD"
 STATUS_LEFT=`
     `'#{'`
       `'?#{==:'$KT_PREFIX'-,'`
          `'#{='$((${#KT_PREFIX} + 1))':client_key_table}'`
         `'},'`
-       `$MODAL_ICON' ,'`
+       `'#[bg=green]'$MODAL_ICON' ,'`
      `'}'

 # We want to set the left status bar once; do it only if we can't find our

Because that worked for me. Otherwise please paste your patch/diff. Maybe you just need to restart tmux?