def draw_banner(): # Get terminal size and store in globals global NROWS, NCOLS NROWS, NCOLS, hp, wp = struct.unpack( 'HHHH', fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, struct.pack('HHHH', 0, 0, 0, 0))) banner_height = 15 # Make sure we have enough lines to draw banner. Inform user if not if NROWS < banner_height + 5 or NCOLS < 60: mess = 'Please make terminal ' if NROWS < banner_height + 5: mess += 'taller' if NCOLS < 60: mess += ' and wider' if NCOLS < 60: mess += 'wider' MOVETO(1, 1) CLEARLINE() sys.stdout.write(REVERESED) PRINTCENTERED(1, mess) sys.stdout.write(RESET) MOVETO(1, NROWS) sys.stdout.flush() return # Draw border/background sys.stdout.write(BACKGROUND_MAGENTA + BRIGHT_WHITE + BOLD) PRINTAT(1, 1, '-' * NCOLS) for i in range(2, banner_height): PRINTAT(1, i, '|' + ' ' * (NCOLS - 2) + '|') PRINTAT(1, banner_height, '-' * NCOLS) # Draw status PRINTAT(3, 2, 'Num. Events Processed: %d' % jana.GetNeventsProcessed()) #PRINTAT( 3, 3, ' Num. Tasks Completed: %d' % jana.GetNtasksCompleted() ) # This no longer exists PRINTAT(3, 4, ' Num. Cores: %d' % jana.GetNcores()) PRINTAT(3, 5, ' Num. JThreads: %d' % jana.GetNJThreads()) PRINTAT( NCOLS / 2, 2, 'Rate: %5.0fHz (%5.0fHz avg.)' % (jana.GetInstantaneousRate(), jana.GetIntegratedRate())) # Cursor is repositioned and stdout flushed in command_line after calling this # so no need to do it here. Just reset to default drawing options. sys.stdout.write(RESET)
def process_command( input ): global CLI_ACTIVE, BANNER_ON, mode stripped = input.rstrip() tokens = input.rstrip().split() if len(tokens) < 1: return cmd = tokens[0] args = tokens[1:] print 'processing command: ' + ' '.join(tokens) LEFT(1000) #--- banner if cmd=='banner': if len(args) == 0: print 'command banner requires you to specify "on" or "off". (see help for details)' elif args[0] == 'on' : BANNER_ON = True elif args[0] == 'off': BANNER_ON = False else: print 'command banner requires you to specify "on" or "off". (see help for details)' #--- exit, quit elif cmd=='exit' or cmd=='quit': CLI_ACTIVE = False jana.Quit() #--- help elif cmd=='help': print_help() #--- history elif cmd=='history': idx = 0 for h in history: print '%3d %s\r' % (idx, h) idx += 1 print '%3d %s\r' % (idx, ' '.join(tokens) ) # include this history command which will be added below #--- nthreads elif cmd=='nthreads': if len(args) == 0: print 'Number of JThreads: %d' % jana.GetNJThreads() elif len(args)==1: print 'Number of JThreads now at: %d' % jana.SetNJThreads( int(args[0]) ) else: print 'njthreads takes either 0 or 1 argument (see help for details)' #--- parameter elif cmd=='parameter': if len(args) == 0: print 'command parameter requires arguments. (see help for details)' elif args[0] == 'get': if len(args)==2: print '%s: %s' % (args[1], jana.GetParameterValue(args[1])) else: print 'command parameter get requires exactly 1 argument! (see help for details)' elif args[0] == 'set': if len(args)==3: jana.SetParameter(args[1], args[2]) else: print 'command parameter set requires exactly 2 arguments! (see help for details)' elif args[0] == 'list': if len(args)==1: jana.PrintParameters(True) else: print 'command parameter list requires no arguments! (see help for details)' #--- resume elif cmd=='resume': jana.Resume() print 'event processing resumed' #--- status elif cmd=='status': jana.PrintStatus() print '' #--- stop elif cmd=='stop': jana.Stop(True) print 'event processing stopped after %d events (use "resume" to start again)' % jana.GetNeventsProcessed() #--- unknown command else: print 'Unknown command: ' + cmd return history.append( ' '.join(tokens) ) # add to history