Archiv verlassen und diese Seite im Standarddesign anzeigen : Perlig
Wisst ihr wie man Farbe mit Perl in der Console ausgibt?
Interessant für mich zu wissen wäre auch wie man in Perl eine Eingabeaufforderung (mitsamt Wertübergabe) schreibt.
Außerdem: Kann ich Ausdrücke in regulären Ausdrücken verwenden?
Beispiel:
$filter = "/^$array[0]/";
if ($suchzeile =~ eval($filter)) {
...
ist sowas möglich?
please help me, out there....
> in Perl eine Eingabeaufforderung (mitsamt Wertübergabe) schreibt.
??? sehr unverständlich
Zum verwenden von Farben auf der Console Ansi-Escape Sequenzen mitausgeben. Beispiele hier in der rc.status(bash-Syntax)
# /etc/rc.status
# Definition of boot script return messages
#
# The bootscripts should use the variables rc_done and rc_failed to
# report whether they failed or succeeded. See /etc/init.d/skeleton for
# an example how the shell functions rc_status and rc_reset are used.
#
# These functions make use of the variables rc_done and rc_failed;
# rc_done_up and rc_failed_up are the same as rc_done and rc_failed
# but contain a terminal code to move up one line before the output
# of the actual string. (This is particularly useful when the script
# starts a daemon which produces user output with a newline character)
#
# The variable rc_reset is used by the master resource control script
# /etc/init.d/rc to turn off all attributes and switch to the standard
# character set.
#
# \033 ascii ESCape
# \033[<NUM>G move to column <NUM> (linux console, xterm, not vt100)
# \033[<NUM>C move <NUM> columns forward but only upto last column
# \033[<NUM>D move <NUM> columns backward but only upto first column
# \033[<NUM>A move <NUM> rows up
# \033[<NUM>B move <NUM> rows down
# \033[1m switch on bold
# \033[31m switch on red
# \033[32m switch on green
# \033[33m switch on yellow
# \033[m switch on color/bold
# \017 exit alternate mode (xterm, vt100, linux console)
# \033[10m exit alternate mode (linux console)
# \015 carriage return (without newline)
#
# check whether splash screen animations are installed.
_rc_splash=0
test -x /bin/splash && _rc_splash=1
if test -z "$LINES" -o -z "$COLUMNS" ; then
eval `stty size 2>/dev/null | (read L C; \
echo LINES=${L:-24} COLUMNS=${C:-80})`
fi
test $LINES -eq 0 && LINES=24
test $COLUMNS -eq 0 && COLUMNS=80
export LINES COLUMNS
if test "$TERM" != "raw" && stty size > /dev/null 2>&1 ; then
esc=`echo -en "\033"`
extd="${esc}[1m"
warn="${esc}[1;31m"
done="${esc}[1;32m"
attn="${esc}[1;33m"
norm=`echo -en "${esc}[m\017"`
stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"`
rc_done="${stat}${done}done${norm}"
rc_running="${stat}${done}running${norm}"
rc_failed="${stat}${warn}failed${norm}"
rc_missed="${stat}${warn}missing${norm}"
rc_skipped="${stat}${attn}skipped${norm}"
rc_dead="${stat}${warn}dead${norm}"
rc_unused="${stat}${extd}unused${norm}"
rc_done_up="${esc}[1A${rc_done}"
rc_failed_up="${esc}[1A${rc_failed}"
rc_reset="${norm}"
rc_save="${esc}7"
rc_restore="${esc}8"
function rc_cuu () { echo -en "\033[${1}A"; }
else
esc=""
extd=""
warn=""
done=""
attn=""
norm=""
stat=""
rc_done="..done"
rc_running="..running"
rc_failed="..failed"
rc_missed="..missing"
rc_skipped="..skipped"
rc_dead="..dead"
rc_unused="..unused"
rc_done_up="${rc_done}"
rc_failed_up="${rc_failed}"
rc_reset=""
rc_save=""
rc_restore=""
function rc_cuu () { return; }
fi
_rc_status=0
_rc_status_all=0
_rc_todo=$1
function rc_check ()
{
_rc_check_ret=$?
test $_rc_check_ret -eq 0 || _rc_status=$_rc_check_ret
test $_rc_status -eq 0 || _rc_status_all=$_rc_status
return $_rc_check_ret
}
function rc_reset ()
{
_rc_status=0
rc_check
return 0
}
if test "$_rc_todo" = "status" ; then
function rc_status ()
{
rc_check
for i ; do
case "$i" in
-v|-v[1-9]|-v[1-9][0-9])
echo -en "$rc_save"
test -n "${i#-v}" && rc_cuu ${i#-v}
case "$_rc_status" in
0) echo -en "$rc_running" ;; # service running
1) echo -en "$rc_dead" 1>&2 ;; # service dead (no pid file)
2) echo -en "$rc_dead" 1>&2 ;; # service dead (no lock if any)
3) echo -en "$rc_unused" ;; # service not running
esac
echo -en "$rc_restore"
test -z "${i#-v}" && echo ;;
-r) rc_reset ;;
-s) echo -e "$rc_skipped" ; rc_failed 3 ;;
-u) echo -e "$rc_unused" ; rc_failed 3 ;;
*) echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
esac
done
return $_rc_status
}
elif test -n "$_rc_todo" ; then
function rc_status ()
{
rc_check
test "$_rc_status" -gt 7 && rc_failed 1
for i ; do
case "$i" in
-v|-v[1-9]|-v[1-9][0-9])
echo -en "$rc_save"
test -n "${i#-v}" && rc_cuu ${i#-v}
case "$_rc_status" in
0) echo -en "$rc_done" ;; # success
1) echo -en "$rc_failed" 1>&2 ;; # generic or unspecified error
2) echo -en "$rc_failed" 1>&2 ;; # invalid or excess args
3) echo -en "$rc_missed" 1>&2 ;; # unimplemented feature
4) echo -en "$rc_failed" 1>&2 ;; # insufficient privilege
5) echo -en "$rc_skipped" 1>&2 ;; # program is not installed
6) echo -en "$rc_unused" 1>&2 ;; # program is not configured
7) test "$_rc_todo" = "stop" && {
echo -en "$rc_done" # program is not running which
rc_failed 0 # is success if we stop service
} || \
echo -en "$rc_failed" 1>&2 ;; # program is not running
*) echo -en "$rc_failed" 1>&2 ;; # unknown (maybe used in future)
esac
echo -en "$rc_restore"
test -z "${i#-v}" && echo ;;
-r) rc_reset ;;
-s) echo -e "$rc_skipped" 1>&2 ; rc_failed 5 ;;
-u) echo -e "$rc_unused" 1>&2 ; rc_failed 6 ;;
*) echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
esac
done
return $_rc_status
}
else
function rc_status ()
{
rc_check
for i ; do
case "$i" in
-v|-v[1-9]|-v[1-9][0-9])
echo -en "$rc_save"
test -n "${i#-v}" && rc_cuu ${i#-v}
test $_rc_status -gt 0 && echo -en "$rc_failed" || echo -en "$rc_done"
echo -en "$rc_restore"
test -z "${i#-v}" && echo ;;
-r) rc_reset ;;
-s) echo -e "$rc_skipped" ; return 0 ;;
-u) echo -e "$rc_unused" ; return 0 ;;
*) echo "rc_status: Usage: [-v[<num>] [-r]|-s|-u]" 1>&2 ; return 0 ;;
esac
done
return $_rc_status
}
fi
function rc_failed ()
{
case "$1" in
[0-7]) _rc_status=$1 ;;
"") _rc_status=1
esac
rc_check
return $_rc_status
}
function rc_exit ()
{
exit $_rc_status_all
}
function rc_splash()
{
test "$BOOT_SPLASH" != "no" && test "$_rc_splash" -eq 1 && /bin/splash "$1"
}
Mitsamt Wertübergabe meine ich dass ich die Tastatureingabe auswerten kann, nicht nur ein TASTE-GEDRÜCKT oder TASTE-NICHT-GEDRÜCKT Ereignis.
Das mit der Farbe: Hmm... *g* kannst du mir nicht einfach die Textstelle extrahieren die mir weiterhelfen wird?
Damit habe ich z. B. gemeint das man diese ANSI-Escape Sequenzen nutzen könnte:
# \033[1m switch on bold
# \033[31m switch on red
# \033[32m switch on green
# \033[33m switch on yellow
# \033[m switch on color/bold
z. B. so:
#!/usr/bin/perl
for(30 .. 60) {
system("echo -e \"bla\\033[".$_."mblabla\\033[39m\"");
}
Aber das geht garantiert eleganter. Da gibt's bestimmt ein Modul für. Einfach mal suchen im CPAN oder mit perlfaq/perldoc!
Powered by vBulletin® Version 4.2.5 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.