#!/bin/bash

# flashforth port
TTY=/dev/ttyUSB0
MOI=`tty`

# flavor of xterm
# TERM=black
TERM=blue

BAUD=38400

# commands

# set serial tty and current tty to raw, and connect them via nullmodem

MODE="raw -echo"
# MODE=sane

here_old () {
    echo $MOI
    stty -F $TTY $MODE $BAUD
    stty -F $MOI $MODE
    exec nullmodem $TTY $MOI
}

SOCAT_TTY=$TTY,raw,echo=0,cr,igncr=1,ixon=1,b$BAUD,cr3
here () {
    exec socat $SOCAT_TTY \
	READLINE,history=$HOME/.flashforth_history
}

pipe () {
    exec socat $SOCAT_TTY -
}

term () {
    exec $TERM -e $0 here
}

# if no args, run again but in xterm
[ -z $1 ] && here


# else run command
$1
