ash/stty usage
James Simmons
jsimmons at infradead.org
Fri Jun 13 20:54:11 UTC 2008
On Fri, 13 Jun 2008, Denys Vlasenko wrote:
> On Thursday 12 June 2008 22:59, James Simmons wrote:
> >
> > > > Hi!
> > > >
> > > > I'm attempting color text but I'm getting "K[37;1mTextK[31;1m". Any
> > > > idea what is wrong?
> > >
> > > What do you do to get it?
> >
> > echo "IP address <$ip>"
>
> Well, I meant "give me means to reproduce your case" :)
Here you go. In bash the text is:
Software version: 1.0.0
In ash it prints:
Software version: K[37;1m1.0.0K[37;0m
#!/busybox-1.6.1/_install/bin/sh
_reset='\033[0m'
_black='\033[30;00m'
_grey='\033[37;0m'
_dgrey='\033[30;1m'
_white='\033[37;1m'
_red='\033[31;1m'
_dred='\033[31;0m'
_green='\033[32;1m'
_dgreen='\033[32;0m'
_yellow='\033[33;1m'
_brown='\033[33;0m'
_blue='\033[34;1m'
_dblue='\033[34;0m'
_magenta='\033[35;1m'
_dmagenta='\033[35;0m'
_cyan='\033[36;1m'
_dcyan='\033[36;0m'
color() {
local c="$1"
local name
case "$c" in
""|default) c=grey ;;
grey) ;;
dgrey) ;;
white) ;;
red) ;;
dred) ;;
green) ;;
dgreen) ;;
yellow) ;;
brown) ;;
blue) ;;
dblue) ;;
magenta) ;;
dmagenta) ;;
cyan) ;;
dcyan) ;;
*) return 1 ;;
esac
name="_${c}"
CURRENT_COLOR="$c"
eval CURRENT_COLOR_ESC=\"\$${name}\"
echo -en "${CURRENT_COLOR_ESC}"
}
echo_with_bold() {
[ -n "$CURRENT_COLOR_ESC" ] || color default
local tmp="$2"
tmp=${tmp//</${1}}
tmp=${tmp//>/${CURRENT_COLOR_ESC}}
echo -e "${tmp}"
}
VERSION=1.0.0
ver_color=${_white}
text="Software version: <${VERSION}>"
echo_with_bold "${ver_color}" " ${text}"
> > > > Also I'm looking to flush the tty. Currently I'm doing
> > > >
> > > > Do you know of a better way?
> > >
> > > Don't know for sure, maybe this?
> > >
> > > int tcflush(int fd, int queue_selector);
> >
> > I was hoping some app in busybox did that in some way. Will search for
> > tools to do that.
>
> If you can confirm that the above code works for you
> as a tiny standalone executable, it can be added to busybox.
Hum. I'm going to dig into this some more. There must be a terminal
control code to flush the buffer. Prehaps ^O to the terminal.
More information about the busybox
mailing list