def display_suggestion(msg): global old_matches matches = [] if not msg or not msg.strip(): if old_matches != matches: W.gotoxy(0, C.height - 2) W.clreol() old_matches = matches return msg = msg.split()[0] for command in commands: if command.command.startswith(msg) and not command.hide: matches.append(command) if matches: #limit our match count matches = matches[:5] if old_matches != matches: old_matches = matches W.gotoxy(0, C.height - 2) W.clreol() targetwidth = C.width / len(matches) W.textcolor(W.DARKGREY) for command in matches: W.cputs(('%s (%s)' % (command.command, format_time(command.time, command.time_variable))).center(targetwidth)) return matches
def _erase(self): self.written_x = 0 sys.stdout.write ("\r") if self.OS != 'nt': sys.stdout.write ("\x1b[0K") else: WConio.clreol()
def _erase(self): self.written_x = 0 sys.stdout.write("\r") if self.OS != 'nt': sys.stdout.write("\x1b[0K") else: WConio.clreol()
def restore(): ''' Keep the terminal usable. Always performed on exit. ''' W.clreol() W.textattr(defaultcolor) W.setcursortype(1)
def status(self, y, s): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - wc.gotoxy(0, y) wc.movetext(0, y, self.ex, self.ey -1, 0, y+1) wc.gotoxy(0, y) wc.textbackground(7) wc.textcolor(15) wc.clreol() wc.cputs(s)
def status(self, y, s): #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - wc.gotoxy(0, y) wc.movetext(0, y, self.ex, self.ey - 1, 0, y + 1) wc.gotoxy(0, y) wc.textbackground(7) wc.textcolor(15) wc.clreol() wc.cputs(s)
def limpialinea(): sys.stdout.write ("\r") if OS!='nt': sys.stdout.write ("\x1b[0K") else: WConio.clreol()
def delete_line(self): if os.name != 'nt': sys.stdout.write("\r" + Term.delete) else: WConio.clreol()
def get_input(): buf = [] while True: msg = ''.join(buf) matches = display_suggestion(msg) W.gotoxy(0, C.height - 1) W.clreol() W.textcolor(W.GREEN) W.cputs(game.state.current_node.command_prompt + '$ '), W.textcolor(W.LIGHTGREEN) W.cputs(msg) if matches and len(matches) == 1: #show the argument help text match = matches[0] x = W.wherex() W.textcolor(W.DARKGREY) splitted = match.arguments.split() splitted = splitted[max(0, len(msg.split())-2):] W.cputs(' ' + ' '.join(splitted)) W.textcolor(W.LIGHTGREEN) W.gotoxy(x, C.height - 1) else: match = None #Read input W.setcursortype(1) (chn, chs) = W.getch() W.setcursortype(0) #figure out if we're done if chs == '\r': #enter, exit break if chn == 8: #backspace if len(buf): buf.pop() else: MessageBeep() continue if chn == 3: log.debug('took a ctrl-c') game.fire('specialkey', 'ctrlc') break if chn == 0 or chn == 224: #special keys come in two parts (chn2, _) = W.getch() if chn2 in W.__keydict: game.fire('specialkey', W.__keydict[chn2]) continue if len(buf) >= C.width: #way too long now break if chs not in string.printable: #dont care continue buf.append(chs) return buf, match
def limpialinea(): sys.stdout.write("\r") if OS != 'nt': sys.stdout.write("\x1b[0K") else: WConio.clreol()
logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) import sys import os if 'nt' not in os.name: import XConio import curses import game game.start = curses.wrapper(game.start) import WConio as W defaultcolor = W.gettextinfo()[4] import game try: game.start() except game.GameShutdown: W.textmode() pass except KeyboardInterrupt: W.textmode() raise except: raise finally: logger.debug("Shutting down") logging.shutdown() W.clreol() W.textattr(defaultcolor) W.setcursortype(1)
def clearLines(): for i in range (21,24): WConio.gotoxy(0,i) WConio.clreol()