LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 06-20-2012, 09:55 AM   #1
stoat
Member
 
Registered: May 2007
Distribution: LFS
Posts: 628

Rep: Reputation: 185Reputation: 185
Add some color (and other stuff) to your LFS login


Ordinarily, the login prompt appears on the screen following the last line of the init messages. That works just fine, but it can be made to look better.



/etc/issue



The /etc/issue file is described in chapter three of the BLFS book. It is a text file for storing information or instructions for modifying the appearance of the login prompt. The kinds of things that can be added to the login prompt screen include plain text, various bits of system information, and ASCII art. Keyboard and display functions such as changing the cursor location, clearing the display, and changing text colors can be executed. Overall, this stuff can produce a login screen that rivals those of graphic display managers, IMO.



ANSI Escape Sequences



ANSI escape sequences are special sequences of ASCII characters that can be used in /etc/issue to control the cursor’s position, clear the display, and many other things. An ANSI escape sequence always begins with the ASCII "Escape" character 27 (1Bh) followed by the left-bracket character "[ " (5Bh).
Esc[
The characters following the escape and left-bracket characters in an ANSI escape sequence specify an alphanumeric code that controls a keyboard or display function. Some examples...

This one homes the cursor...
Esc[H
This one erases the entire display...
Esc[2J
See more display control sequences here...
http://ascii-table.com/ansi-escape-sequences.php
An obvious problem at this point is how to type the Esc character into the /etc/issue file and create ANSI escape sequences in it. It turns out to be easy, but not exactly straightforward on first sight. So let's move on to that now.



How to Enter ANSI Escape Sequences in /etc/issue



Chapter three of the BLFS book describes a simple way to enter the "home cursor" and "erase display" ANSI escape sequences into /etc/issue...

Code:
clear > /etc/issue
The resulting line in the /etc/issue file created by that looks like this when viewed with vi...
^[[H^[[2J
The first obvious thing to notice about that is the Esc character is depicted as a caret + a left square bracket like this: ^[ . So the two initial ANSI escape sequence characters, Esc and [ , together look like this in the /etc/issue file...
^[[
Again, just to be clear about what you're looking at as the the first two characters of that ANSI escape sequence...
Esc + [ = ^[ + [
The book's /etc/issue file is easy to explain and create without using a text editor. With a text editor, the Esc character cannot simply be typed into a text document that way (as a caret and a left bracket). If you try that, it will not work when you log out or reboot and arrive at the log in prompt. That's probably why the book also warns us to leave that first line of /etc/issue alone.

Okay, so the book's thing is fine for homing the cursor and erasing the display, but for other ANSI escape sequences the Esc character must be entered somehow. As I said, the problem is just with that first Esc character part of an ANSI escape sequence. The rest of an ANSI escape sequence, including the left-bracket following the Esc character, is just text typed in the usual way.

There are various ways to enter the ASCII Esc character in various editors. I prefer to use vi. But my preference does not mean it's the only or best way to enter the Esc character in /etc/issue. Some ways to enter the Esc character...
vi...
Ctrl+v then Esc
emacs...
Ctrl+q then Esc
nano...
Esc then v then Esc
echo...
echo -e "\x1b"
The resulting characters that are entered from any of those are the aforementioned ^[ representing the Esc character. An ANSI escape sequence begun in this way will work in the expected way. There may be even more ways to do this, but I still prefer vi for editing /etc/issue and the method above for enter the Esc character.



Color



The color of the characters printed on the console screen and their background color can be controlled by ANSI escape sequences in this format...
Escape [ style ; foreground ; background m
These are the codes for style, foreground, and background...

Code:
 Style        Foreground     Background
-----------------------------------------
 NORMAL=0     FG_BLACK=30    BG_BLACK=40
 BOLD=1       FG_RED=31      BG_RED=41
 UNDERLINE=4  FG_GREEN=32    BG_GREEN=42
 BLINK=5      FG_YELLOW=33   BG_YELLOW=43
 REVERSE=7    FG_BLUE=34     BG_BLUE=44
              FG_MAGENTA=35  BG_MAGENTA=45
              FG_CYAN=36     BG_CYAN=46
              FG_GRAY=37     BG_GRAY=47
              FG_DEFAULT=39  BG_DEFAULT=49

NOTE: Not specifying a style, foreground, or background code in the
escape sequence is the same as entering the normal or default value.
Example to change the text color (foreground) to bold blue...
^[[1;34m
Example to change the text color to normal blue and change the background to cyan...
^[[0;34;46m
Example to revert back to the default style, text, and background...
^[[0m
You can do other things in /etc/issue to affect the login screen such as add plain text, system information, and ASCII art. Onward to those things now.



agetty Issue Escape Codes



The agetty issue escape codes below can be included in /etc/issue in the format of a backslash ( \ ) followed by the appropriate letter to display the specified system information.

Code:
b   Insert the baudrate of the current line.
d   Insert the current date.
s   Insert the system name, the name of the operating system.
l   Insert the name of the current tty line.
m   Insert the architecture identifier of the machine, e.g., i686.
n   Insert the nodename of the machine, also known as the hostname.
o   Insert the domainname of the machine.
r   Insert the release number of the kernel, e.g., 2.6.11.12.
t   Insert the current time.
u   Insert the number of current users logged in.
U   Insert the string "1 user" or "<n> users" where <n> is the
    number of current users logged in.
v   Insert the version of the OS, e.g., the build-date etc.


Plain Text



Entering plain text in /etc/issue doesn't need much explanation. It will appear on the login screen as typed in /etc/issue except for the backslash character which has special meaning in /etc/issue for the agetty issue escape codes explained above. So to display a backslash as text, it needs to be escaped with another backslash (just type backslashes meant as text two times).



ASCII Art



ASCII art in /etc/issue can jazz up a login screen. If you can't create your own from scratch, then there are plenty of easy-to-find examples and free ASCII art generators that will convert your images into ASCII art. All of this stuff can go in /etc/issue and be displayed on the login screen.

"2001: A Space Odyssey" by Sebastian Stöcker from http://ascii-art.net/index.php with permission...

Code:
                                                _.--"""""--._
                                             ,-'             `-.
                  _                        ,' --- -  ----   --- `.
                ,'|`.                    ,'       ________________`.
               O`.+,'O                  /        /____(_______)___\ \
      _......_   ,=.         __________;   _____  ____ _____  _____  :
    ,'   ,--.-`,,;,:,;;;;;;;///////////|   -----  ---- -----  -----  |
   ( SSt(  ==)=========================|      ,---.    ,---.    ,.   |
    `._  `--'-,``````"""""""\\\\\\\\\\\:     /`. ,'\  /_    \  /\/\  ;
       ``````                           \    :  Y  :  :-'-. :  : ): /
                                         `.  \  |  /  \=====/  \/\/'
                                           `. `-'-'    `---'    ;'
                                             `-._           _,-'
                                                 `--.....--'   ,--.
                                                              ().0()
                                                               `'-'
When copying ASCII art into /etc/issue, again remember the special meaning of the backslash in /etc/issue. Backslashes often are used in ASCII art images. Just as with text, they have to be escaped with another backslash to be displayed. Copying the example above "as is" into /etc/issue will result in many of the backslashes not being displayed on the login screen. Here it is after I added extra backslashes to escape the backslashes in the image...

Code:
                                                _.--"""""--._
                                             ,-'             `-.
                  _                        ,' --- -  ----   --- `.
                ,'|`.                    ,'       ________________`.
               O`.+,'O                  /        /____(_______)___\\ \\
      _......_   ,=.         __________;   _____  ____ _____  _____  :
    ,'   ,--.-`,,;,:,;;;;;;;///////////|   -----  ---- -----  -----  |
   ( SSt(  ==)=========================|      ,---.    ,---.    ,.   |
    `._  `--'-,``````"""""""\\\\\\\\\\\\\\\\\\\\\\:     /`. ,'\\  /_    \\  /\\/\\  ;
       ``````                           \\    :  Y  :  :-'-. :  : ): /
                                         `.  \\  |  /  \\=====/  \\/\\/'
                                           `. `-'-'    `---'    ;'
                                             `-._           _,-'
                                                 `--.....--'   ,--.
                                                              ().0()
                                                               `'-'
Sort of messed up now, but it looks right again on the login screen...

Click image for larger version

Name:	2001.JPG
Views:	1531
Size:	37.6 KB
ID:	9920



My Humble Login Screen



Finally, as a simple example of everything mentioned above, this is in my /etc/issue file...

Code:
^[[H^[[2J
^[[1;34m
  |        ___|    ___|
  |       |       (
  |        __|    ___ \\
  |       |            )
 _____|  _|       ____/
^[[0m
Welcome to Linux From Scratch!
^[[0;35mApollo 13 Version - Build 2^[[0m
Kernel v\r
It homes the cursor, clears the the screen, displays a simple ASCII art image in bold blue, and prints some lines of plain text with color and an issue escape code to print the kernel version...

Click image for larger version

Name:	lfs.JPG
Views:	2262
Size:	64.4 KB
ID:	9921

It's all I want. You can do more with yours if you like. In fact, anybody who is willing should post their login here next. I, for one, would like to see them. Show a screenshot and/or the /etc/issue file.

P.S.: I have tested everything above and use all of it in my own /etc/issue file. But if anyone out there knows of better ways to do this business or something I omitted, then please feel free to add a post to improve the situation.

Last edited by stoat; 06-22-2012 at 05:28 PM.
 
Old 06-20-2012, 10:35 AM   #2
Mordillo98
LQ Newbie
 
Registered: May 2012
Posts: 27

Rep: Reputation: Disabled
Nice stuff... Thx for sharing.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Add stuff by right-clicking lealsaballos Linux - Desktop 7 11-09-2010 08:11 PM
weird ls and --color stuff aveshs Linux - General 1 03-16-2006 09:40 AM
add your fun quotes and stuff Mattentaart General 16 05-05-2004 04:24 PM
Add Color cj2001 Linux - Newbie 2 03-31-2004 08:03 PM
how do i add stuff to the K menu ShawnD Linux - General 3 09-03-2002 11:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 08:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration