from . import GridRenderer
from ..grid import symbols

class LineGridRenderer(GridRenderer):
    """Renders a grid into a flat string, as puzzles are often presented in
    plaintext collections.
    """
    pass


class SquareGridRenderer(GridRenderer):
    """Renders a grid as a square of characters."""

    def after_row(self, row, new_box=False):
        return '\n'


class AsciiArtGridRenderer(SquareGridRenderer):
    """Renders a questionably-pretty ASCII art drawing of a grid, with dividers
    between rows and columns.
    """

    def inside_grid(self, grid):
        box_header = '+' + '-' * grid.box_width
        return box_header * grid.box_height + '+\n'

    def inside_row(self, row):
        return '|'

    def after_row(self, row):
        return '|\n'

    def inside_cell(self, cell):
        if cell.solved:
            return symbols[cell.value]
        else:
            return ' '
