Tuesday, 10 September 2013

python curses program asking for terminal type

python curses program asking for terminal type

I tried to run this program
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from time import sleep
from os import system
import curses
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
screen.keypad(1)
curses.init_pair(1,curses.COLOR_BLACK, curses.COLOR_WHITE)
h = curses.color_pair(1)
n = curses.A_NORMAL
MENU = "menu"
COMMAND = "command"
EXITMENU = "exitmenu"
menu_data = {
'title': "T Manager", 'type': MENU, 'subtitle': "Please select an
option...",
'options':[
{ 'title': "Status", 'type': COMMAND, 'command': 'ls' },
{ 'title': "Space", 'type': COMMAND, 'command': 'df -h' },
{ 'title': "Ctrl", 'type': MENU, 'subtitle': "Please an
option!",
'options': [
{ 'title': "where", 'type' : COMMAND, 'command':
'pwd' },
{ 'title': "credential", 'type' : COMMAND, 'command':
'uname -a'},
{ 'title': "who", 'type' : COMMAND, 'command': 'id' },
{ 'title': "Echo", 'type' : COMMAND, 'command': 'echo
$PATH$'},
]
},
{ 'title': "Clear SCR", 'type': COMMAND, 'command': 'clear' },
]
}
def runmenu(menu, parent):
if parent is None:
lastoption = "Exit"
else:
lastoption = "Return to %s menu" % parent['title']
optioncount = len(menu['options'])
pos=0
oldpos=None
x = None
while x !=ord('\n'):
if pos != oldpos:
oldpos = pos
screen.border(0)
screen.addstr(2,2, menu['title'], curses.A_STANDOUT)
screen.addstr(4,2, menu['subtitle'], curses.A_BOLD)
for index in range(optioncount):
textstyle = n
if pos==index:
textstyle = h
screen.addstr(5+index,4, "%d - %s" % (index+1,
menu['options'][index]['title']), textstyle)
textstyle = n
if pos==optioncount:
textstyle = h
screen.addstr(5+optioncount,4, "%d - %s" % (optioncount+1,
lastoption), textstyle)
screen.refresh()
x = screen.getch() # Gets user input
if x >= ord('1') and x <= ord(str(optioncount+1)):
pos = x - ord('0') - 1
elif x == 258:
if pos < optioncount:
pos += 1
else: pos = 0
elif x == 259:
if pos > 0:
pos += -1
else: pos = optioncount
return pos
def processmenu(menu, parent=None):
optioncount = len(menu['options'])
exitmenu = False
while not exitmenu:
getin = runmenu(menu, parent)
if getin == optioncount:
exitmenu = True
elif menu['options'][getin]['type'] == COMMAND:
curses.def_prog_mode()
system('reset')
screen.clear()
print '\n'
system(menu['options'][getin]['command'])
screen.clear()
curses.reset_prog_mode()
curses.curs_set(1)
curses.curs_set(0)
elif menu['options'][getin]['type'] == MENU:
screen.clear()
processmenu(menu['options'][getin], menu)
screen.clear() pos
elif menu['options'][getin]['type'] == EXITMENU:
exitmenu = True
processmenu(menu_data)
curses.endwin()
system('clear')
And I'm gettin this error:
menureset: unknown terminal type xterm „  Terminal type?
My terminal is xterm and I'm running the program on a RHEL
$ echo $TERM xterm
There is something to do to fix it?

No comments:

Post a Comment