Docker build. Very basic zoom scrolling

This commit is contained in:
Thomas Buckley-Houston 2016-04-25 17:09:40 +03:00
parent c27e72bcfa
commit fb6db109f8
7 changed files with 160 additions and 71 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
build/
*.log
*.out

View file

@ -1,3 +1,33 @@
FROM alpine
RUN apk add xvfb xdotool xfce4 ffmpeg chromium
RUN rm -rf /var/cache/apk/*
RUN echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
# Main dependencies
RUN apk add --no-cache xvfb xdotool@testing xfce4 ffmpeg openssh mosh chromium
# Installing Hiptext, video to text renderer
RUN apk --no-cache add --virtual build-dependencies \
build-base git freetype-dev jpeg-dev ffmpeg-dev ragel
RUN apk --no-cache add libgflags-dev@testing glog-dev@testing
RUN mkdir -p build \
&& cd build \
&& wget -q -O /etc/apk/keys/andyshinn.rsa.pub https://raw.githubusercontent.com/andyshinn/alpine-pkg-glibc/master/andyshinn.rsa.pub \
&& wget https://github.com/andyshinn/alpine-pkg-glibc/releases/download/2.23-r1/glibc-2.23-r1.apk \
# && wget https://github.com/andyshinn/alpine-pkg-glibc/releases/download/2.23-r1/glibc-bin-2.23-r1.apk \
# && wget https://github.com/andyshinn/alpine-pkg-glibc/releases/download/2.23-r1/glibc-i18n-2.23-r1.apk \
&& apk --no-cache add glibc-2.23-r1.apk \
# && apk add glibc-2.23-r1.apk glibc-bin-2.23-r1.apk glibc-i18n-2.23-r1.apk \
# && /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8 \
&& git clone https://github.com/tombh/hiptext \
&& cd hiptext \
&& git checkout ffmpeg-updates \
&& make \
# Alpine's version of `install` doesn't support the `--mode=` format
&& install -m 0755 hiptext /usr/local/bin \
&& cd ../.. && rm -rf build \
&& apk --no-cache del build-dependencies
COPY . /app
# CMD ["run.bash"]

41
do.bash
View file

@ -1,41 +0,0 @@
#
# This is AWESOME.
#
# Original code by: Chris F.A. Johnson
#
ESC="" ## A literal escape character
but_row=1
clear
mv=1000 ## mv=1000 for press and release reporting; mv=9 for press only
_STTY=$(stty -g) ## Save current terminal setup
stty -echo -icanon ## Turn off line buffering
printf "${ESC}[?${mv}h " ## Turn on mouse reporting
printf "${ESC}[?25l" ## Turn off cursor
while :
do
x=$(dd bs=1 count=6 2>/dev/null) ## Read six characters
m1=${x#???} ## Remove the first 3 characters
m2=${x#????} ## Remove the first 4 characters
m3=${x#?????} ## Remove the first 5 characters
## Convert to characters to decimal values
eval "$(printf "mb=%d mx=%d my=%d" "'$m1" "'$m2" "'$m3")"
## Values > 127 are signed
[ $mx -lt 0 ] && MOUSEX=$(( 223 + $mx )) || MOUSEX=$(( $mx - 32 ))
[ $my -lt 0 ] && MOUSEY=$(( 223 + $my )) || MOUSEY=$(( $my - 32 ))
## Button pressed is in first 2 bits; use bitwise AND
BUTTON=$(( ($mb & 3) + 1 ))
echo $MOUSEX $MOUSEY $BUTTON > mouse.out
done
printf "${ESC}[?${mv}l" ## Turn off mouse reporting
stty "$_STTY" ## Restore terminal settings
printf "${ESC}[?12l${ESC}[?25h" ## Turn cursor back on
printf "\n${ESC}[0J\n" ## Clear from cursor to bottom of screen

View file

@ -1,21 +0,0 @@
require 'curses'
include Curses
# These 2 allow mouse input
noecho # Prevent input being echoed to the screen
stdscr.keypad(true) # Not sure what this does exactly, but mouse input doesn't work without it
# Block whilst waiting for input
stdscr.timeout = -1
mousemask(ALL_MOUSE_EVENTS)
loop do
case getch
when KEY_MOUSE
m = getmouse
File.open('/home/tombh/Workspace/lowbandwidth/mouse.out', 'w') do |file|
file.write("#{m.x}, #{m.y}, #{m.z}, #{m.bstate}")
end
end
end

View file

@ -1,7 +0,0 @@
#!/bin/bash
ffmpeg -f x11grab -s 3200x1600 -r 12 -i :0.0 -vcodec mpeg2video -f mpegts udp://127.0.0.1:1234 >> ffmpeg.log 2>&1 &
sleep 1
# (/home/tombh/.rbenv/versions/2.3.0/bin/ruby ./forward_mouse.rb <&3 &) 3<&0
(./do.bash <&3 &) 3<&0
hiptext -width 95 -font /usr/share/fonts/TTF/DejaVuSansMono.ttf 'udp://127.0.0.1:1234' 2> hiptext.log
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

47
run.sh Executable file
View file

@ -0,0 +1,47 @@
#!/bin/sh
export LC_ALL=C
export LANG=C
export DESKTOP_WIDTH='1600'
export DESKTOP_HEIGHT='1200'
export TERMINAL_WIDTH='95'
export TERMINAL_HEIGHT='40'
export DISPLAY=:0
DESKTOP_RES="$DESKTOP_WIDTH"x"$DESKTOP_HEIGHT"
UDP_URI='udp://127.0.0.1:1234'
# Create an X desktop in memory without actually displaying it on a real screen
Xvfb :0 -screen 0 "$DESKTOP_RES"x16 &
/usr/bin/xfwm4 &
/usr/bin/thunar &
sleep 5
# Convert the X framebuffer desktop into a video stream
ffmpeg \
-f x11grab \
-s $DESKTOP_RES \
-r 12 \
-i :0.0 \
-vcodec mpeg2video \
-f mpegts \
$UDP_URI \
>> ffmpeg.log 2>&1 &
# The above ffmpeg can take a while to open the UDP stream, so wait a little
sleep 1
# Intercept STDIN and forward to the X framebuffer via xdotool
(./stdin_intercept.sh <&3 &) 3<&0
# Hiptext renders images and videos into text characters displayable in a terminal
hiptext \
-width 95 \
-font /usr/share/fonts/ttf-dejavu/DejaVuSansMono.ttf \
$UDP_URI \
2> hiptext.log
# Kill all the subprocesses created in this script if the script itself exits
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

80
stdin_intercept.sh Executable file
View file

@ -0,0 +1,80 @@
# Intercept all STDIN from the user's local machine and forward to the
# remote X framebuffer via xdotool. This is exposed via an SSH/MoSH session.
#
# Hat tip to Chris F.A. Johnson whereever you are.
ESC="" # A literal escape character (it's not blank!)
clear
mv=1000 # mv=1000 for press and release reporting; mv=9 for press only
_STTY=$(stty -g) # Save current terminal setup
stty -echo -icanon # Turn off line buffering
printf "${ESC}[?${mv}h " # Turn on mouse reporting
printf "${ESC}[?25l" # Turn off cursor
# Ratios to convert mouse clicks in the terminal to mouse clicks on the virtual desktop
XFACTOR=$(($DESKTOP_WIDTH / $TERMINAL_WIDTH))
YFACTOR=$(($DESKTOP_HEIGHT / $TERMINAL_HEIGHT))
while :
do
# TODO: parse actual keyboard presses
# TODO: use the more modern mouse modes, eg; 1015
x=$(dd bs=1 count=6 2>/dev/null) # Read six characters
m1=${x#???} # Remove the first 3 characters
m2=${x#????} # Remove the first 4 characters
m3=${x#?????} # Remove the first 5 characters
# Convert from characters to decimal values
eval "$(printf "mb=%d mx=%d my=%d" "'$m1" "'$m2" "'$m3")"
# Values > 127 are signed
[ $mx -lt 0 ] && MOUSEX=$(( 223 + $mx )) || MOUSEX=$(( $mx - 32 ))
[ $my -lt 0 ] && MOUSEY=$(( 223 + $my )) || MOUSEY=$(( $my - 32 ))
case $mb in
32) # Left down
BUTTON=1
BPRESS='mousedown'
;;
33) # Middle down
BUTTON=2
BPRESS='mousedown'
;;
34) # Right down
BUTTON=3
BPRESS='mousedown'
;;
35) # Last button up
BUTTON=$BUTTON
BPRESS='mouseup'
;;
97)
BUTTON=4
BPRESS='click'
;;
96)
BUTTON=5
BPRESS='click'
;;
esac
WINX=$(($MOUSEX * $XFACTOR))
WINY=$(($MOUSEY * $YFACTOR))
if [ "$DEBUG" = "true" ]; then
echo "$MOUSEX"x"$MOUSEY" "$WINX"x"$WINY" "$BUTTON":"$BPRESS"
fi
xdotool mousemove $WINX $WINY
xdotool keydown alt $BPRESS $BUTTON keyup alt
echo "xdotool mousemove $WINX $WINY" >> mouse.out
echo "xdotool keydown alt $BPRESS $BUTTON keyup alt" >> mouse.out
done
printf "${ESC}[?${mv}l" # Turn off mouse reporting
stty "$_STTY" # Restore terminal settings
printf "${ESC}[?12l${ESC}[?25h" # Turn cursor back on
printf "\n${ESC}[0J\n" # Clear from cursor to bottom of screen