<s> """<STR_LIT>""" <EOL> import colorama <EOL> from colorama import Fore , Back , Style <EOL> import StringIO <EOL> colorama . init ( ) <EOL> class Column ( object ) : <EOL> def __init__ ( self , layout ) : <EOL> self . width = layout . config . get_column_width ( self ) <EOL> def format ( self , data ) : <EOL> return self . FORMAT % data <EOL> class DateColumn ( Column ) : <EOL> NAME = "<STR_LIT:date>" <EOL> FORMAT = Fore . WHITE + Back . BLACK + Style . DIM + "<STR_LIT:%s>" + Style . RESET_ALL <EOL> DEFAULT_WIDTH = <NUM_LIT:7> <EOL> class TimeColumn ( Column ) : <EOL> NAME = "<STR_LIT:time>" <EOL> FORMAT = Fore . WHITE + Back . BLACK + Style . DIM + "<STR_LIT:%s>" + Style . RESET_ALL <EOL> DEFAULT_WIDTH = <NUM_LIT> <EOL> class PIDColumn ( Column ) : <EOL> NAME = "<STR_LIT>" <EOL> DEFAULT_WIDTH = <NUM_LIT:8> <EOL> FORMAT = Fore . WHITE + Back . BLACK + Style . DIM + "<STR_LIT:%s>" + Style . RESET_ALL <EOL> def format ( self , pid ) : <EOL> if self . width > <NUM_LIT:0> : <EOL> pid = pid . center ( self . width ) <EOL> return Column . format ( self , pid ) <EOL> class TIDColumn ( PIDColumn ) : <EOL> NAME = "<STR_LIT>" <EOL> def format ( self , tid ) : <EOL> if "<STR_LIT>" in tid : <EOL> tid = str ( int ( tid , <NUM_LIT:16> ) ) <EOL> return PIDColumn . format ( self , tid ) <EOL> class TagColumn ( Column ) : <EOL> NAME = "<STR_LIT>" <EOL> DEFAULT_WIDTH = <NUM_LIT:20> <EOL> COLOR_NAMES = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> COLOR_MAP = { } <EOL> @ classmethod <EOL> def init_color_map ( cls ) : <EOL> for color in cls . COLOR_NAMES : <EOL> cls . COLOR_MAP [ color ] = getattr ( Fore , color ) <EOL> def __init__ ( self , layout ) : <EOL> Column . __init__ ( self , layout ) <EOL> tag_colors = None <EOL> if layout . profile : <EOL> tag_colors = layout . profile . tag_colors <EOL> self . tag_colors = tag_colors or { } <EOL> self . last_used = self . COLOR_MAP . values ( ) [ : ] <EOL> def allocate_color ( self , tag ) : <EOL> if tag not in self . tag_colors : <EOL> self . tag_colors [ tag ] = self . last_used [ <NUM_LIT:0> ] <EOL> color = self . tag_colors [ tag ] <EOL> self . last_used . remove ( color ) <EOL> self . last_used . append ( color ) <EOL> return color <EOL> def format ( self , tag ) : <EOL> color = self . allocate_color ( tag ) <EOL> if self . width > <NUM_LIT:2> : <EOL> if self . width < len ( tag ) : <EOL> tag = tag [ <NUM_LIT:0> : self . width - <NUM_LIT:2> ] + "<STR_LIT:..>" <EOL> tag = tag . rjust ( self . width ) <EOL> return color + Style . DIM + tag + Style . RESET_ALL <EOL> TagColumn . init_color_map ( ) <EOL> class PriorityColumn ( Column ) : <EOL> NAME = "<STR_LIT>" <EOL> DEFAULT_WIDTH = <NUM_LIT:3> <EOL> COLORS = { <EOL> "<STR_LIT>" : Fore . WHITE + Back . BLACK , <EOL> "<STR_LIT:D>" : Fore . BLACK + Back . BLUE , <EOL> "<STR_LIT:I>" : Fore . BLACK + Back . GREEN , <EOL> "<STR_LIT>" : Fore . BLACK + Back . YELLOW , <EOL> "<STR_LIT:E>" : Fore . BLACK + Back . RED , <EOL> "<STR_LIT:F>" : Fore . BLACK + Back . RED , <EOL> "<STR_LIT:S>" : Fore . BLACK + Back . WHITE <EOL> } <EOL> def __init__ ( self , layout ) : <EOL> Column . __init__ ( self , layout ) <EOL> self . formats = { } <EOL> for priority in self . COLORS . keys ( ) : <EOL> self . formats [ priority ] = self . COLORS [ priority ] + priority . center ( self . width ) + Style . RESET_ALL <EOL> def format ( self , priority ) : <EOL> return self . formats [ priority ] <EOL> class MessageColumn ( Column ) : <EOL> NAME = "<STR_LIT:message>" <EOL> DEFAULT_WIDTH = <NUM_LIT:0> <EOL> def __init__ ( self , layout ) : <EOL> self . width = None <EOL> self . left = layout . total_column_width <EOL> if layout . config . get_wrap ( ) and ( not layout . profile or layout . profile . wrap ) : <EOL> self . width = layout . width - self . left <EOL> def format ( self , message ) : <EOL> if not self . width : <EOL> return message <EOL> messagebuf = StringIO . StringIO ( ) <EOL> current = <NUM_LIT:0> <EOL> while current < len ( message ) : <EOL> next = min ( current + self . width , len ( message ) ) <EOL> messagebuf . write ( message [ current : next ] ) <EOL> if next < len ( message ) : <EOL> messagebuf . write ( "<STR_LIT>" % ( "<STR_LIT:U+0020>" * self . left ) ) <EOL> current = next <EOL> return messagebuf . getvalue ( ) </s>
