Stop blindly assuming that a blank TERM is cons25. For cons25 terms we drop one column so we don't get an extra newline.

This commit is contained in:
Roy Marples 2007-05-02 10:43:43 +00:00
parent b2d024b7f4
commit 700bdb4f1d
3 changed files with 42 additions and 22 deletions

View File

@ -5,10 +5,13 @@
# Ensure we are called by init # Ensure we are called by init
[ "$PPID" = "1" ] || exit 0 [ "$PPID" = "1" ] || exit 0
# If $TERM is not set then assume default of cons25
# This gives us a nice colour boot :)
[ -z "$TERM" ] && export TERM="cons25"
# BSD's init works somewhat differently to sysvinit. # BSD's init works somewhat differently to sysvinit.
# This block should 'translate' from the way init calls it to the way it would # This block should 'translate' from the way init calls it to the way it would
# be called by sysvinit on linux. # be called by sysvinit on linux.
RUNLEVEL="1" /sbin/rc sysinit || exit 1 RUNLEVEL="1" /sbin/rc sysinit || exit 1
RUNLEVEL="1" /sbin/rc boot || exit 1 RUNLEVEL="1" /sbin/rc boot || exit 1
PREVLEVEL="1" /sbin/rc default PREVLEVEL="1" /sbin/rc default

View File

@ -7,8 +7,11 @@
# Try and use stuff in /lib over anywhere else so we can shutdown # Try and use stuff in /lib over anywhere else so we can shutdown
# local mounts correctly. # local mounts correctly.
LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}" export LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}"
export LD_LIBRARY_PATH
# If $TERM is not set then assume default of cons25
# This gives us a nice colour shutdown :)
[ -z "$TERM" ] && export TERM="cons25"
# BSD's init works somewhat differently to sysvinit. # BSD's init works somewhat differently to sysvinit.
# This block should 'translate' from the way init calls it to the way it would # This block should 'translate' from the way init calls it to the way it would
@ -16,6 +19,6 @@ export LD_LIBRARY_PATH
case "$1" in case "$1" in
reboot) export RUNLEVEL=6;; reboot) export RUNLEVEL=6;;
shutdown) export RUNLEVEL=0;; shutdown) export RUNLEVEL=0;;
single) export RUNLEVEL=S;; single) export RUNLEVEL=S;;
esac esac
exec /sbin/rc "$1" exec /sbin/rc "$1"

View File

@ -124,6 +124,8 @@ static const char *color_terms[] = {
static int stdfd[2] = {-1, -1}; static int stdfd[2] = {-1, -1};
static FILE *ebfp = NULL; static FILE *ebfp = NULL;
static char ebfile[PATH_MAX] = { '\0' }; static char ebfile[PATH_MAX] = { '\0' };
static const char *term = NULL;
static bool term_is_cons25 = false;
/* A pointer to a string to prefix to einfo/ewarn/eerror messages */ /* A pointer to a string to prefix to einfo/ewarn/eerror messages */
static const char *_eprefix = NULL; static const char *_eprefix = NULL;
@ -146,17 +148,22 @@ static bool colour_terminal (void)
{ {
static int in_colour = -1; static int in_colour = -1;
int i = 0; int i = 0;
char *term;
if (in_colour == 0) if (in_colour == 0)
return (false); return (false);
if (in_colour == 1) if (in_colour == 1)
return (true); return (true);
term = getenv ("TERM"); if (! term) {
/* If $TERM isn't set then the chances are we're in single user mode */ term = getenv ("TERM");
if (! term) if (! term)
return (true); return (false);
}
if (strcmp (term, "cons25") == 0)
term_is_cons25 = true;
else
term_is_cons25 = false;
while (color_terms[i]) { while (color_terms[i]) {
if (strcmp (color_terms[i], term) == 0) { if (strcmp (color_terms[i], term) == 0) {
@ -575,35 +582,44 @@ int ebegin (const char *fmt, ...)
} }
hidden_def(ebegin) hidden_def(ebegin)
static void _eend (int col, einfo_color_t color, const char *msg) static void _eend (FILE *fp, int col, einfo_color_t color, const char *msg)
{ {
FILE *fp = stdout;
int i; int i;
int cols; int cols;
if (! msg) if (! msg)
return; return;
if (color == ecolor_bad) cols = get_term_columns () - (strlen (msg) + 5);
fp = stderr;
cols = get_term_columns () - (strlen (msg) + 6); /* cons25 is special - we need to remove one char, otherwise things
* do not align properly at all. */
if (! term) {
term = getenv ("TERM");
if (term && strcmp (term, "cons25") == 0)
term_is_cons25 = true;
else
term_is_cons25 = false;
}
if (term_is_cons25)
cols--;
if (cols > 0 && colour_terminal ()) { if (cols > 0 && colour_terminal ()) {
fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols, fprintf (fp, "\033[A\033[%dC %s[ %s%s %s]%s\n", cols,
ecolor (ecolor_bracket), ecolor (color), msg, ecolor (ecolor_bracket), ecolor (color), msg,
ecolor (ecolor_bracket), ecolor (ecolor_normal)); ecolor (ecolor_bracket), ecolor (ecolor_normal));
} else { } else {
for (i = -1; i < cols - col; i++) if (col > 0)
fprintf (fp, " "); for (i = 0; i < cols - col; i++)
fprintf (fp, "[ %s ]\n", msg); fprintf (fp, " ");
fprintf (fp, " [ %s ]\n", msg);
} }
} }
static int _do_eend (const char *cmd, int retval, const char *fmt, va_list ap) static int _do_eend (const char *cmd, int retval, const char *fmt, va_list ap)
{ {
int col = 0; int col = 0;
FILE *fp; FILE *fp = stdout;
va_list apc; va_list apc;
if (fmt && retval != 0) { if (fmt && retval != 0) {
@ -616,11 +632,9 @@ static int _do_eend (const char *cmd, int retval, const char *fmt, va_list ap)
fp = stderr; fp = stderr;
} }
va_end (apc); va_end (apc);
if (colour_terminal ())
fprintf (fp, "\n");
} }
_eend (col, _eend (fp, col,
retval == 0 ? ecolor_good : ecolor_bad, retval == 0 ? ecolor_good : ecolor_bad,
retval == 0 ? OK : NOT_OK); retval == 0 ? OK : NOT_OK);
return (retval); return (retval);
@ -658,7 +672,7 @@ hidden_def(ewend)
void ebracket (int col, einfo_color_t color, const char *msg) void ebracket (int col, einfo_color_t color, const char *msg)
{ {
_eend (col, color, msg); _eend (stdout, col, color, msg);
} }
hidden_def(ebracket) hidden_def(ebracket)