コード例 #1
0
def receiver(raw):
    """ Receives the raw prompt text and parses """

    # strip out the colors
    prompt = ansi.filter_ansi(raw)

    # What is this??
    if '-' not in prompt:
        return raw

    if prompt[0] == '-':
        player.blackout = True
        blackout_signal.send(blackout=True)
        blackout_triggers.enable()
        return renderer.render_blackout()

    if player.blackout is True:
        blackout_signal.send(blackout=False)
        player.blackout = False
        blackout_triggers.disable()

    stats = prompt.split(' ')[-1][:-1]

    prompt_stats.send(stats=stats, renderer=renderer)
    player.prompt_stats = stats

    renderer.receive(raw, stats)

    return renderer.render()
コード例 #2
0
ファイル: communication.py プロジェクト: danielja/mudpy
def chatstuff(talker, channel, text, **kwargs):
    global convos
    global last_response
    global talkon
    if talker.lower() == player.name.lower() or talker.lower() == 'you' or not talkon:
         return
    thread.start_new_thread(chatstuffThreaded, (talker, channel, ansi.filter_ansi(text)))
コード例 #3
0
def chatstuff(talker, channel, text, **kwargs):
    global convos
    global last_response
    global talkon
    if talker.lower() == player.name.lower() or talker.lower(
    ) == 'you' or not talkon:
        return
    thread.start_new_thread(chatstuffThreaded,
                            (talker, channel, ansi.filter_ansi(text)))
コード例 #4
0
    def segmentReceived(self):
        data = self.data_buffer
        self.data_buffer = ''

        # don't lead with a newline
        if data[0] == NL:
            data = data[1:]

        # Fix color-only leading line
        color_newline = self.color_newline.match(data)
        if color_newline:
            color = data[0:color_newline.end() - 1]
            data = color + data[color_newline.end():]

        data = data.split('\n')

        pre_prompt.send(raw_data=data)

        # lines received
        lines = data[:-1]

        # last line is always the prompt
        prompt_data = data[-1]

        # Send the prompt to the prompt receiver
        try:
            prompt_output = prompt.receiver(prompt_data)
        except Exception as err:
            _log.err()
            prompt_output = "%s - %s" % (ansi.bold_red('ERROR:'), ansi.red(str(err)))

        # send lines to inbound receiver
        lines = inbound.receiver(lines)

        post_prompt.send()

        signal.pre_outbound.send(
            raw_lines=sage.buffer,
            lines=lines,
            ansi_prompt=prompt_output,
            prompt=ansi.filter_ansi(prompt_output)
        )

        self.receivers.input(lines, prompt_output)
コード例 #5
0
    def segmentReceived(self):
        data = self.data_buffer
        self.data_buffer = ''

        # don't lead with a newline
        if data[0] == NL:
            data = data[1:]

        # Fix color-only leading line
        color_newline = self.color_newline.match(data)
        if color_newline:
            color = data[0:color_newline.end() - 1]
            data = color + data[color_newline.end():]

        data = data.split('\n')

        pre_prompt.send(raw_data=data)

        # lines received
        lines = data[:-1]

        # last line is always the prompt
        prompt_data = data[-1]

        # Send the prompt to the prompt receiver
        try:
            prompt_output = prompt.receiver(prompt_data)
        except Exception as err:
            _log.err()
            prompt_output = "%s - %s" % (ansi.bold_red('ERROR:'),
                                         ansi.red(str(err)))

        # send lines to inbound receiver
        lines = inbound.receiver(lines)

        post_prompt.send()

        signal.pre_outbound.send(raw_lines=sage.buffer,
                                 lines=lines,
                                 ansi_prompt=prompt_output,
                                 prompt=ansi.filter_ansi(prompt_output))

        self.receivers.input(lines, prompt_output)
コード例 #6
0
ファイル: inbound.py プロジェクト: spicerack/sage
 def __new__(cls, string):
     line = str.__new__(cls, filter_ansi(string))
     line.raw = string
     line.output = string
     return line