Commit 4398d058 authored by stettberger's avatar stettberger

Buddylist with color ( in stiis )

parent acad1058
......@@ -45,7 +45,6 @@ void refresh_buddylist() {
if(!buddy_conns[i])
continue;
write(buddy_conns[i], "update\n", 7);
DEBUG("Refresh");
}
}
......
......@@ -15,7 +15,10 @@ class BuddyList:
except:
self.socket=None
def has_data(self):
(iwtd, owtd, ewtd)=select.select([self.socket],[],[],0.05)
try:
(iwtd, owtd, ewtd)=select.select([self.socket],[],[],0.05)
except:
return False
if len(iwtd)==0:
return False
return True
......@@ -34,9 +37,8 @@ class BuddyList:
class DeMultiplexer:
def __init__(self, prefix="%s/irc"%os.environ['HOME']):
self.scr = curses.initscr()
curses.noecho()
self.servers=[]
self.scr=None
self.buddylist=[]
for i in os.walk(prefix):
if "buddylist" in i[2]:
......@@ -44,7 +46,14 @@ class DeMultiplexer:
if server.socket==None:
continue
self.servers.append(server)
self.refresh()
def init_curses(self):
self.scr = curses.initscr()
curses.start_color()
curses.noecho()
curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLACK)
self.scr.attron(curses.A_BOLD)
def refresh(self):
self.buddylist=[]
for i in self.servers:
......@@ -52,14 +61,28 @@ class DeMultiplexer:
self.buddylist.append(x)
self.scr.clear()
for i in self.buddylist:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]))
if "D" in i[0]:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(3))
elif "G" in i[0]:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(3) | curses.A_BOLD)
elif "I" in i[0]:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(2) | curses.A_BOLD)
else:
self.scr.addstr("[%s] %s\n"%(i[0], i[1]), curses.color_pair(1) | curses.A_BOLD)
self.scr.refresh()
def run(self):
while True:
for i in self.servers:
if i.has_data():
if i.read() == "update":
self.refresh()
self.init_curses()
self.refresh()
try:
while True:
for i in self.servers:
if i.has_data():
if i.read() == "update":
self.refresh()
time.sleep(1)
except:
curses.endwin()
fd=DeMultiplexer()
fd.run()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment