View Single Post
Old August 4th, 2007   #80
s1ightcrazed
Just Give Me the Beans!
 
s1ightcrazed's Avatar
 
Join Date: Feb 2007
Location: somewhere cold
Beans: 62
Kubuntu 8.10 Intrepid Ibex
Re: "Hello Ubuntu" in every programming language

Curses (Python)

Code:
import curses, traceback, string

screen = None

def main(stdscr):
	global screen
	# add subscreen to main window
	screen = stdscr.subwin(23, 79, 0, 0)
	# draw box around subscreen
	screen.box()
	# draw keyhelp
	screen.addstr(1, 15, "Type i to input, q to quit", curses.A_BOLD)
	# add horizontal line
	screen.hline(2, 1, curses.ACS_HLINE, 77)
	# Draw prompt
	screen.addstr(5, 4, "           Enter your name:", curses.A_BOLD)
	

    # Enter loop
	while 1==1:
		c = screen.getch()
		if c in (ord('q'), ord('Q')): break
		if c in (ord('i'), ord('I')): 
			curses.echo()
			screen.addstr(5,33, " "*43, curses.A_UNDERLINE)
			name = screen.getstr(5,33)
			curses.noecho()
			screen.addstr(10, 16, "Welcome to Ubuntu,", curses.A_NORMAL)
			screen.addstr(10, 36, name, curses.A_BOLD)
		screen.refresh()
		continue
    



if __name__=='__main__':
	try:
		# Initialization
		stdscr=curses.initscr()
		# echo off and key buffering off
		curses.noecho() ; curses.cbreak()
		# call main
		main(stdscr)
		# Set term defaults after loop broken
		stdscr.keypad(0)
		curses.echo() ; curses.nocbreak()
		# Terminate curses
		curses.endwin()
	except:
		# In the event of an error, restore the terminal
		# to a sane state.
		stdscr.keypad(0)
		curses.echo() ; curses.nocbreak()
		curses.endwin()
		traceback.print_exc()           # Print the exception
Copy to a file (ex: file.py) and run with:

$ python file.py
__________________
for beer in $(ls /home/fridge); do
drink $beer
done
s1ightcrazed is offline   Reply With Quote