~mil/f_scripts

77bd65e4d9b5a79844467ae4b68b705f120feac0 — Miles Alan 6 months ago 3e36502
f_theme: Add rotate entry switch 1/3 fbcon pref; & add missing fifo checks
1 files changed, 18 insertions(+), 11 deletions(-)

M scripts/f_theme
M scripts/f_theme => scripts/f_theme +18 -11
@@ 3,12 3,12 @@ shopt -s strict:all
DEP="terminus-font util-linux-misc"
DEC="Change the framebuffer theme (font & colors)"
DOC="
  Allows customizing your framebuffer's theme by setting
  the font and colors. Uses the setterm and setfont command line
  tools - so only applicable in the TTY / framebuffer. Also uses
  escape codes to make colors (true black / true white).
  Allows customizing your framebuffer's theme by setting the font, colors,
  and framebuffer rotation. Uses the setterm and setfont command line
  tools - so only applicable in the TTY / framebuffer. Also uses escape
  codes to make colors (true black / true white).

  Use the variables for \$F_THEME_FONT_{SM,MD,LG} to set the fonts
  Use the variables for \$F_THEME_FONT{SM,MD,LG} to set the fonts
  used for {sm,md,lg}{white,dark}.
"
VAR='


@@ 17,30 17,29 @@ VAR='
  F_THEME_FONTLG="/usr/share/consolefonts/ter-v32n.psf.gz"
'


fontchange() {
  local FONTS PICKED

  FONTS="$(ls -1 /usr/share/consolefonts/ | sed 's/.psf.gz//g' )"
  echo -e "\b\fcancel\n$FONTS" > /tmp/fbp.fifo
  [ -p /tmp/fbp.fifo ] && echo -e "\b\fcancel\n$FONTS" > /tmp/fbp.fifo
  echo "$FONTS"
  echo "Pick a font:"
  read -r PICKED
  [ "$PICKED" = cancel ] && return
  setfont /usr/share/consolefonts/$PICKED.psf.gz
  echo -e "\v" > /tmp/fbp.fifo
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

blackonwhite() {
  setterm -foreground black -background white --clear --store
  echo  -en "\e]P7ffffff"
  echo -e "\v" > /tmp/fbp.fifo
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

whiteonblack() {
  setterm -foreground white -background black --clear --store
  echo  -en "\e]P7ffffff"
  echo -e "\v" > /tmp/fbp.fifo
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

lgdark() { setfont $F_THEME_FONTLG; whiteonblack; }


@@ 51,13 50,21 @@ lgwhite() { setfont $F_THEME_FONTLG; blackonwhite; }
mdwhite() { setfont $F_THEME_FONTMD; blackonwhite; }
smwhite() { setfont $F_THEME_FONTSM; blackonwhite; }

rotate() {
  [ -p /tmp/fbp.fifo ] && echo -e "\a" > /tmp/fbp.fifo
  echo "$(
    grep -q 1 /sys/class/graphics/fbcon/rotate && echo 0 || echo 1
  )" | sudo tee /sys/class/graphics/fbcon/rotate_all > /dev/null
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

main() {
  local RUN

  env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"

  while true; do
    OPTS="lgdark mddark smdark lgwhite mdwhite smwhite fontchange"
    OPTS="lgdark mddark smdark lgwhite mdwhite smwhite fontchange rotate"
    [ -p /tmp/fbp.fifo ] && { echo -e "\b\f\r"; echo "$OPTS" | tr " " "\n"; } > /tmp/fbp.fifo
    read -p "Choice ($OPTS)" RUN
    "$RUN"