walles / moar

Moar is a pager. It's designed to just do the right thing without any configuration.
Other
600 stars 17 forks source link

Pick default theme based on terminal background color #67

Closed walles closed 5 months ago

walles commented 2 years ago

According to https://stackoverflow.com/a/7767891/473672 some terminals support querying the actual background color of the terminal window.

Unclear what happens with background images / transparency, but still.

Example usage, text after the second $ is the response from the terminal.

~ $ printf "\e]11;?\a"
~ $ ]11;rgb:fefe/f4f4/9c9c
walles commented 2 years ago

Example shell script for querying the terminal background color:

#!/bin/sh

OLDSTTY=$(stty -g)

stty raw -echo min 0
echo "\033]11;?\033\\"

# If this delay is too short you will miss your terminal's response
sleep 1

read -r ANSWER
stty "$OLDSTTY"

# Extract response body
RGB=$(echo "$ANSWER" | sed 's/[^r]*//' | sed 's@[^rgb:0-9a-f/]@@g')
echo "$RGB"

Example response: rgb:fefe/f4f4/9c9c

Inspired by: https://stackoverflow.com/a/30540928/473672

walles commented 6 months ago

We should re-apply ed491742a18f145b7fe4c755343d64969a9f7531 (pick status bar color based on the current style) or something to that effect after this is done.

walles commented 5 months ago

Done: https://github.com/walles/moar/releases/tag/v1.23.0