def run(self, screen): """""" self.screen = screen self.screen.nodelay(1) try: curses.curs_set(0) except: logger.warning("Could not hide the cursor") #set default screen self.status_pad = curses.newpad(STATUS_LINES, WIDTH) self.main_pad = curses.newpad(DOWNLOAD_LINES, WIDTH) self.log_pad = curses.newpad(LOG_LINES, WIDTH) #load links file self.th = threading.Thread(group=None, target=self.load_links, name=None) self.th.start() while self.running: self.win_height, self.win_chars = self.screen.getmaxyx() self.parse_input() try: log_len = self.update_main() self.update_log(log_len) except curses.error, e: logger.warning(e) else: curses.doupdate() time.sleep(0.5)
def post_resize(self, w, h): super().post_resize(w, h) self.grouppad = curses.newpad(MAX_ENTITIES * 2, self.cols - 4) self.cuepad = curses.newpad(MAX_ENTITIES * 2, self.cols - 4) self.mode() if hasattr(self, "groups"): self.refresh(self.screen.mode+"s")
def main_curses(stdscr, lines, d): curses.curs_set(0) curses.init_pair(1, 251, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_YELLOW) # change color curses.init_pair(3, 238, curses.COLOR_BLACK) curses.init_pair(4, 237, curses.COLOR_BLACK) offset = (0, 0) table = TableView(lines, d) table_pad = curses.newpad(table.height + 1, table.width) # TODO: Get width of output pad from column offsets output_pad = curses.newpad(table.height * table.column_number + 1, table.width) draw(stdscr, table_pad, output_pad, offset, table) while True: c = stdscr.getch() if c == ord('q'): return elif c in TableView.DIRECTIONS.keys(): di, dj = TableView.DIRECTIONS[c] table.move(di, dj) elif c == ord(' '): table.toggle_select() elif c == ord('d'): table.clear_selection() elif c == ord('c'): table.select_column() elif c == ord('\n') or c == curses.KEY_ENTER: print('<enter> => print and copy selected cells') return process_output(table) offset = draw(stdscr, table_pad, output_pad, offset, table)
def main(self, stdscr, opts): """ Method to be wrapped by curses.wrapper() for selecting chunks. """ signal.signal(signal.SIGWINCH, self.sigwinchHandler) self.stdscr = stdscr self.yScreenSize, self.xScreenSize = self.stdscr.getmaxyx() curses.start_color() curses.use_default_colors() # available colors: black, blue, cyan, green, magenta, white, yellow # init_pair(color_id, foreground_color, background_color) self.initColorPair(None, None, name="normal") self.initColorPair(curses.COLOR_WHITE, curses.COLOR_MAGENTA, name="selected") self.initColorPair(curses.COLOR_RED, None, name="deletion") self.initColorPair(curses.COLOR_GREEN, None, name="addition") self.initColorPair(curses.COLOR_WHITE, curses.COLOR_BLUE, name="legend") # newwin([height, width,] begin_y, begin_x) self.statuswin = curses.newwin(self.numTopStatusLines,0,0,0) self.statuswin.keypad(1) # interpret arrow-key, etc. ESC sequences self.bottomstatuswin = curses.newwin(self.numBottomStatusLines,0,self.yScreenSize-self.numBottomStatusLines,0) # figure out how much space to allocate for the chunk-pad which is # used for displaying the patch # stupid hack to prevent getNumLinesDisplayed from failing self.chunkpad = curses.newpad(1,self.xScreenSize) # add 1 so to account for last line text reaching end of line self.numPadLines = self.getNumLinesDisplayed(ignoreFolding=True) + 1 self.chunkpad = curses.newpad(self.numPadLines, self.xScreenSize) # initialize selecteItemEndLine (initial start-line is 0) self.selectedItemEndLine = self.getNumLinesDisplayed( self.currentSelectedItem, recurseChildren=False) self.setup(opts) while True: self.updateScreen() try: keyPressed = self.statuswin.getkey() except curses.error: keyPressed = "FOOBAR" if self.handleKey(keyPressed, opts): break curses.nocbreak() stdscr.keypad(0) curses.echo() curses.endwin() # Silly curses.wrapper does not propagate the return value opts['_returnValue'] = self.finish(opts)
def main(stdscr): curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLUE ) #curses.noecho() #curses.curs_set(0) #stdscr.clear() #stdscr.resize(50, 50) #stdscr.border(0) #x=input("...waiting..") #curses.endwin() stdscr.border(0) stdscr.refresh() stdscr_y = curses.LINES - 1 stdscr_x = curses.COLS - 1 drawCoor(stdscr) pad = curses.newpad(20, 20) pad2 = curses.newpad(20, 20) for y in range(0, 19): for x in range(0, 19): pad.addch(y,x, ord('a') + (x*x+y*y) % 26) for y in range(0, 19): for x in range(0, 19): pad2.addch(y,x, ord('-')) pad.border(0) pad2.border(0) pad2.refresh(0,0, 15,5, 65,30) pad.refresh(0,0, 5,15, 30,40) stdscr.refresh() stdscr.addstr(15, 50,"Pretty text", curses.color_pair(2)) stdscr.addstr(10, 50, "Current mode: Typing mode", curses.A_REVERSE) stdscr.addstr(10, 50, "HELLO") stdscr.refresh() stdscr.addstr(50, 50, "Enter IM message: (hit Ctrl-G to send)") rectangle(stdscr, 40,80, 60, 100) stdscr.refresh() ## Let the user edit until Ctrl-G is struck. editwin = curses.newwin(10,10, 50,90) # height, width, begin_y, begin_x stdscr.refresh() box = Textbox(editwin) box.edit()
def graphics(self, stdscr): self.stdscr = stdscr self.my, self.mx = self.stdscr.getmaxyx() self.height = 4 self.width = self.mx - 30 self.posy = int(self.my / 2.0 - self.height / 2.0) self.posx = int(self.mx / 2.0 - self.width / 2.0) self.midipad = curses.newpad(self.height, 1) self.annotationpad = curses.newpad(self.height, 1) self.com_buffer = curses.newwin(1, self.width, self.posy, self.posx) self.buf = '' self.stdscr.refresh() if annotationcorpus.exists('autosave', 'autosave'): if cgui.menu(self.stdscr, 'Annotator quit unexpectedly. Restore last session?', ['Yes', 'No']) == 0: self.load('autosave', 'autosave') while True: exp = re.compile(r'(?P<repetitions>[0-9]+)?(?P<action>[iqpsx ])$|:(?P<command>set |play|stop|pause|save|strip|subtract|q|load|score|restore)(?P<arg1>resolution|correction|beatsperbar|beatdiv)?(?P<arg2> (-)?[0-9]+)?\n$') if self.mode == self.INSERT: exp = re.compile(r'(?P<command>[ wsrge]|t(?P<arg>[0-9]+))$') # Check if the buffer contains a command m = exp.match(self.buf) if m: if not self.execute(m): break self.buf = '' self.updateScr(self.stdscr) c = self.stdscr.getch() if c == curses.ERR: continue self.status = '' if c == 27: # or c == curses.KEY_BACKSPACE: if self.mode == self.INSERT: self.mode = self.ANNOTATING self.status = 'Leaving insert mode' # Empty buffer self.buf = '' elif c == curses.KEY_BACKSPACE: # Empty buffer self.buf = '' elif c == curses.KEY_LEFT: self.curs_left() elif c == curses.KEY_RIGHT: self.curs_right() elif c == curses.KEY_UP and self.mode != self.INSERT: if self.mode == self.ANNOTATING: self.mode = self.PLAYING elif c == curses.KEY_DOWN and self.mode != self.INSERT: if self.mode == self.PLAYING: self.mode = self.ANNOTATING else: if c in range(32, 128) + [10]: self.buf += chr(c)
def initialize(self): self.topPadYX = [self.botEnd+1, self.width] self.botPadYX = [self.botEnd+1, self.width] self.topPad = curses.newpad(self.topPadYX[0], self.topPadYX[1]) # height, width self.botPad = curses.newpad(self.botPadYX[0], self.botPadYX[1]) # height, width self.window.hline(self.center, 0, curses.ACS_HLINE, self.width) self.window.move(self.topCursYX[0], self.topCursYX[1]) self.topPad.refresh(self.topScrlVH[0], self.topScrlVH[1], 0, 0, self.center-1, self.width) self.botPad.refresh(self.botScrlVH[0], self.botScrlVH[1], self.botBeg, 0, self.botEnd, self.width)
def pads(self, width): if self.pad and (self.footpad or not self.footlines) and not self.changed: return self.lns self.pad = curses.newpad(self.lines(width), width) self.render_header(width, WrapPad(self.pad)) if self.footlines: self.footpad = curses.newpad(self.footlines, width) self.render_footer(width, WrapPad(self.footpad)) return self.lns
def curses_init(self): self.stdscr = curses.initscr() curses.def_shell_mode() curses.noecho() curses.cbreak() curses.curs_set(0) self.stdscr.keypad(1) self.world_pad = curses.newpad(self.world.height+1, self.world.width) self.stats_pad = curses.newpad(self.stats_height+1, self.stats_width) self.stdscr.refresh()
def init_scr(self): self.stdscr = curses.initscr() curses.noecho() curses.curs_set(0) self.stdscr_size = self.stdscr.getmaxyx() self.task_total = count_file_linenum(self.config.seedfile) self.pgsscr_size = (self.config.proc_num + 2, 40) self.pgsscr = curses.newpad(*self.pgsscr_size) self.cntscr_size = (4, 40) self.cntscr = curses.newpad(*self.cntscr_size) self.optscr_size = (18, 80) self.optscr = curses.newpad(*self.optscr_size)
def create_room(self, room_name): rooms = self.rooms.keys() if room_name not in rooms: # create the pad to store each rooms messages room_pad = curses.newpad(self.display_pad_size_y, self.display_pad_size_x) user_pad = curses.newpad(self.display_pad_size_y, self.display_pad_size_x) num_msgs = self.MESSAGE_BASE num_users = self.USER_BASE user_pad.addstr(num_users, 0, 'me') num_users += 1 self.rooms[room_name] = (room_pad, num_msgs, user_pad, num_users) self.current_room = room_name self.draw_screen()
def refresh(self, width): story_conf = self.callbacks["get_opt"]("story") self.width = width # Make sure we actually have all of the attributes needed # to complete the render. for attr in story_conf["format_attrs"]: if attr not in self.content: self.pad = curses.newpad(1, width) self.pad.addstr("Waiting on content...") self.lines = 1 return # Do we need the relative enumerated form? rel_enumerated = self.callbacks["get_tag_opt"]("enumerated") # These are the only things that affect the drawing # of this item. state = { "width" : width, "abs_idx" : self.offset, "rel_idx" : self.rel_offset, "rel_enumerated" : rel_enumerated, "enumerated" : story_conf["enumerated"], "state" : self.content["canto-state"][:], "selected" : self.selected, "marked" : self.marked, "fstring" : story_conf["format"] } # Render once to a FakePad (no IO) to determine the correct # amount of lines. Force this to entirely unenumerated because # we don't want the enumerated content to take any more lines # than the unenumerated. Render will truncate smartly if we # attempt to go over. This avoids insane amounts of line shifting # when enumerating items and allows us to get the perfect size # for this story's pad. unenum_state = state.copy() unenum_state["enumerated"] = False unenum_state["rel_enumerated"] = False lines = self.render(FakePad(width), unenum_state) # Create the new pad and actually do the render. self.pad = curses.newpad(lines, width) self.render(WrapPad(self.pad), state) self.lines = lines self.changed = False
def _init_screen(self): self.scr = curses.initscr() self.y, self.x = self.scr.getmaxyx() # hide cursor curses.curs_set(0) self.scr.keypad(1) curses.noecho() # instant key input curses.cbreak() self.hpad = curses.newpad(1, self.x) self.pad_y = self.irq_count + 7 self.pad = curses.newpad(self._get_height(), self.x) #self._fit_size() self._set_header()
def __init__(self, quadricopter, refreshtime=0.2): threading.Thread.__init__(self) self.logger = logging.getLogger('myQ.display') self.myQ = quadricopter self.cycling = True self.screen = curses.initscr() self.logQ = curses.newpad(3, 81) self.padQ = curses.newpad(11, 81) self.padModeQ = curses.newpad(11, 81) self.refreshtime = refreshtime self.paused = False self.currentMode = -1 self.firstcycle = True
def _setup_curses(self, screen): curses.curs_set(0) curses.init_pair(1, 251, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_YELLOW) curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(4, 237, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_WHITE, curses.COLOR_RED) curses.init_pair(6, curses.COLOR_WHITE, curses.COLOR_BLUE) curses.init_pair(7, 240, curses.COLOR_BLACK) self.screen = screen self.table_pad = curses.newpad(self._table.height + 1, self._table.width) # Have to account for header size (width and height) # TODO: Remove hard-coded 50 value self.output_pad = curses.newpad(self._table.ncells + 2, max(self._table.width, 50))
def __init__(self, stdscr): screenSize = stdscr.getmaxyx() self.screenLines = screenSize[0] - 8 self.screenCols = screenSize[1] self.linePos = 0 self.colPos = 0 self.pad = curses.newpad(1, 1)
def manage_curses_display(stdscr, msg_queue, msg_queue_lock, nthreads=1): curses.curs_set(0) base_pad = curses.newpad(1000, 500) base_pad.timeout(0) header = base_pad.subpad(2, MAX_NCOL, 1, 1) thread_data_windows = [] thread_data_windows.append( base_pad.subpad(1, MAX_NCOL, 3, 1) ) thread_data_windows[-1].insstr( 0, 0, "Thread 0:".ljust(11) ) for i in xrange(nthreads): thread_data_windows.append( base_pad.subpad(1, MAX_NCOL, 3+i+1, 1)) thread_data_windows[i+1].insstr(0, 0, ("Thread %i:" % (i+1)).ljust(11)) base_pad.addstr(nthreads+2+2+1, 1, "Log:" ) nrow, ncol = stdscr.getmaxyx() log_border = base_pad.subpad( N_LOG_ROWS+2, min(ncol, MAX_NCOL), nthreads+2+2+2, 1) log_border.border() log = log_border.subpad( N_LOG_ROWS, min(ncol, MAX_NCOL)-2, 1, 1) header.addstr(0, 0, "GRIT (version %s)" % grit.__version__ ) while True: start_time = time.time() while True: # make sure that we refresh at least every 10 messages counter = 0 # make sure that we refresh every one in a while if start_time - time.time() > MAX_REFRESH_TIME: break # try to acquire a message. If none exists, brak # to refresh and sleep try: thread_index, do_log, msg = msg_queue.pop() except IndexError, inst: break except IOError, inst: break # if the message is BREAK, then we are done so exit the thread if msg == 'BREAK': return if do_log: log.insertln() log.insstr( msg ) # truncate the message so that it doesnt extend past 80 charcters msg = msg[:MAX_NCOL-11] if thread_index != None: line = ("Thread %i:" % (thread_index)).ljust(11) \ + msg.ljust(MAX_NCOL-11) thread_data_windows[thread_index].erase() thread_data_windows[thread_index].insstr(0, 0, line ) counter += 1 if counter >= 10: break
def _create_screen(self): try: if self.lines_were_auto_set: self.lines = None if self.cols_were_auto_set: self.columns = None except: pass if not self.lines: self.lines = self._max_physical()[0] + 1 self.lines_were_auto_set = True if not self.columns: self.columns = self._max_physical()[1] + 1 self.cols_were_auto_set = True if self.min_l > self.lines: self.lines = self.min_l if self.min_c > self.columns: self.columns = self.min_c #self.area = curses.newpad(self.lines, self.columns) self.curses_pad = curses.newpad(self.lines, self.columns) #self.max_y, self.max_x = self.lines, self.columns self.max_y, self.max_x = self.curses_pad.getmaxyx()
def __init__(self, y_start, x_start, width, max_length, commands=None, prompt=":"): """ The constructor. :param y_start: The vertical start position of the command line. :param x_start: The horizontal start position of the command line. :param width: The width of the command line. :param max_length: The maximum allowed length of input (may be longer than the width of the CLI). :param commands: A TurboLineCmd object which contains the commands. If no object is provided autocompletion is disabled. :param prompt: The prompt to show on input (colon per default). """ self.prompt = prompt self.__prompt_window = curses.newwin(1, width, y_start, x_start) self.__prompt_window.refresh() self.__visibility_info = TurboLineVisibilityInfo(0, 0, y_start, x_start + len(prompt), y_start, x_start + width) self.y_start = y_start self.x_start = x_start self.__text_box_window = curses.newpad(1, max_length) self.__text_box = TurboLineTextbox(self.__text_box_window, self.__visibility_info) self.validator = TurboLineValidator(self.__text_box_window, self.__text_box) self.__commands = commands if self.__commands is not None: assert isinstance(commands, cmd.Cmd) self.__commands.set_turboline(self) self.validator.set_commands(commands)
def pads(self, width): if self.pad and not self.changed: return self.lns self.pad = curses.newpad(self.lines(width), width) self.render(WrapPad(self.pad), width) return self.lns
def __init__(self, height, width, pos): self.pos = pos self.pad = curses.newpad(height, width) self.pad.border() self.pad.addstr(0, 2, "Input / Output", curses.A_BOLD) self.pad.addstr(9, 3, "Press i or o key to switch In / Out") self.reset()
def main( scr ): prevul_total, prevul_mtc, prevul_star = None, None, None prevdl_total, prevdl_mtc, prevdl_star = [], [], [] curses.init_pair( 1, curses.COLOR_GREEN, curses.COLOR_BLACK ) curses.init_pair( 2, curses.COLOR_YELLOW, curses.COLOR_BLACK ) curses.init_pair( 3, curses.COLOR_RED, curses.COLOR_BLACK ) speedWnd = curses.newpad( 10, 110 ) while True: dl_total = parseTable( getoutput( 'iptables -xnvL count_in | tail -n+3' ).split( '\n' ), False ) dl_mtc = parseTable( getoutput( 'iptables -xnvL count_mtc_in | tail -n+3' ).split( '\n' ), False ) #dl_star = parseTable( getoutput( 'iptables -xnvL count_star_in | tail -n+3' ).split( '\n' ), False ) ul_total = parseTable( getoutput( 'iptables -xnvL count_out | tail -n+3' ).split( '\n' ) ) ul_mtc = parseTable( getoutput( 'iptables -xnvL count_mtc_out | tail -n+3' ).split( '\n' ) ) #ul_star = parseTable( getoutput( 'iptables -xnvL count_star_out | tail -n+3' ).split( '\n' ) ) printTable( speedWnd, ( 'D/total', dl_total, prevdl_total, 4000 ), ( 'U/total', ul_total, prevul_total, 3100 ), ( 'D/mtc', dl_mtc, prevdl_mtc, 2000 ), ( 'U/mtc', ul_mtc, prevul_mtc, 100 ), # ( 'D/star', dl_star, prevdl_star, 3000 ), # ( 'U/star', ul_star, prevul_star, 3000 ) ) prevdl_total, prevul_total = dl_total, ul_total prevdl_mtc, prevul_mtc = dl_mtc, ul_mtc # prevdl_star, prevul_star = dl_star, ul_star scr.erase() scr.refresh() ( sh, sw ) = scr.getmaxyx() ( h, w ) = speedWnd.getmaxyx() try: speedWnd.refresh( 0, 0, 0, 0, min( h, sh ) - 1, min( w, sw ) - 1 ) except curses.error: pass for i in xrange( 10 ): curses.napms( 100 )
def __init__(self, height, width, pos): self.pos = pos self.size = [ height, width ] self.pad = curses.newpad(height, width) self.pad.border() self.pad.addstr(0, 2, "Info", curses.A_BOLD) self.pad.addstr(1, 3, "Running on RaspiO'Mix" + ("+ Oh yeah ! ;)" if IS_PLUS else '') + "...")
def __init__(self, height, width, pos): self.pos = pos self.pad = curses.newpad(height, width) self.pad.border() self.pad.addstr(0, 2, "Serial", curses.A_BOLD) self.ser = serial.Serial(Raspiomix.DEVICE, 9600, timeout = 0.1)
def _initDialog(self, height, width, buttons=('OK',), caption=None): self._dialogpad = curses.newpad(height, width) self._dialogpad.bkgd(0x94, curses.color_pair(self.COLOR_HEADER_HI)) self._dialogpad.clear() self._dialogpad.box() if caption: lh = (width / 2) - (len(caption) / 2) - 1 self._dialogpad.addstr(0, lh, ' {0} '.format(caption), curses.color_pair(self.COLOR_NORMAL) | curses.A_STANDOUT) if buttons: if len(buttons) > 1: bwid = 0 for bcap in buttons: if len(bcap) > bwid: bwid = len(bcap) cellwid = (width - 4) / len(buttons) lpad = (cellwid - bwid) / 2 - 1 rpad = cellwid - bwid - lpad - 1 self._dialogpad.move(height - 2, 1) else: bwid = len(buttons[0]) lpad = rpad = 1 self._dialogpad.move(height - 2, (width / 2) - (bwid / 2) - 2) for button in buttons: self._dialogpad.addstr('{0:{wlpad}}<{1:^{wbwid}}>{0:{wrpad}}'.format('',button, wlpad=lpad, wbwid=bwid, wrpad=rpad)) dt = (self._screensize[0] / 2) - (height / 2) dl = (self._screensize[1] / 2) - (width / 2) dc = padcoords(sminrow=dt,smincol=dl,smaxrow=dt+height - 1, smaxcol=dl+width - 1) self._dialogcoords = dc self._dialogpad.overlay(self._screen, 0, 0, dc.sminrow, dc.smincol, dc.smaxrow, dc.smaxcol) self._screen.refresh()
def __init__(self): # Initialisation de curses self.init_curse() # Connexion a la BD self.db = DBAccess() # Initialisation des fenetres dims = self.stdscr.getmaxyx() dims = (max(dims[Y], MIN_HEIGHT), max(dims[X], MIN_WIDTH)) h = dims[Y]/2 w = dims[X]/2 hProcs = max(MIN_HEIGHT_PROCS, h) self.pad = curses.newpad(h + hProcs, w*2) self.menu = WindowMenu(self, self.pad, h, w, 0, 0, self.db) self.stats = WindowStats(self, self.pad, h, w, 0, w, self.db) self.procs = WindowProcess(self, self.pad, hProcs - HEIGHT_FOOT, w*2, h, 0, self.db) self.windows = [self.menu, self.stats, self.procs] self.focus_windows = [self.menu, self.stats] # Focus de la fenetre principale self.focused = 0 # Initialisation du menu self.menu.focus()
def trackview(stdscr, tracks, width=40, ypos=5, xpos=5, scale=10): height = len(tracks) + 1 length = max([t.length() for t in tracks]) length /= 1000000.0 viewwidth = int(math.ceil(length * scale)) view = curses.newpad(height, viewwidth+1) win = curses.newwin(height, 8, ypos, xpos) win.addstr(0, 0, 'time (s)') for i in range(len(tracks)): win.addstr(i+1, 0, '#{0}'.format(tracks[i].n)) # status.addstr(height - 1, 0, 'Time:{0}\tTime left: {1}\tScale: {2}'.format(0, 0, scale)) trackrolls = {} data = {} for i in range(len(tracks)): positions = {} for j in range(len(tracks[i])): on = tracks[i].midifile.ticks_to_microseconds(tracks[i][j].on) pos = int(math.floor((on / 1000000.0)*scale)) positions[str(pos)] = 1 data[str(tracks[i].n)] = positions roll = ['-'] * viewwidth for posstr in positions.keys(): roll[int(posstr)] = 'o' rollstr = ''.join(roll) trackrolls[str(tracks[i].n)] = rollstr view.addstr(i+1, 0, rollstr) return(data, win, view)
def main(scr): curses.curs_set(False) curses.start_color() for i in range(1, 16): curses.init_pair(i, i, curses.COLOR_BLACK) scry, scrx = scr.getmaxyx() pady = scry * 2 padx = scrx * 2 pad = curses.newpad(pady, padx) pad.nodelay(True) mandel(pad) oy = 1 ox = 0 while True: pad.refresh(oy, ox, 0, 0, scry-1, scrx-1) key = pad.getch() if key in (ord('q'), ord('Q')): break elif key in (ord('w'), curses.KEY_UP): oy = max(oy - 1, 0) elif key in (ord('s'), curses.KEY_DOWN): oy = min(oy + 1, pady - scry - 1) elif key in (ord('a'), curses.KEY_LEFT): ox = max(ox - 2, 0) elif key in (ord('d'), curses.KEY_RIGHT): ox = min(ox + 2, padx - scrx) elif key == curses.KEY_RESIZE: scry, scrx = scr.getmaxyx()
def run(self): self.calculate_dimensions() self.windowH = curses.LINES self.windowW = curses.COLS self.title_window = curses.newwin(1,0,0,0) self.nav_window = curses.newwin(self.nlines, self.ncols, self.nyval, self.nxval) #Create the pad window self.data_window = curses.newpad(BUFFER_SIZE, self.dcols) self.data_window.keypad(1) self.data_window.timeout(100) #100 ms self.update_title() self.update_windows() counter = time.time() #self.started = True while not self.stopped: c = self.data_window.getch() self.check_resize_ui() #Update every 1 seconds newtime = time.time() if newtime - counter >= 1 : counter = newtime if self.__current_panel__().autoscroll: self.scroll_end() #check to see if window has been resized if not self.check_resize_ui(): self.update_windows() if not self.handle_input(c): break
def __init__(self, console_height, console_width, game_height, game_width, conway): """Initialize ConwayScreen. :param console_height: the height of the console :param console_width: the width of the console :param game_height: the height of the game :param game_width: the width of the game :param conway: a Conway graph :return: null """ self.conway = conway self.game_pad = curses.newpad(game_height, game_width) # Start and stop points for the graph [start, stop). self.start_y, self.start_x = util.center_start(console_height, console_width, game_height, game_width) # Stop points are a function based on the start. self.stop_y, self.stop_x = self.start_y + game_height, self.start_x + game_width # Initializes pause window for use in pause(). pause_height, pause_width = 8, 50 pause_y, pause_x = util.center_start(console_height, console_width, pause_height, pause_width) self.pause_window = curses.newwin(pause_height, pause_width, pause_y, pause_x) # Surround Conway graph with a box util.color_box(self.game_pad, 0, 0, game_height, game_width, 0)
def __init__(self, screen=1): self.lock = False self.std_scr = curses.initscr() self.screen_initialize() term_size = shutil.get_terminal_size() self.term_width = term_size.columns self.term_height = term_size.lines self.screen = screen self.output_scr = [] self.output_pos = [] for i in range(screen): if i == screen - 1: self.output_scr.append( curses.newpad(self.term_height - 1, int(self.term_width / screen) + screen % 2)) else: self.output_scr.append( curses.newpad(self.term_height - 1, int(self.term_width / screen))) self.output_pos.append([0, 0]) self.output_scr[i].scrollok(1) self.refresh(screen=i) self.input_scr = curses.newpad(1, self.term_width)
def render_summary(outer_window, h, w, thread_cm, total_switch, cmetric_reports, post_time, futex_events, filenames): text_size_window = curses.newpad(5000, w - 4) render_summary_text(text_size_window, w - 4, thread_cm, total_switch, cmetric_reports, post_time, futex_events, filenames) (window_height_inner, _) = text_size_window.getyx() window_height_inner += 1 border_window = outer_window.derwin(window_height_inner + 4, w, 0, 0) border_window.border() window = border_window.derwin(window_height_inner, w - 4, 2, 2) render_summary_text(window, w - 4, thread_cm, total_switch, cmetric_reports, post_time, futex_events, filenames) return window_height_inner + 4
def _main_loop(self, scr): if scr is not None: CursesMenu.stdscr = scr self.screen = curses.newpad( len(self.items) + 6, CursesMenu.stdscr.getmaxyx()[1]) self._set_up_colors() curses.curs_set(0) CursesMenu.stdscr.refresh() self.draw() CursesMenu.currently_active_menu = self self._running.set() while self._running.wait() is not False and not self.should_exit: self.process_user_input()
def __init__(self, n_row, current_annotator, csv_file, pad=None, log="data/log.txt"): if pad is None: pad = [0, 1, 0, 0, 9, 200] self.pad = pad self.progress_pad = curses.newpad(pad[4], pad[5]) self.n_row = n_row self.current_annotator = current_annotator self.file_names = csv_file.iloc[:, 0]
def meta(stdscr, ebook): rows, cols = stdscr.getmaxyx() hi, wi = rows - 4, cols - 4 Y, X = 2, 2 meta = curses.newwin(hi, wi, Y, X) meta.box() meta.keypad(True) meta.addstr(1, 2, "Metadata") meta.addstr(2, 2, "--------") key_meta = 0 mdata = [] for i in ebook.get_meta(): data = re.sub("<[^>]*>", "", i[1]) data = re.sub("\t", "", data) mdata += textwrap.fill(i[0].upper() + ": " + data, wi - 6).splitlines() src_lines = mdata totlines = len(src_lines) pad = curses.newpad(totlines, wi - 2) pad.keypad(True) for n, i in enumerate(src_lines): pad.addstr(n, 0, i) y = 0 meta.refresh() pad.refresh(y, 0, Y + 4, X + 4, rows - 5, cols - 6) padhi = rows - 5 - Y - 4 + 1 while key_meta != META and key_meta not in QUIT: if key_meta in SCROLL_UP and y > 0: y -= 1 elif key_meta in SCROLL_DOWN and y < totlines - hi + 6: y += 1 elif key_meta in PAGE_UP: y = pgup(y, padhi) elif key_meta in PAGE_DOWN: y = pgdn(y, totlines, padhi) elif key_meta in CH_HOME: y = 0 elif key_meta in CH_END: y = pgend(totlines, padhi) elif key_meta == curses.KEY_RESIZE: return key_meta pad.refresh(y, 0, 6, 5, rows - 5, cols - 5) key_meta = meta.getch() meta.clear() meta.refresh() return
def setup(self, vault): """ Setup ncurses and render to the screen. """ self._screen = curses.initscr() curses.start_color() curses.noecho() self._screen.keypad(1) curses.curs_set(0) self._vault = vault max_lines = vault.max_item_count() self._header = self._screen.subwin(2, curses.COLS, 0, 0) self._body = curses.newpad(max_lines, curses.COLS) self._screen.untouchwin()
def show(self): self.screen.refresh() h, w = self.screen.getmaxyx() self.pad = curses.newpad( len(self.visible_processes) if self.visible_processes else 1, w) for i, p in enumerate(self.visible_processes): if p.is_running(): self.print_process(p, i) self.pad.refresh(self.page_scroll_offset, 0, 0, 0, h - 1 - 1, w - 1) self.status.draw( f'{self.current_process_index + 1}/{len(self.visible_processes)}')
def __init__(self, name, y, x, size, label, parent, default=""): super(self.__class__, self).__init__(name, y, x, label, parent) # Call the init method of the base class self.fieldSize = size self.default = default self.text = default if len(self.text) > self.fieldSize: self.text = self.text[:self.fieldSize] self.type = "t" # self.swin = self.win.subwin(1, self.fieldSize+1, self.posY, self.posX + 3 + len(self.label)) #nlines, ncols, begin_y, begin_x self.swin = curses.newpad(1, 1024) #nlines, ncols, begin_y, begin_x self.swin.addstr(0, 0, self.text) self.tb = _Textbox(self.swin) #, insert_mode=True
def __init__(self, stdscr): self.stdscr = stdscr curses.curs_set(0) stdscr.timeout(0) self.char = '▓' self.limit = 1000 self.height, self.width = stdscr.getmaxyx() self.pad = curses.newpad(self.height+1, self.width+1) curses.init_pair(1, 1, 1) stdscr.clear() data = ping_stream(['ping', '-t', *(sys.argv[1:] or ['www.google.com'])]) # test data: #data = [f'time={t}ms' for t in range(0,1501, 100)]; data.insert(6, 'timed out') self.process(data)
def t(): pad = curses.newpad(10, 10) # These loops fill the pad with letters; this is # explained in the next section for y in range(0, 100): for x in range(0, 100): try: pad.addch(y, x, ord('a') + (x * x + y * y) % 26) except curses.error: pass # Displays a section of the pad in the middle of the screen pad.refresh(0, 0, 5, 5, 20, 75)
def redraw_if_changed(self): """ Redraws the box if it has changed. """ # Re-calculate the box's size and position. height = self.grid.height(self.rows) width = self.grid.width(self.columns) x_offset = self.grid.x_offset(self.columns_offset) y_offset = self.grid.y_offset(self.rows_offset) # Only refresh the contents after waiting for the specified interval. if self.next_refresh <= datetime.now(): try: self.contents = subprocess.check_output(self.command, shell=True) except: self.contents = '\n There was a problem running this ' + \ 'window\'s command.' # Calculate the height the pad needs to be to fit the contents. lines = self.contents.splitlines() if len(lines) >= height: # Without adding 1 to height here the program crashes, but I'm # not sure why. It doesn't seem like it should be necessary. self.pad_height = len(lines) + 1 else: self.pad_height = height # Calculate the width the pad needs to be to fit the contents. self.pad_width = width for line in lines: # Add 1 to the string length to allow for end-of-line # characters. if len(line) >= self.pad_width: self.pad_width = len(line) + 1 # Set the time of the next refresh. self.next_refresh += timedelta(seconds=self.interval) # Recreate the box and set its colors. self.box = curses.newpad(self.pad_height, self.pad_width) self.box.bkgdset(ord(' '), curses.color_pair(1)) self.box.erase() self.box.addstr(self.contents) # Only refresh the box if it has changed since the last refresh. if self.box.is_wintouched(): # Subtract 1 from height and width to allow for column and row # numbering starting at 0. self.box.refresh(0, 0, y_offset, x_offset, y_offset + (height - 1), x_offset + (width - 1))
def build_interface(stdscr): global screen #TODO Why does this need to be global? (max_y, max_x) = stdscr.getmaxyx() master_pad = curses.newpad(max_y, max_x) #screen_topleft = curses.newwin(max_y/2, max_x/2, 0, 0) #screen_topleft.addstr(0, 2, "Client List") #declare some commonly used string graphics hline_break = '-' * (max_x / 2) hline = " ----- ----- ----- " vline = "| ' ' ' | ' ' ' | ' ' ' |" usg_msg = "Use arrow keys to move.\n 1-9 are valid entries.\n Use 0 to reset a value.\n Options: [d]one, [q]uit" sure_msg = "Are you sure? (y/n): " another_msg = "Try another? (y/n): " ''' for y in xrange(1,14): if ((y-1)%4 == 0): screen.addstr(y, 1, hline) else: screen.addstr(y, 1, vline) ''' #add necessary strings to screen screen_topleft.addstr(1, 0, hline_break) #screen_topleft.addstr((max_y/2)-1,0, usg_msg) screen_topleft.move(2, 3) #screen.box() #screen.hline() screen_topleft.refresh() #screen.nodelay(1) while True: c = screen_topleft.getch() (y, x) = screen_topleft.getyx() #screen.addstr(0,0, str(c)) if c == ord('d') or c == ord('q'): screen_topleft.addstr(19, 2, sure_msg) screen_topleft.refresh() ans = screen_topleft.getch() if ans != ord('y'): screen_topleft.move(19, 0) screen_topleft.clrtoeol() screen_topleft.move(y, x) #move back to where the cursor was else: if c == 'q': #quit signal received, break out of the while loop #break return
def __init__(self, screen, maxrows=1000, top=1, left=0, height=None, width=None, footer=False): if footer: nfooterlines = 1 else: nfooterlines = 0 self.parent = screen self.top, self.left = top+1, left self._height = default(height, screen.getmaxyx()[0]-top)-1-nfooterlines self._width = default(width, screen.getmaxyx()[1]) self.pad = curses.newpad(maxrows, self.width) self.header = curses.newwin(1, self.width, top, left) self.cursor, self.position = 0, 0 self.rows, self.formats, self.keys = [], [], [] self.colFooters = None
def render(self): if self.height() > self.scr.getmaxyx()[0] - 1: self.scr = curses.newpad(self.height() + 1, self.width()) super().render() for y in range(self.terminal.screen.height): for x in range(self.terminal.screen.width): c = self.terminal.screen.chars[y][x] self.scr.addch(y + 2, x + 1, c) self.scr.addstr(self._height + 2, 1, '─' * (self.width() - 2)) for i, line in enumerate(self.output, 3 + self._height): if line: self.scr.addstr(i, 1, line) x, y = self.terminal.screen.cursor self.cursor = x + 1, y + 2
def Sat_List_Menu(self): mypad = curses.newpad(40, 60) mypad_pos = 0 mypad.refresh(mypad_pos, 0, 5, 5, 10, 60) while 1: cmd = mypad.getch() if cmd == curses.KEY_DOWN: mypad_pos += 1 mypad.refresh(mypad_pos, 0, 5, 5, 10, 60) elif cmd == curses.KEY_UP: mypad_pos -= 1 mypad.refresh(mypad_pos, 0, 5, 5, 10, 60) elif cmd == ord("q"): break
def __init__(self, directory=None, ext=None): if directory == None: self.directory = str(os.getcwd()) + "/" rows, cols = os.popen('stty size', 'r').read().split() self.rows = int(rows) self.cols = int(cols) self.origin = os.getcwd() self.hmarg = 3 self.vmarg = 3 self.inmarg = 3 self.outer_x = self.cols - 2 * self.hmarg self.outer_y = self.rows - 2 * self.vmarg self.pad_x = self.outer_x - 4 self.pad_y = self.outer_y - 4 self.ext = ext self.window = 0 self.lchoice = 0 # upper and lower pad choices self.lchoice2 = 0 # respectively self.rchoice = 0 self.listfiles = [] self.folders = [] self.chosen = [] self.abs_chosen = [] self.ch = '' self.show_dotfiles = False self.directory_populate() self.curses_init() self.outerbox = curses.newwin(self.rows - 2*self.vmarg, \ self.cols - 2*self.hmarg, \ self.vmarg,self.hmarg) try: self.directorypad = curses.newpad(len(self.listfiles), self.cols - 2 * self.inmarg) except: self.directorypad = curses.newpad(1, self.cols - 2 * self.inmarg) try: self.folderpad = curses.newpad(len(self.folders), self.cols - 2 * self.inmarg) except: self.folderpad = curses.newpad(1, self.cols - 2 * self.inmarg) try: self.fpad = curses.newpad(len(self.listfiles), self.cols - 2 * self.inmarg) except: self.fpad = curses.newpad(1, self.cols - 2 * self.inmarg) self.okpad = curses.newpad(1, 6) self.draw_frames() self.draw_ok() self.draw_directorypad() self.draw_folderpad() self.draw_fpad() self.mainloop()
def __init__(self, stdscreen, x, y, max_line_size_, col_size_, main_window_lines=500, refreshrate=0.7, header_line_size_=2): # the screen window self.screen = stdscreen # last update time [for now it is the creation time] self.time = time.time() # the window refresh-rate self.refreshrate = refreshrate # the number of maximal lines that will be displayed in the window at a given time self.max_line_size_ = max_line_size_ # the number of maximal chars that will be displayed in the window at a given time self.col_size_ = col_size_ # the X location of the most upper-left corner of the window self.x = x # the Y location of the most upper-left corner of the window self.y = y # generating and initializing the main data window self.window = curses.newpad(main_window_lines, self.col_size_ * 10) # generating and initializing the header window self.header_line_size_ = header_line_size_ self.hwindow = curses.newpad(self.header_line_size_, self.col_size_ * 10) # generating and initializing the bottom part of the window self.xwindow = curses.newpad(self.header_line_size_, self.col_size_ * 10) #reset the window self.clear() # Indicator if the window is active self.active = True self.id = None
def update(self, echotxt=''): self.wclear() try: self.modewin.erase() self.modewin.addstr(0, 0, self.mode.name()) self.modewin.noutrefresh() ##self.wblit(self.modewin, self.mode.name()) self.statwin.erase() self.statwin.addstr(0, 0, echotxt) self.statwin.noutrefresh() ##self.wblit(self.statwin, echotxt) self.keywin.erase() items = sorted(self.key.items(), key=lambda pair: pair[0]) for idx, pair in enumerate(items): self.keywin.addstr(0, idx, pair[0]) self.keywin.addstr(1, idx, pair[1]) self.keywin.noutrefresh() ##self.wblit(self.keywin) self.obufwin.erase() self.nbufwin.erase() self.obufwin.border() self.nbufwin.border() if self.obuf is not None: if self.nbuf is None: self.nbuf = curses.newpad(*self.obuf.getmaxyx()) self.nbuf.erase() self.nbuf.addstr(0, 0, self.getnbuf()) by, bx = self.obufwin.getbegyx() my, mx = self.obufwin.getmaxyx() self.obuf.overwrite(self.obufwin, 1 + self.scroll[0], 1 + self.scroll[1], by, bx, my, mx) ##self.obuf.overwrite(self.obufwin) ##self.obuf.refresh(self.scroll[0], self.scroll[1], by, bx, my, mx) by, bx = self.nbufwin.getbegyx() my, mx = self.nbufwin.getmaxyx() self.nbuf.overwrite(self.nbufwin, 1 + self.scroll[0], 1 + self.scroll[1], by, bx, my, mx) ##self.nbuf.overwrite(self.nbufwin) ##self.nbuf.refresh(self.scroll[0], self.scroll[1], by, bx, my, mx) self.obufwin.noutrefresh() self.nbufwin.noutrefresh() ##self.wblit(self.obufwin, self.getobuf(), self.scroll[0], self.scroll[1]) ##self.wblit(self.nbufwin, self.getnbuf(), self.scroll[0], self.scroll[1]) except Exception as e: log(traceback.format_exc()) self.statwin.erase() self.statwin.addstr(0, 0, 'Update error occurred: %r' % (e, )) self.statwin.noutrefresh() curses.doupdate()
def curses_main(args): stdscr = curses.initscr() pad_height, pad_width = stdscr.getmaxyx() pad = curses.newpad(200, 100) curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) curses.cbreak() stdscr.keypad(True) curses.noecho() curses.curs_set(0) news_list = get_articles() selected_item_number = 0 while True: pad.addstr( 0, 0, "Habrahabr RSS. (j,k - to navigate, l - to select, q - to exit)") y = 2 item_number = 0 for item in news_list: if item_number == selected_item_number: attribute = curses.color_pair(1) else: attribute = curses.color_pair(2) pad.addstr(y, 2, item.title.text, attribute) y += 2 item_number += 1 stdscr.refresh() pad.refresh(0, 0, 0, 0, pad_height - 1, pad_width - 1) c = pad.getch() if c == ord("q"): break #exit from script if c == ord("j"): selected_item_number += 1 if selected_item_number > (len(news_list) - 1): selected_item_number = 0 if c == ord("k"): selected_item_number -= 1 if selected_item_number < 0: selected_item_number = len(news_list) - 1 if c == ord("l"): webbrowser.open(news_list[selected_item_number].link.text, 2) #open a selected article in a default browser break #exit from script
def pp(list, name_list, stdscr): sorted(list) output = "" if list: for item in list: timestamp = str(datetime.fromtimestamp(item[0])) feed = item[1]['feed'] name = name_list.get(feed) content = item[1]['text'] curses.echo() output += f"({timestamp}) {name}:\t{content}\n\n" height, width = stdscr.getmaxyx() # Create a curses pad (pad size is height + 10) mypad_height = len(list) * 4 mypad = curses.newpad(mypad_height, width) mypad.scrollok(True) mypad_pos = -2 mypad_refresh = lambda: mypad.refresh(mypad_pos + 2, 0, 0, 0, height - 1, width) mypad_refresh() try: mypad.addstr(output) except: pass finally: mypad_refresh() while 1: key = stdscr.getch() if key == curses.KEY_DOWN and mypad_pos < mypad.getyx( )[0] - height - 1: mypad_pos += 1 mypad_refresh() elif key == curses.KEY_UP and mypad_pos > -2: mypad_pos -= 1 mypad_refresh() elif key == 27: # ESC print_menu(stdscr, 0) break elif key == curses.KEY_RESIZE: height, width = stdscr.getmaxyx() # while mypad_pos > mypad.getyx()[0] - height - 1: # mypad_pos -= 1 mypad.refresh(mypad_pos + 2, 0, 0, 0, height - 1, width - 1) else: scr_print(stdscr, "No logs to show")
def scrollPad(stdscr, stringInput): # Get the current size of the window and save it height, width = stdscr.getmaxyx() # Get number of newlines in a string splitInput = stringInput.split("\n") inputHeight = len(splitInput) # If the line would wrap around, add 1 to the inputheight for line in splitInput: lineLength = len(line) # Tabs are equal to 1 in len, but 8 in spaces, so add 7 to get everything back in alignment. tabNo = len(line.split("\t")) lineLength += tabNo * 7 if lineLength >= width: inputHeight += 1 # Create a new pad with maximum width and however high the string is, including a line position mypad = curses.newpad(inputHeight, width) mypad_pos = 0 mypad.addstr(stringInput) addStatus(stdscr) # For some reason the background is blank for "gapped" areas of input, this workaround resets the background # TODO: Find a cleaner way to do this so that output doesn't have to be dim. mypad.bkgd(0, curses.A_DIM) # Once all of the input is added to the pad, refresh the region (whole screen minus 2 for index and status bar. mypad.refresh(mypad_pos, 0, 0, 0, height - 2, width) # Wait for the input from the user to scroll up/down while True: cmd = mypad.getch() # Go down by one unless it's the end of the file. if cmd == ord("j") and mypad_pos < inputHeight - height + 1: mypad_pos += 1 addStatus(stdscr) mypad.refresh(mypad_pos, 0, 0, 0, height - 2, width) # Go up by one, unless we go "over the top". elif cmd == ord("k") and mypad_pos > 0: mypad_pos -= 1 addStatus(stdscr) mypad.refresh(mypad_pos, 0, 0, 0, height - 2, width) elif cmd == ord("q"): break
def __init__(self, lines, cols): self._x = 0 self._y = 0 self.view_height = lines - 5 self.view_width = cols self.pad_height = lines - 5 self.pad_width = cols self.win = curses.newpad(lines, cols) self.win.bkgdset(ord(' '), curses.color_pair(1)) self.win.insertln() self.refresh()
def __init__(self, screen, picked): curses.curs_set(0) # get rid of cursor self.screen = screen self.y, self.x = self.screen.getmaxyx() self.header = curses.newwin(0, self.x, 0, 0) self.win = curses.newwin(self.y - 3, self.x, 2, 0) self.footer = curses.newwin(0, self.x, self.y - 1, 0) self.screen.refresh() self.win.refresh() self.pad = curses.newpad(self.y, self.x) self.footer.refresh() self.header.refresh() self.picked = picked self.color = Color(self.win) self.lc, self.pos = (0, ) * 2
def draw_level(playerPos, lvlArray): pad = curses.newpad(20, 21) curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_GREEN) curses.init_pair(2, curses.COLOR_MAGENTA, curses.COLOR_MAGENTA) curses.init_pair(3, curses.COLOR_BLUE, curses.COLOR_BLUE) for x in range(0, 20): for y in range(0, 20): if lvlArray[x][y] == 1: pad.addstr(x, y, '#', curses.color_pair(1)) elif lvlArray[x][y] == 2: pad.addstr(x, y, '#', curses.color_pair(2)) elif lvlArray[x][y] == 3: pad.addstr(x, y, '#', curses.color_pair(3)) #pad.addstr(playerPos[0],playerPos[1],'@') pad.refresh(0, 0, 0, 0, 19, 20)
def iimport(self, filename): self.screen.move(0, 0) with open(filename) as f: data = f.readlines() self.height = len(data) temp_width = max([len(x) for x in data]) temp_pad = curses.newpad(self.height, temp_width) attr_gen = self.convert_to_attr() attr = next(attr_gen) line_lengths = [] y = 0 for line in data: line = line.strip("\n") length = 0 line = iter(line) temp_pad.move(y, 0) for char in line: if ord(char) == 27: code = self.grab_escape_sequence(line) attr_gen.send(code) attr = next(attr_gen) continue length += 1 try: temp_pad.addch(char, attr) except: break line_lengths.append(length) y += 1 self.width = max(line_lengths) self.screen.addstr(0, 0, str(self.width) + " ") self.canvas = curses.newpad(self.height, self.width) temp_pad.overlay(self.canvas) del temp_pad self.refresh_canvas()
def __init__(self): self.screen = curses.initscr() self.screen.keypad(1) curses.noecho() self.height, self.width = self.screen.getmaxyx() self.pad = curses.newpad(self.height, self.width) self.text = "" self.my_msg = "" self.stop = False threading._start_new_thread(self.startDrawingThread, ()) self.hintWord = "" self.levelWord = "" self.remainWord = "" self.titleWord = "" self.answers = []
def start_curses(self, stdscr): self.stdscr = stdscr curses.curs_set(0) self.maxy, self.maxx = self.stdscr.getmaxyx() self.logo = curses.newwin(self.logoy, self.logox, 0, 0) self.logo.erase() logolines = 0 for line in self.banner: logolines += 1 if logolines <= self.maxrows(): self.logo.addstr(line + "\n") self.plogo = curses.panel.new_panel(self.logo) self.text = curses.newpad(self.maxrows(), self.maxcols()) self.stdscr.refresh()
def __init__(self, screen, maxrows=20000, top=1, left=0, height=None, width=None): self.parent = screen self.top, self.left = top, left self._height = default(height, screen.getmaxyx()[0] - top) self._width = default(width, screen.getmaxyx()[1]) self.pad = curses.newpad(maxrows, self.width) self.position = 0 self.text = [] self.nrows = 0
def __init__(self, stdscr, lines): self.stdscr = stdscr self.lines = lines self.maxy, self.maxx = self.stdscr.getmaxyx() self.longest = len(max(self.lines, key=len)) self.foot = curses.newwin(0, self.maxx, self.maxy - 1, 0) self.pad = curses.newpad(len(self.lines) + 1, self.longest + 1) self.pad.keypad(True) # use function keys self.pad.idlok(True) self.pad.scrollok(True) self.pminrow = 0 # pad row to start displaying contents at self.pmincol = 0 # pad column to start displaying contents at self.matches = [] self.color = mkculor() curses.curs_set(0) # hide the cursor
def parseInput(self, key): if key == self.program.settings["BinaryNinjaContextSwitchView"]: # Clean Up if self.view == 0: del self.linearDisassemblyScreen del self.functionListScreen del self.xrefsScreen elif self.view == 1: del self.hexScreen elif self.view == 2: del self.cfgScreen del self.functionListScreen del self.xrefsScreen # Switch Contexts if self.view == 0: self.view = 1 elif self.view == 1: self.view = 2 elif self.view == 2: self.view = 0 # Setup if self.view == 0: self.updateFunctionList = True self.linearDisassemblyScreen = curses.newpad(curses.LINES-1, curses.COLS - self.program.settings["functionListScreenWidth"]) self.functionListScreen = curses.newpad(curses.LINES-1-self.program.settings["xrefsScreenHeight"], self.program.settings["functionListScreenWidth"]) self.xrefsScreen = curses.newpad(self.program.settings["xrefsScreenHeight"], self.program.settings["functionListScreenWidth"]) self.loadLinearDisassembly() elif self.view == 1: self.updateFunctionList = True self.hexScreen = curses.newpad(curses.LINES-1, curses.COLS) elif self.view == 2: self.cfgScreen = curses.newpad(curses.LINES-1, curses.COLS - self.program.settings["functionListScreenWidth"]) self.functionListScreen = curses.newpad(curses.LINES-1-self.program.settings["xrefsScreenHeight"], self.program.settings["functionListScreenWidth"]) self.xrefsScreen = curses.newpad(self.program.settings["xrefsScreenHeight"], self.program.settings["functionListScreenWidth"]) elif key == self.program.settings["BinaryNinjaContextSwitchFocus"]: if self.focus == 0: self.focus = 1 elif self.focus == 1: self.focus = 2 elif self.focus == 2: self.focus = 0 if self.view == 0: self.parseInput_linear(key) elif self.view == 1: self.parseInput_hex(key) elif self.view == 2: self.parseInput_cfg(key)