Beispiel #1
0
    def do_commit(self, input_text: str):
        print("🕑", end="\r")
        input_block = Block(input_text, attrs=dict(type='input'))
        input_block: Block = self.block_formatter.filter_block(input_block)
        if input_block.text:
            self.story.blocks.append(input_block)

        processed_story: str = self.block_formatter.process_story(self.story)
        output_text: str = self.generator.generate_raw(processed_story)

        output_block = Block(output_text, attrs=dict(type='output'))
        output_block = self.block_formatter.filter_block(output_block)
        self.story.blocks.append(output_block)

        print("  ", end="\r")

        rendered_block: Block = self.block_formatter.render_block(output_block)
        self.poutput(rendered_block.text)
Beispiel #2
0
    def render_input(self, block: Block) -> Block:
        rendered_input = block.text
        is_input = block.attrs.get('type') == 'input'
        is_pinned = block.attrs.get('pinned')

        if self.settings.fill_width:
            rendered_input = "\n".join([
                self.fill_text(l, is_input, is_pinned)
                for l in rendered_input.splitlines()
            ])

        return Block(rendered_input, block.attrs.copy())
Beispiel #3
0
    def render_output(self, block: Block) -> Block:
        rendered_output = block.text
        is_input = block.attrs.get('type') == 'input'
        is_pinned = block.attrs.get('pinned')

        if self.settings.fill_width:
            rendered_output = "\n".join([
                self.fill_text(l, is_input, is_pinned)
                for l in rendered_output.splitlines()
            ])

        rendered_output = f"{self.settings.top_separator}\n{rendered_output}\n{self.settings.bottom_separator}"
        return Block(rendered_output, block.attrs.copy())
Beispiel #4
0
    def filter_output(self, block: Block) -> Block:
        text = cut_trailing_sentence(block.text)

        if len(text) == 0:
            text = ""
        else:
            text = text.replace('."', '".')
            text = text.replace("#", "")
            text = text.replace("*", "")
            text = text.replace("\n\n", "\n")

            text = text.strip(' \t\n\r')

            if not text.endswith("."):
                text = text + "."

        return Block(text, attrs=block.attrs.copy())
Beispiel #5
0
 def process_output(self, block: Block) -> Block:
     return Block(block.text, block.attrs.copy())
Beispiel #6
0
 def process_input(self, block: Block) -> Block:
     return Block("\n> " + block.text + "\n", block.attrs.copy())
Beispiel #7
0
 def filter_input(self, block: Block) -> Block:
     return Block(block.text.strip(' \t\n\r'), attrs=block.attrs.copy())
Beispiel #8
0
 def from_data(cls, path, data):
     story = cls(path)
     story.attrs = data["attrs"]
     story.blocks = [Block.from_data(d) for d in data["blocks"]]
     return story