Provide CTRL+ALT+Q to cleanly exit

pull/16/head
Thomas Buckley-Houston 2016-06-03 13:31:00 +09:00
rodzic 287d21916d
commit 576821fa37
3 zmienionych plików z 65 dodań i 15 usunięć

Wyświetl plik

@ -58,7 +58,9 @@ MoSH is available through most system package managers. SSH can be used exactly
`user@yourserver` is the normal URI you would use to connect via SSH.
**Exiting**
At the moment the only way to exit is with MoSH's `CTRL+^ .` or SSH's `ENTER ~ .`
`CTRL+ALT+Q` will drop you back to the docker container's CLI. You can start again with `./run.sh`
If MoSH or SSH become unresponsive you can exit MoSH with `CTRL+^ .` or SSH with `ENTER ~ .`
##Interaction
* `CTRL + mousewheel` to zoom

Wyświetl plik

@ -46,28 +46,38 @@ var panNeedsSetup bool
var panStartingX float32
var panStartingY float32
var debugMode = parseENVVar("DEBUG") == 1
func initialise() {
setupLogging()
log("Starting...")
setupTermbox()
setupDimensions()
C.xzoom_init()
xzoomBackground()
if !debugMode {
C.xzoom_init()
xzoomBackground()
}
}
func parseENVVar(variable string) int {
value, err := strconv.Atoi(os.Getenv(variable))
if err != nil {
panic(err)
return 0
}
return value
}
func setupDimensions() {
hipWidth = parseENVVar("TTY_WIDTH")
hipHeight = parseENVVar("TTY_HEIGHT")
envDesktopWidth = parseENVVar("DESKTOP_WIDTH")
envDesktopHeight = parseENVVar("DESKTOP_HEIGHT")
if debugMode {
hipWidth, hipHeight = termbox.Size()
envDesktopWidth = 1200
envDesktopHeight = 900
} else {
hipWidth = parseENVVar("TTY_WIDTH")
hipHeight = parseENVVar("TTY_HEIGHT")
envDesktopWidth = parseENVVar("DESKTOP_WIDTH")
envDesktopHeight = parseENVVar("DESKTOP_HEIGHT")
}
C.desktop_width = C.int(envDesktopWidth)
C.width[C.SRC] = C.desktop_width
C.width[C.DST] = C.desktop_width
@ -85,7 +95,7 @@ func setupTermbox() {
if err != nil {
panic(err)
}
termbox.SetInputMode(termbox.InputMouse)
termbox.SetInputMode(termbox.InputAlt | termbox.InputMouse)
}
func setupLogging() {
@ -100,6 +110,14 @@ func setupLogging() {
}
}
func printXY(x, y int, s string) {
for _, r := range s {
termbox.SetCell(x, y, r, termbox.ColorWhite, termbox.ColorDefault)
x++
}
termbox.Flush()
}
func log(msg string) {
f, oErr := os.OpenFile(logfile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if oErr != nil {
@ -111,6 +129,10 @@ func log(msg string) {
if _, wErr := f.WriteString(msg); wErr != nil {
panic(wErr)
}
if debugMode {
printXY(0, 0, msg)
}
}
func min(a float32, b float32) float32 {
@ -130,6 +152,9 @@ func getYGrab() int {
// Issue an xdotool command to simulate mouse and keyboard input
func xdotool(args ...string) {
log(strings.Join(args, " "))
if debugMode {
return
}
if args[0] == "noop" {
return
}
@ -155,6 +180,10 @@ func ctrlPressed() bool {
return curev.Mod&termbox.ModCtrl != 0
}
func altPressed() bool {
return curev.Mod&termbox.ModAlt != 0
}
// Whether the mouse is moving
func mouseMotion() bool {
return curev.Mod&termbox.ModMotion != 0
@ -442,10 +471,20 @@ func xzoomBackground() {
}()
}
func needToExit() bool {
// CTRL+ALT+Q
if (curev.Key == termbox.KeyCtrlQ) && altPressed() {
return true
}
return false
}
func teardown() {
termbox.Close()
close(stopXZoomChannel)
<-xZoomStoppedChannel
if !debugMode {
close(stopXZoomChannel)
<-xZoomStoppedChannel
}
}
// I'm afraid I don't understand most of what this does :/
@ -470,6 +509,9 @@ func mainLoop() {
break
}
curev = ev
if needToExit() {
return
}
copy(data, data[curev.N:])
data = data[:len(data)-curev.N]
}

14
run.sh
Wyświetl plik

@ -52,7 +52,16 @@ ffmpeg \
sleep 1
# Intercept STDIN (mouse and keypresses) and forward to the X framebuffer via xdotool
(./interfacer/interfacer <&3 > ./logs/interfacer.log 2>&1 &) 3<&0
(
# Kill all the processes in this script when the interfacer exits
trap '
trap - EXIT
killall Xvfb firefox ffmpeg hiptext
exit
' EXIT INT TERM
./interfacer/interfacer <&3 > ./logs/interfacer.log 2>&1
) 3<&0 &
# Hiptext renders images and videos into text characters displayable in a terminal.
# It complains unless you specify the exact path to the font, seems like a bug to me.
@ -63,6 +72,3 @@ hiptext \
-bgprint=true \
$UDP_URI \
2> ./logs/hiptext.log
# Kill all the subprocesses created in this script if the script itself exits
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT