~mil/f_scripts

ref: cd1986844d6b5eaeb0e991e07d7329b221c5aa5a f_scripts/scripts/f_web -rwxr-xr-x 2.9 KiB
cd198684Miles Alan f_maps: Disable bg clearing in directfb to prevent clearing fbp space 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env osh
shopt -s strict:all
DEP="w3m netsurf-framebuffer tslib"
DEC="Select a website and browse via w3m or netsurf"
DOC="
  Browse the web via w3m (text) or netsurf (graphical) setting fbp hotkeys
  to helpful hotkeys.
  
  Quirks - starts w3m in mode that respects C-c.
  For netsurf, has to be run as root (so runs via sudo).

  Set \$F_WEB_SITES to customize sites shown to user
"
VAR="
  F_WEB_SITES='
    npr text.npr.org
    ddg duck.com
    hn news.ycombinator.com
    lbtr lobste.rs
    cnn lite.cnn.com
    pmos postmarketos.org
  '
  F_WEB_NETSURF_FBPRATIO='2 / 3'
  F_WEB_NETSURF_YRES='1440'
  F_WEB_NETSURF_XRES='720'
"

netsurflaunch() {
  local XRES YRES URL INPUTDEV
  URL="$1"
  env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"
  XRES="$(echo "$F_WEB_NETSURF_XRES" | bc)"
  YRES="$(echo "$F_WEB_NETSURF_YRES * $F_WEB_NETSURF_FBPRATIO" | bc)"
  fbset -yres "$YRES"
  export SDL_MOUSEDRV=TSLIB
  # Interferes with fbp VT switching
  export DFBARGS="system=fbdev,no-cursor,disable-module=linux_input,no-vt,no-vt-switch" 
  INPUTDEV="$(ts_uinput -d -v)"
  export TSLIB_TSDEVICE="$INPUTDEV"
  ts_calibrate
  mkdir -p $HOME/.netsurf
  echo "fb_toolbar_size: 70" > $HOME/.netsurf/Choices
  echo "fb_toolbar_layout:blfsruct" >> $HOME/.netsurf/Choices
  [ -p /tmp/fbp.fifo ] && echo -e "\a" > /tmp/fbp.fifo
  netsurf-fb -f sdl -w "$XRES" -h "$YRES" "$URL"
  fbset -yres "$F_WEB_NETSURF_YRES"
  [ -p /tmp/fbp.fifo ] && echo -e "\v" > /tmp/fbp.fifo
}

w3mlaunch() {
  local URL
  URL="$1"

  w3msetfbp
  w3m -o keymap_file="$(w3mcfg)" "$URL"
  [ -p /tmp/fbp.fifo ] && echo -e "\r" > /tmp/fbp.fifo
}

w3msetfbp() {
  [ -p /tmp/fbp.fifo ] && { 
    echo -e "\b\f\e"; 
    echo "g + - j k w b B \\t \\n u v Q" | tr " " "\n" 
  }  > /tmp/fbp.fifo
}

w3mcfg() {
  local FILE

  # By default C-c just stops loading; fbp sends C-c
  FILE="$(mktemp)"
  echo "keymap  C-c EXIT" > "$FILE"
  echo "$FILE"
}

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

  local HANDLE URL MODE
  echo "f_web:"
  echo "graphical = netsurf"
  echo "text = w3m"
  OPTS="graphical text"
  [ -p /tmp/fbp.fifo ] && { echo -e "\b\r\f"; echo "$OPTS" | tr " " "\n"; } > /tmp/fbp.fifo
  read -p "Mode ($OPTS)" MODE


  while true; do
    clear
    echo "$F_WEB_SITES"
    echo "Or your custom site, just type!"
    HANDLEOPTS="$(echo "$F_WEB_SITES" | awk '{$1=$1};1' | cut -d' ' -f1 | tr "\n" " ")"
    [ -p /tmp/fbp.fifo ] && { echo -e "\b\r\f"; echo "$HANDLEOPTS" | tr " " "\n"; } > /tmp/fbp.fifo
    read -p "Handle ($HANDLEOPTS): " HANDLE

    URL="$(
      echo "$F_WEB_SITES" |
        sed '/^[[:space:]]*$/d' |
        awk '{$1=$1};1' |
        grep "$HANDLE" | 
        cut -d ' ' -f2
    )"

    [ "$MODE" = text ] && w3mlaunch "$URL"
    [ "$MODE" = graphical ] && {
      [ -p /tmp/fbp.fifo ] && echo -e "\a" > /tmp/fbp.fifo
      sudo "$0" netsurflaunch "$URL"
    }
  done
}

if [ -n "$1" ]; then "$@"; else main; fi