def refresh_line(y): global urlGrab, urlGrabSettings, urlgrab_buffer, current_line, max_buffer_length #Print format Time(space)buffer(max4 spaces, but lined up)url format = "%%s%%s %%s%%-%ds%%s%%s" % (max_buffer_length + 4) #non selected colors color_buffer = urlGrabSettings["color_buffer"] color_url = urlGrabSettings["color_url"] color_time = urlGrabSettings["color_time"] #selected colors color_buffer_selected = urlGrabSettings["color_buffer_selected"] color_url_selected = urlGrabSettings["color_url_selected"] color_time_selected = urlGrabSettings["color_time_selected"] color_bg_selected = urlGrabSettings["color_bg_selected"] color1 = color_time color2 = color_buffer color3 = color_url #If this line is selected we change the colors. if y == current_line: color1 = "%s,%s" % (color_time_selected, color_bg_selected) color2 = "%s,%s" % (color_buffer_selected, color_bg_selected) color3 = "%s,%s" % (color_url_selected, color_bg_selected) color1 = weechat.color(color1) color2 = weechat.color(color2) color3 = weechat.color(color3) text = format % (color1, urlGrab.globalUrls[y]['time'], color2, urlGrab.globalUrls[y]['buffer'], color3, urlGrab.globalUrls[y]['url']) weechat.prnt_y(urlgrab_buffer, y, text)
def test_display(): """Test display functions.""" check(weechat.prefix('action') != '') check(weechat.prefix('error') != '') check(weechat.prefix('join') != '') check(weechat.prefix('network') != '') check(weechat.prefix('quit') != '') check(weechat.prefix('unknown') == '') check(weechat.color('green') != '') check(weechat.color('unknown') == '') weechat.prnt('', '## test print core buffer') weechat.prnt_date_tags('', 946681200, 'tag1,tag2', '## test print_date_tags core buffer') buffer = weechat.buffer_new('test_formatted', 'buffer_input_cb', '', 'buffer_close_cb', '') check(buffer != '') check(weechat.buffer_get_integer(buffer, 'type') == 0) weechat.prnt(buffer, '## test print formatted buffer') weechat.prnt_date_tags(buffer, 946681200, 'tag1,tag2', '## test print_date_tags formatted buffer') weechat.buffer_close(buffer) buffer = weechat.buffer_new_props('test_free', {'type': 'free'}, 'buffer_input_cb', '', 'buffer_close_cb', '') check(weechat.buffer_get_integer(buffer, 'type') == 1) check(buffer != '') weechat.prnt_y(buffer, 0, '## test print_y free buffer') weechat.prnt_y_date_tags(buffer, 0, 946681200, 'tag1,tag2', '## test print_y_date_tags free buffer') weechat.buffer_close(buffer)
def refresh_line(self, y): format = "%%s%%s %%s%%-%ds%%s%%s %%s - %%s" % (self.max_buffer_width-4) color_time = "cyan" color_buffer = "red" color_info = "green" color_url = "blue" color_bg_selected = "red" if y == self.current_line: color_time = "%s,%s" % (color_time, color_bg_selected) color_buffer = "%s,%s" % (color_buffer, color_bg_selected) color_info = "%s,%s" % (color_info, color_bg_selected) color_url = "%s,%s" % (color_url, color_bg_selected) color_time = weechat.color(color_time) color_buffer = weechat.color(color_buffer) color_info = weechat.color(color_info) color_url = weechat.color(color_url) text = '' if len(self.urls) - 1 > y : url = self.urls[y] url_info = self.url_infos[url] text = format % (color_time, url_info['time'], color_buffer, url_info['buffer'], color_info, url_info['info'], color_url, url_info['url'] ) weechat.prnt_y(self.url_buffer,y,text)
def render(self): for y in self.screen.dirty: line = self.display_line(self.screen.buffer[y]) message = self.render_line(y, line) + weechat.color("reset") weechat.prnt_y(self.buffer, y, message.encode("utf-8")) self.screen.dirty.clear()
def minesweeper_display_status(): """Display status line below board.""" global minesweeper if not minesweeper['buffer']: return msgend = '' if minesweeper['end']: msgend = '%s%s' % (weechat.color( minesweeper['endmsg'][minesweeper['end']][0]), minesweeper['endmsg'][minesweeper['end']][1]) else: if minesweeper['flags'] == 0: msgend = '%sSome bad flags, remove and go on!' % weechat.color( 'yellow') hours = minesweeper['time'] // 3600 minutes = (minesweeper['time'] % 3600) // 60 seconds = (minesweeper['time'] % 3600) % 60 if minesweeper_settings['utf8'] == 'on': flag = '⚑' else: flag = 'p' weechat.prnt_y( minesweeper['buffer'], 2 + (minesweeper['size'] * (minesweeper['zoom'] + 2)), '%s %3d%s/%-3d%s%5d:%02d:%02d %s' % (flag, minesweeper['flags'], weechat.color('green'), minesweeper['mines'][minesweeper['size']], weechat.color('reset'), hours, minutes, seconds, msgend))
def display_line(self, line: int) -> None: """Display a line of maze.""" str_line: str if line >= self.height: str_line = (weechat.color("white") + ("▀" * ((self.width * 2) + 1))) else: both_sol: int = self.SOLUTION | self.SOLUTION_INT cell: int = self.cells[line * self.width] color: str = ("lightred" if cell & self.SOLUTION_INT else "blue" if cell & self.SOLUTION else "black") str_line = (weechat.color(f"{color},white") + ("▄" if cell & self.LEFT else " ")) for col in range(self.width): cell = self.cells[(line * self.width) + col] color = ("lightred" if cell & self.SOLUTION_INT else "blue" if cell & self.SOLUTION else "black") # door opened on top? if cell & self.TOP: pos: int = ((line - 1) * self.width) + col if line > 0 and self.cells[pos] & both_sol: str_line += weechat.color(f"white,{color}") + " " else: str_line += weechat.color(f"{color},black") + "▄" else: str_line += weechat.color(f"{color},white") + "▄" # door opened on the right? str_line += (weechat.color(f"{color},white") + ("▄" if cell & self.RIGHT else " ")) str_line += weechat.color("reset") weechat.prnt_y(self.buffer, line, str_line)
def weetris_display_playing_time_cb(data, remaining_calls): """Callback of timer to display the playing time.""" total_seconds = time.time() - weetris['play_start_time'] minutes = int(total_seconds // 60) seconds = int(total_seconds % 60) total_seconds += 1 weechat.prnt_y(weetris['buffer'], START_Y + GAME_HEIGHT + 6, ' Playing time : %02d:%02d' % (minutes, seconds)) return weechat.WEECHAT_RC_OK
def display_all(): """Display everything on the weetris buffer.""" display_piece(True) weechat.prnt_y(weetris['buffer'], START_Y, ' ┌' + ('──' * GAME_WIDTH) + '┐') for y in range(GAME_HEIGHT): display_line(y) weechat.prnt_y(weetris['buffer'], START_Y + GAME_HEIGHT + 1, ' └' + ('──' * GAME_WIDTH) + '┘') display_piece(False)
def display_level_lines(): """Display the current level and number of lines.""" list_info = [ 'Level %-3d %6d line%s' % (weetris['level'], weetris['lines'], 's' if weetris['lines'] > 1 else ''), '-' * (1 + (GAME_WIDTH * 2) + 1), 'Highest level: %d' % weetris['best_level'], 'Max lines : %d' % weetris['best_lines'], ] for y, info in enumerate(list_info): weechat.prnt_y(weetris['buffer'], START_Y + GAME_HEIGHT + 2 + y, ' ' + info)
def floodit_display(clear=False): """Display status and board.""" global floodit if not floodit['buffer']: return if clear: weechat.buffer_clear(floodit['buffer']) spaces = ' ' * ((floodit['zoom'] + 1) * 2) str_line = '' for index, color in enumerate(floodit['colors']): str_select = [' ', ' '] if floodit['color'] == index: str_select = ['»', '«'] str_line += '%s%s%s%s%s%s%s' % (weechat.color('white,default'), str_select[0], weechat.color(',%s' % color), spaces, weechat.color('white,default'), str_select[1], spaces[0:-2]) str_status = '' str_end = '' if floodit['mode'] == 'single': board = copy.deepcopy(floodit['board']) floodit_flood_xy(board, 0, 0, board[0][0]) percent = (floodit_count_color(board, -1) * 100) // (floodit['size'] * floodit['size']) str_status = '%2d/%d%s (%d%%)' % (floodit['count'], floodit['count_max'], weechat.color('chat'), percent) message_end = { 'win': '** CONGRATS! **', 'lose': '...GAME OVER!...' } elif floodit['mode'] == 'versus': colors = ['yellow', 'lightred'] board = copy.deepcopy(floodit['board']) floodit_flood_xy(board, 0, 0, board[0][0]) count_player = floodit_count_color(board, -1) board = copy.deepcopy(floodit['board']) floodit_flood_xy(board, floodit['size'] - 1, floodit['size'] - 1, board[floodit['size'] - 1][floodit['size'] - 1]) count_computer = floodit_count_color(board, -1) if count_player == count_computer: colors[1] = 'yellow' elif count_computer > count_player: colors.reverse() str_status = '%sYou: %d%s / %sWee: %d' % (weechat.color(colors[0]), count_player, weechat.color('default'), weechat.color(colors[1]), count_computer) message_end = { 'win': '** YOU WIN! **', 'lose': '...You lose...', 'equality': 'Equality!' } str_end = '%s%s' % (weechat.color('white'), message_end.get(floodit['end'], '')) weechat.prnt_y(floodit['buffer'], 0, '%s %s %s' % (str_line, str_status, str_end)) for i in range (0, floodit['zoom']): weechat.prnt_y(floodit['buffer'], 1 + i, str_line) weechat.prnt_y(floodit['buffer'], floodit['zoom'] + 1, '%s%s' % (weechat.color('blue'), '─' * (floodit['size'] * ((floodit['zoom'] + 1) * 2)))) for y, line in enumerate(floodit['board']): str_line = '' for color in line: str_line += '%s%s' % (weechat.color(',%s' % floodit['colors'][color]), spaces) str_line += '%s' % weechat.color('chat') for i in range (0, floodit['zoom'] + 1): weechat.prnt_y(floodit['buffer'], floodit['zoom'] + 2 + (y * (floodit['zoom'] + 1)) + i, str_line)
def end_of_piece(): """End of a piece (it can not go down any more).""" display_piece(True) set_new_form() if is_possible(weetris['piece_x'], weetris['piece_y'], weetris['piece_form']): remove_completed_lines() else: weetris['piece_form'] = 0 weetris['playing'] = False weetris['paused'] = False if weetris['time_display_timer']: weechat.unhook(weetris['time_display_timer']) weetris['time_display_timer'] = '' weechat.prnt_y(weetris['buffer'], START_Y + GAME_HEIGHT + 2, '>> End of game, score: %d lines, level %d ' '(alt-N to restart) <<' % (weetris['lines'], weetris['level']))
def show_nicks_cb(data, signal, signal_data): global nicklist buffer = weechat.buffer_search('python', 'hipchat_nicks') if not buffer: return weechat.WEECHAT_RC_OK weechat.command("", "/buffer " + weechat.buffer_get_string(buffer, "name")) args = weechat.buffer_get_string(buffer, 'localvar_hipchat_args') idx = 0 nicks = sorted(nicklist.items()) for name, nick in nicks: line = '@{name} - {fullname}'.format(name=encode(name), fullname=encode(nick['name'])) if not args or weechat.string_match(line, args, 0): weechat.prnt_y(buffer, idx, line) idx += 1 return weechat.WEECHAT_RC_OK
def new_game(): """New game.""" weechat.prnt_y(weetris['buffer'], START_Y + GAME_HEIGHT + 2, '') weetris['matrix'] = [[-1] * GAME_WIDTH for i in range(GAME_HEIGHT)] weetris['next_piece_number'] = -1 set_new_form() weetris['playing'] = True weetris['paused'] = False weetris['lines'] = 0 weetris['level'] = 1 weetris['play_start_time'] = time.time() weechat.prnt_y(weetris['buffer'], START_Y + GAME_HEIGHT + 6, ' Playing time : 00:00') init_timer() weetris['time_display_timer'] = weechat.hook_timer( 1000, 0, 0, 'weetris_display_playing_time_cb', '', ) display_all() display_level_lines()
def minesweeper_display_status(): """Display status line below board.""" global minesweeper if not minesweeper['buffer']: return msgend = '' if minesweeper['end']: msgend = '%s%s' % (weechat.color(minesweeper['endmsg'][minesweeper['end']][0]), minesweeper['endmsg'][minesweeper['end']][1]) else: if minesweeper['flags'] == 0: msgend = '%sSome bad flags, remove and go on!' % weechat.color('yellow') hours = minesweeper['time'] // 3600 minutes = (minesweeper['time'] % 3600) // 60 seconds = (minesweeper['time'] % 3600) % 60 if minesweeper_settings['utf8'] == 'on': flag = '⚑' else: flag = 'p' weechat.prnt_y(minesweeper['buffer'], 2 + (minesweeper['size'] * (minesweeper['zoom'] + 2)), '%s %3d%s/%-3d%s%5d:%02d:%02d %s' % (flag, minesweeper['flags'], weechat.color('green'), minesweeper['mines'][minesweeper['size']], weechat.color('reset'), hours, minutes, seconds, msgend))
def display_line(y): """Display a line of the matrix.""" line = ' │' if weetris['paused']: if y == GAME_HEIGHT // 2: spaces_before = ((GAME_WIDTH * 2) - 6) // 2 spaces_after = (GAME_WIDTH * 2) - 6 - spaces_before line += (' ' * spaces_before) + 'PAUSED' + (' ' * spaces_after) else: line += ' ' * GAME_WIDTH else: for x in range(GAME_WIDTH): line += get_piece_block(weetris['matrix'][y][x]) line += weechat.color(',default') + '│' if weetris['playing'] and weetris_settings['display_next_piece'] == 'on': if y == 0: line += ' Next: ' elif 1 <= y <= 4: line += ' ' for x in range(4): line += get_piece_block(weetris['matrix_next'][y - 1][x]) line += weechat.color(',default') weechat.prnt_y(weetris['buffer'], START_Y + y + 1, line)
def samegame_display(clear=False): """Display status and board.""" global samegame if not samegame["buffer"]: return if clear: weechat.buffer_clear(samegame["buffer"]) spaces = " " * ((samegame["zoom"] + 1) * 2) # display status str_status = "Board: %s%dx%d%s Colors: %s%d%s Score: %s%d" % ( weechat.color("white"), samegame["size"][0], samegame["size"][1], weechat.color("chat"), weechat.color("white"), samegame["numcolors"], weechat.color("chat"), weechat.color("white"), samegame["score"], ) str_end = "%s%s" % (weechat.color("white"), samegame["end"]) weechat.prnt_y(samegame["buffer"], 0, "%s %s" % (str_status, str_end)) # display board weechat.prnt_y( samegame["buffer"], 1, "%s┌%s┐" % (weechat.color("chat"), "─" * (samegame["size"][0] * ((samegame["zoom"] + 1) * 2))), ) for y, line in enumerate(samegame["board"]): str_line = "│" for color in line: if color < 0: str_color = "default" else: str_color = samegame["colors"][color] str_line += "%s%s" % (weechat.color(",%s" % str_color), spaces) str_line += "%s│" % weechat.color("chat") for i in range(0, samegame["zoom"] + 1): weechat.prnt_y(samegame["buffer"], 2 + (y * (samegame["zoom"] + 1)) + i, str_line) weechat.prnt_y( samegame["buffer"], 1 + (samegame["size"][1] * (samegame["zoom"] + 1)) + 1, "%s└%s┘" % (weechat.color("chat"), "─" * (samegame["size"][0] * ((samegame["zoom"] + 1) * 2))), )
def refresh_line (y): global urlGrab , urlGrabSettings, urlgrab_buffer, current_line, max_buffer_length #Print format Time(space)buffer(max4 spaces, but lined up)url format = "%%s%%s %%s%%-%ds%%s%%s" % (max_buffer_length+4) #non selected colors color_buffer = urlGrabSettings["color_buffer"] color_url = urlGrabSettings["color_url"] color_time =urlGrabSettings["color_time"] #selected colors color_buffer_selected = urlGrabSettings["color_buffer_selected"] color_url_selected = urlGrabSettings["color_url_selected"] color_time_selected = urlGrabSettings["color_time_selected"] color_bg_selected = urlGrabSettings["color_bg_selected"] color1 = color_time color2 = color_buffer color3 = color_url #If this line is selected we change the colors. if y == current_line: color1 = "%s,%s" % (color_time_selected, color_bg_selected) color2 = "%s,%s" % (color_buffer_selected, color_bg_selected) color3 = "%s,%s" % (color_url_selected, color_bg_selected) color1 = weechat.color(color1) color2 = weechat.color(color2) color3 = weechat.color(color3) text = format % (color1, urlGrab.globalUrls[y]['time'], color2, urlGrab.globalUrls[y]['buffer'], color3, urlGrab.globalUrls[y]['url'] ) weechat.prnt_y(urlgrab_buffer,y,text)
def samegame_display(clear=False): """Display status and board.""" global samegame if not samegame['buffer']: return if clear: weechat.buffer_clear(samegame['buffer']) spaces = ' ' * ((samegame['zoom'] + 1) * 2) # display status str_status = 'Board: %s%dx%d%s Colors: %s%d%s Score: %s%d' % ( weechat.color('white'), samegame['size'][0], samegame['size'][1], weechat.color('chat'), weechat.color('white'), samegame['numcolors'], weechat.color('chat'), weechat.color('white'), samegame['score']) str_end = '%s%s' % (weechat.color('white'), samegame['end']) weechat.prnt_y(samegame['buffer'], 0, '%s %s' % (str_status, str_end)) # display board weechat.prnt_y( samegame['buffer'], 1, '%s┌%s┐' % (weechat.color('chat'), '─' * (samegame['size'][0] * ((samegame['zoom'] + 1) * 2)))) for y, line in enumerate(samegame['board']): str_line = '│' for color in line: if color < 0: str_color = 'default' else: str_color = samegame['colors'][color] str_line += '%s%s' % (weechat.color(',%s' % str_color), spaces) str_line += '%s│' % weechat.color('chat') for i in range(0, samegame['zoom'] + 1): weechat.prnt_y(samegame['buffer'], 2 + (y * (samegame['zoom'] + 1)) + i, str_line) weechat.prnt_y( samegame['buffer'], 1 + (samegame['size'][1] * (samegame['zoom'] + 1)) + 1, '%s└%s┘' % (weechat.color('chat'), '─' * (samegame['size'][0] * ((samegame['zoom'] + 1) * 2))))
def tictactoe_display(clear=False): """Display board.""" if not tictactoe['buffer']: return if clear: weechat.buffer_clear(tictactoe['buffer']) line = 1 for y in range(0, 3): for i in range(0, 3): str_line = ' ' for x in range(0, 3): pos = (y * 3) + x if i == 0: str_line += '%s%d ' % (weechat.color( tictactoe_settings['color_digits']), 9 - ((y * 3) + (2 - x))) else: str_line += '%s%s' % (weechat.color( tictactoe['colors'][tictactoe['board'][pos]] ), tictactoe['symbols'][tictactoe['board'][pos]][i - 1]) if x < 2: str_line += '%s%s' % (weechat.color( tictactoe_settings['color_board']), '│') if y == 0 and i == 0: str_line += ' %sO%s = you' % (weechat.color( tictactoe_settings['color_human']), weechat.color('default')) if y == 0 and i == 1: str_line += ' %sX%s = computer' % ( weechat.color(tictactoe_settings['color_computer']), weechat.color('default')) weechat.prnt_y(tictactoe['buffer'], line, str_line) line += 1 if y < 2: weechat.prnt_y( tictactoe['buffer'], line, ' %s──────┼──────┼──────' % weechat.color(tictactoe_settings['color_board'])) line += 1 line += 1 weechat.prnt_y( tictactoe['buffer'], line, '%s%s' % (weechat.color(tictactoe_settings['color_status']), tictactoe['end']))
def buffer_refresh_line(y): global curline if y >= 0 and y < len(buffer_items()): formatted_line = buffer_line_format(buffer_items()[y], y == curline) weechat.prnt_y(script_buffer(), y, formatted_line)
def lb_refresh_line(y): global lb_buffer, lb_curline, lb_channels if y >= 0 and y < len(lb_channels): formatted_line = lb_line_format(lb_channels[y], y == lb_curline) weechat.prnt_y(lb_buffer, y, formatted_line)
def minesweeper_display(clear=False): """Display status and board.""" global minesweeper, minesweeper_settings if not minesweeper['buffer']: return if clear: weechat.buffer_clear(minesweeper['buffer']) if minesweeper_settings['utf8'] == 'on': hbar = '▁' vbar = '▕' flag = '⚑' else: hbar = '_' vbar = '|' flag = 'p' str_grid = '%s%s%s%s ' % (hbar, hbar, hbar, hbar * minesweeper['zoom'] * 2) weechat.prnt_y( minesweeper['buffer'], 0, '%s%s' % (weechat.color(minesweeper_settings['color_grid']), str_grid * minesweeper['size'])) color_explosion = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_explosion_bg']) color_explosion_text = '%s,%s' % ( minesweeper_settings['color_flag'], minesweeper_settings['color_explosion_bg']) color_mine = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_mine_bg']) color_mine_text = '%s,%s' % (minesweeper_settings['color_mine'], minesweeper_settings['color_mine_bg']) for y, line in enumerate(minesweeper['board']): if minesweeper['zoom'] == 0: str_lines = ['', ''] else: str_lines = ['', '', ''] for x, status in enumerate(line): if minesweeper['cursor'] and minesweeper['x'] == x and minesweeper[ 'y'] == y: color_nostatus = '%s,%s' % ( minesweeper_settings['color_grid'], minesweeper_settings['color_cursor_bg']) color_flag = '%s,%s' % ( minesweeper_settings['color_grid'], minesweeper_settings['color_cursor_bg']) color_flag_text = '%s,%s' % ( minesweeper_settings['color_flag'], minesweeper_settings['color_cursor_bg']) color_digit = '%s,%s' % ( minesweeper_settings['color_grid'], minesweeper_settings['color_cursor_bg']) color_digit_text_bg = ',%s' % minesweeper_settings[ 'color_cursor_bg'] else: color_nostatus = '%s,%s' % ( minesweeper_settings['color_grid'], minesweeper_settings['color_square_bg']) color_flag = '%s,%s' % ( minesweeper_settings['color_grid'], minesweeper_settings['color_square_bg']) color_flag_text = '%s,%s' % ( minesweeper_settings['color_flag'], minesweeper_settings['color_square_bg']) color_digit = '%s,default' % minesweeper_settings['color_grid'] color_digit_text_bg = ',default' if status[1] == ' ': char = ' ' if status[0] and minesweeper['cheat']: char = '*' if minesweeper['zoom'] == 0: str_lines[0] += '%s %s %s%s' % (weechat.color( color_nostatus), char, vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % ( weechat.color(color_nostatus), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color( color_nostatus), vbar, weechat.color('reset')) str_lines[1] += '%s %s %s%s' % (weechat.color( color_nostatus), char, vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % ( weechat.color(color_nostatus), hbar * 5, vbar, weechat.color('reset')) elif status[1] == 'F': if minesweeper['zoom'] == 0: str_lines[0] += '%s %s%s%s %s%s' % ( weechat.color(color_flag), weechat.color(color_flag_text), flag, weechat.color(color_flag), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_flag), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_flag), vbar, weechat.color('reset')) str_lines[1] += '%s %s%s%s %s%s' % ( weechat.color(color_flag), weechat.color(color_flag_text), flag, weechat.color(color_flag), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_flag), hbar * 5, vbar, weechat.color('reset')) elif status[1].isdigit(): char = status[1] if char == '0': char = ' ' color_digit_text = 'default' else: color_digit_text = minesweeper['color_digits'][ int(status[1]) - 1] if minesweeper['zoom'] == 0: str_lines[0] += '%s %s%s%s %s%s' % ( weechat.color(color_digit), weechat.color(color_digit_text + color_digit_text_bg), char, weechat.color(color_digit), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_digit), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color( color_digit), vbar, weechat.color('reset')) str_lines[1] += '%s %s%s%s %s%s' % ( weechat.color(color_digit), weechat.color(color_digit_text + color_digit_text_bg), char, weechat.color(color_digit), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_digit), hbar * 5, vbar, weechat.color('reset')) elif status[1] == '+': if minesweeper['zoom'] == 0: str_lines[0] += '%s %s*%s %s%s' % ( weechat.color(color_mine), weechat.color(color_mine_text), weechat.color(color_mine), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_mine), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_mine), vbar, weechat.color('reset')) str_lines[1] += '%s %s*%s %s%s' % ( weechat.color(color_mine), weechat.color(color_mine_text), weechat.color(color_mine), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_mine), hbar * 5, vbar, weechat.color('reset')) elif status[1] == '*': if minesweeper['zoom'] == 0: str_lines[0] += '%s %s*%s %s%s' % ( weechat.color(color_explosion), weechat.color(color_explosion_text), weechat.color(color_explosion), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % ( weechat.color(color_explosion), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color( color_explosion), vbar, weechat.color('reset')) str_lines[1] += '%s %s*%s %s%s' % ( weechat.color(color_explosion), weechat.color(color_explosion_text), weechat.color(color_explosion), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % ( weechat.color(color_explosion), hbar * 5, vbar, weechat.color('reset')) for i, str_line in enumerate(str_lines): weechat.prnt_y(minesweeper['buffer'], 1 + (y * len(str_lines)) + i, str_line) minesweeper_display_status()
def rooms_refresh_line(y): global rooms_buffer, rooms_curline, rooms_channels_filtered if y >= 0 and y < len(rooms_channels): formatted_line = rooms_line_format(rooms_channels_filtered[y], y == rooms_curline) weechat.prnt_y(rooms_buffer, y, formatted_line)
def floodit_display(clear=False): """Display status and board.""" global floodit if not floodit['buffer']: return if clear: weechat.buffer_clear(floodit['buffer']) spaces = ' ' * ((floodit['zoom'] + 1) * 2) str_line = '' for index, color in enumerate(floodit['colors']): str_select = [' ', ' '] if floodit['color'] == index: str_select = ['»', '«'] str_line += '%s%s%s%s%s%s%s' % ( weechat.color('white,default'), str_select[0], weechat.color(',%s' % color), spaces, weechat.color('white,default'), str_select[1], spaces[0:-2]) str_status = '' str_end = '' if floodit['mode'] == 'single': board = copy.deepcopy(floodit['board']) floodit_flood_xy(board, 0, 0, board[0][0]) percent = (floodit_count_color(board, -1) * 100) // (floodit['size'] * floodit['size']) str_status = '%2d/%d%s (%d%%)' % (floodit['count'], floodit['count_max'], weechat.color('chat'), percent) message_end = {'win': '** CONGRATS! **', 'lose': '...GAME OVER!...'} elif floodit['mode'] == 'versus': colors = ['yellow', 'lightred'] board = copy.deepcopy(floodit['board']) floodit_flood_xy(board, 0, 0, board[0][0]) count_player = floodit_count_color(board, -1) board = copy.deepcopy(floodit['board']) floodit_flood_xy(board, floodit['size'] - 1, floodit['size'] - 1, board[floodit['size'] - 1][floodit['size'] - 1]) count_computer = floodit_count_color(board, -1) if count_player == count_computer: colors[1] = 'yellow' elif count_computer > count_player: colors.reverse() str_status = '%sYou: %d%s / %sWee: %d' % ( weechat.color(colors[0]), count_player, weechat.color('default'), weechat.color(colors[1]), count_computer) message_end = { 'win': '** YOU WIN! **', 'lose': '...You lose...', 'equality': 'Equality!' } str_end = '%s%s' % (weechat.color('white'), message_end.get(floodit['end'], '')) weechat.prnt_y(floodit['buffer'], 0, '%s %s %s' % (str_line, str_status, str_end)) for i in range(0, floodit['zoom']): weechat.prnt_y(floodit['buffer'], 1 + i, str_line) weechat.prnt_y( floodit['buffer'], floodit['zoom'] + 1, '%s%s' % (weechat.color('blue'), '─' * (floodit['size'] * ((floodit['zoom'] + 1) * 2)))) for y, line in enumerate(floodit['board']): str_line = '' for color in line: str_line += '%s%s' % (weechat.color( ',%s' % floodit['colors'][color]), spaces) str_line += '%s' % weechat.color('chat') for i in range(0, floodit['zoom'] + 1): weechat.prnt_y( floodit['buffer'], floodit['zoom'] + 2 + (y * (floodit['zoom'] + 1)) + i, str_line)
def minesweeper_display(clear=False): """Display status and board.""" global minesweeper, minesweeper_settings if not minesweeper['buffer']: return if clear: weechat.buffer_clear(minesweeper['buffer']) if minesweeper_settings['utf8'] == 'on': hbar = '▁' vbar = '▕' flag = '⚑' else: hbar = '_' vbar = '|' flag = 'p' str_grid = '%s%s%s%s ' % (hbar, hbar, hbar, hbar * minesweeper['zoom'] * 2) weechat.prnt_y(minesweeper['buffer'], 0, '%s%s' % (weechat.color(minesweeper_settings['color_grid']), str_grid * minesweeper['size'])) color_explosion = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_explosion_bg']) color_explosion_text = '%s,%s' % (minesweeper_settings['color_flag'], minesweeper_settings['color_explosion_bg']) color_mine = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_mine_bg']) color_mine_text = '%s,%s' % (minesweeper_settings['color_mine'], minesweeper_settings['color_mine_bg']) for y, line in enumerate(minesweeper['board']): if minesweeper['zoom'] == 0: str_lines = ['', ''] else: str_lines = ['', '', ''] for x, status in enumerate(line): if minesweeper['cursor'] and minesweeper['x'] == x and minesweeper['y'] == y: color_nostatus = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_cursor_bg']) color_flag = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_cursor_bg']) color_flag_text = '%s,%s' % (minesweeper_settings['color_flag'], minesweeper_settings['color_cursor_bg']) color_digit = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_cursor_bg']) color_digit_text_bg = ',%s' % minesweeper_settings['color_cursor_bg'] else: color_nostatus = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_square_bg']) color_flag = '%s,%s' % (minesweeper_settings['color_grid'], minesweeper_settings['color_square_bg']) color_flag_text = '%s,%s' % (minesweeper_settings['color_flag'], minesweeper_settings['color_square_bg']) color_digit = '%s,default' % minesweeper_settings['color_grid'] color_digit_text_bg = ',default' if status[1] == ' ': char = ' ' if status[0] and minesweeper['cheat']: char = '*' if minesweeper['zoom'] == 0: str_lines[0] += '%s %s %s%s' % (weechat.color(color_nostatus), char, vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_nostatus), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_nostatus), vbar, weechat.color('reset')) str_lines[1] += '%s %s %s%s' % (weechat.color(color_nostatus), char, vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_nostatus), hbar * 5, vbar, weechat.color('reset')) elif status[1] == 'F': if minesweeper['zoom'] == 0: str_lines[0] += '%s %s%s%s %s%s' % (weechat.color(color_flag), weechat.color(color_flag_text), flag, weechat.color(color_flag), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_flag), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_flag), vbar, weechat.color('reset')) str_lines[1] += '%s %s%s%s %s%s' % (weechat.color(color_flag), weechat.color(color_flag_text), flag, weechat.color(color_flag), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_flag), hbar * 5, vbar, weechat.color('reset')) elif status[1].isdigit(): char = status[1] if char == '0': char = ' ' color_digit_text = 'default' else: color_digit_text = minesweeper['color_digits'][int(status[1]) - 1] if minesweeper['zoom'] == 0: str_lines[0] += '%s %s%s%s %s%s' % ( weechat.color(color_digit), weechat.color(color_digit_text + color_digit_text_bg), char, weechat.color(color_digit), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_digit), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_digit), vbar, weechat.color('reset')) str_lines[1] += '%s %s%s%s %s%s' % ( weechat.color(color_digit), weechat.color(color_digit_text + color_digit_text_bg), char, weechat.color(color_digit), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_digit), hbar * 5, vbar, weechat.color('reset')) elif status[1] == '+': if minesweeper['zoom'] == 0: str_lines[0] += '%s %s*%s %s%s' % (weechat.color(color_mine), weechat.color(color_mine_text), weechat.color(color_mine), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_mine), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_mine), vbar, weechat.color('reset')) str_lines[1] += '%s %s*%s %s%s' % (weechat.color(color_mine), weechat.color(color_mine_text), weechat.color(color_mine), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_mine), hbar * 5, vbar, weechat.color('reset')) elif status[1] == '*': if minesweeper['zoom'] == 0: str_lines[0] += '%s %s*%s %s%s' % ( weechat.color(color_explosion), weechat.color(color_explosion_text), weechat.color(color_explosion), vbar, weechat.color('reset')) str_lines[1] += '%s%s%s%s' % (weechat.color(color_explosion), hbar * 3, vbar, weechat.color('reset')) else: str_lines[0] += '%s %s%s' % (weechat.color(color_explosion), vbar, weechat.color('reset')) str_lines[1] += '%s %s*%s %s%s' % ( weechat.color(color_explosion), weechat.color(color_explosion_text), weechat.color(color_explosion), vbar, weechat.color('reset')) str_lines[2] += '%s%s%s%s' % (weechat.color(color_explosion), hbar * 5, vbar, weechat.color('reset')) for i, str_line in enumerate(str_lines): weechat.prnt_y(minesweeper['buffer'], 1 + (y * len(str_lines)) + i, str_line) minesweeper_display_status()