Esempio n. 1
0
 def test_bold(self):
     """
     The bold formatting attribute, L{A.bold}, emits the VT102 control
     sequence to enable bold when flattened.
     """
     self.assertEqual(text.assembleFormattedText(A.bold['Hello, world.']),
                      '\x1b[1mHello, world.')
Esempio n. 2
0
 def test_trivial(self):
     """
     Using no formatting attributes produces no VT102 control sequences in
     the flattened output.
     """
     self.assertEqual(text.assembleFormattedText(A.normal['Hello, world.']),
                      'Hello, world.')
Esempio n. 3
0
 def test_blink(self):
     """
     The blink formatting attribute, L{A.blink}, emits the VT102 control
     sequence to enable blinking when flattened.
     """
     self.assertEqual(text.assembleFormattedText(A.blink['Hello, world.']),
                      '\x1b[5mHello, world.')
Esempio n. 4
0
 def test_underline(self):
     """
     The underline formatting attribute, L{A.underline}, emits the VT102
     control sequence to enable underlining when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.underline['Hello, world.']),
         '\x1b[4mHello, world.')
Esempio n. 5
0
 def test_bold(self):
     """
     The bold formatting attribute, L{A.bold}, emits the VT102 control
     sequence to enable bold when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.bold['Hello, world.']),
         '\x1b[1mHello, world.')
Esempio n. 6
0
 def test_trivial(self):
     """
     Using no formatting attributes produces no VT102 control sequences in
     the flattened output.
     """
     self.assertEqual(
         text.assembleFormattedText(A.normal['Hello, world.']),
         'Hello, world.')
Esempio n. 7
0
 def test_underline(self):
     """
     The underline formatting attribute, L{A.underline}, emits the VT102
     control sequence to enable underlining when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.underline['Hello, world.']),
         '\x1b[4mHello, world.')
Esempio n. 8
0
 def test_reverseVideo(self):
     """
     The reverse-video formatting attribute, L{A.reverseVideo}, emits the
     VT102 control sequence to enable reversed video when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.reverseVideo['Hello, world.']),
         '\x1b[7mHello, world.')
Esempio n. 9
0
 def test_blink(self):
     """
     The blink formatting attribute, L{A.blink}, emits the VT102 control
     sequence to enable blinking when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.blink['Hello, world.']),
         '\x1b[5mHello, world.')
Esempio n. 10
0
 def test_reverseVideo(self):
     """
     The reverse-video formatting attribute, L{A.reverseVideo}, emits the
     VT102 control sequence to enable reversed video when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.reverseVideo['Hello, world.']),
         '\x1b[7mHello, world.')
Esempio n. 11
0
 def test_background(self):
     """
     The background color formatting attribute, L{A.bg}, emits the VT102
     control sequence to set the selected background color when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.normal[A.bg.red['Hello, '],
                                             A.bg.green['world!']]),
         '\x1b[41mHello, \x1b[42mworld!')
Esempio n. 12
0
 def test_background(self):
     """
     The background color formatting attribute, L{A.bg}, emits the VT102
     control sequence to set the selected background color when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.normal[A.bg.red["Hello, "], A.bg.green["world!"]]),
         "\x1b[41mHello, \x1b[42mworld!",
     )
Esempio n. 13
0
 def test_foreground(self):
     """
     The foreground color formatting attribute, L{A.fg}, emits the VT102
     control sequence to set the selected foreground color when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(
             A.normal[A.fg.red['Hello, '], A.fg.green['world!']]),
         '\x1b[31mHello, \x1b[32mworld!')
Esempio n. 14
0
 def test_minus(self):
     """
     Formatting attributes prefixed with a minus (C{-}) temporarily disable
     the prefixed attribute, emitting no VT102 control sequence to enable
     it in the flattened output.
     """
     self.assertEqual(
         text.assembleFormattedText(
             A.bold[A.blink['Hello', -A.bold[' world'], '.']]),
         '\x1b[1;5mHello\x1b[0;5m world\x1b[1;5m.')
Esempio n. 15
0
 def test_foreground(self):
     """
     The foreground color formatting attribute, L{A.fg}, emits the VT102
     control sequence to set the selected foreground color when flattened.
     """
     self.assertEqual(
         text.assembleFormattedText(A.normal[A.fg.red["Hello, "],
                                             A.fg.green["world!"]]),
         "\x1b[31mHello, \x1b[32mworld!",
     )
Esempio n. 16
0
 def test_minus(self):
     """
     Formatting attributes prefixed with a minus (C{-}) temporarily disable
     the prefixed attribute, emitting no VT102 control sequence to enable
     it in the flattened output.
     """
     self.assertEqual(
         text.assembleFormattedText(A.bold[A.blink["Hello", -A.bold[" world"], "."]]),
         "\x1b[1;5mHello\x1b[0;5m world\x1b[1;5m.",
     )
Esempio n. 17
0
 def _draw_title(self):
     terminal = self.terminal
     dlg_left = self.left
     dlg_top = self.top
     dlg_w = self.width
     dlg_h = self.height
     title = self.dlg_title
     emca48 = A.bold[title, -A.bold[""]]
     text = assembleFormattedText(emca48)
     pos = dlg_left + (dlg_w - len(title)) // 2
     row = dlg_top
     terminal.cursorPosition(pos, row)
     terminal.write(text)
Esempio n. 18
0
 def _update_instructions(self):
     """
     Display instructions to the player.
     """
     terminal = self.terminal
     tw, th = self.term_size
     instructions = self.instructions
     text_lines = instructions.split("\n")
     instructions = []
     for text_line in text_lines:
         lines = utils.wrap_paras(text_line, width=(tw - 4))
         instructions.extend(lines)
     row = 6
     maxrow = 14
     maxwidth = max(len(line) for line in instructions)
     pos = (tw - (maxwidth + 4)) // 2
     terminal.cursorPosition(pos, row)
     terminal.write(gchars.DHBORDER_UP_LEFT)
     terminal.write(gchars.DBORDER_HORIZONTAL * (maxwidth + 2))
     terminal.write(gchars.DHBORDER_UP_RIGHT)
     title = "Instructions"
     terminal.cursorPosition((tw - len(title)) // 2, row)
     terminal.write(title)
     row += 1
     for line in instructions:
         if row > maxrow:
             break
         terminal.cursorPosition(pos, row)
         terminal.write(gchars.VERTICAL)
         terminal.write(" ")
         terminal.write(line)
         terminal.write(" ")
         terminal.cursorPosition(pos + maxwidth + 3, row)
         terminal.write(gchars.VERTICAL)
         row += 1
     terminal.cursorPosition(pos, row)
     terminal.write(gchars.DHBORDER_DOWN_LEFT)
     terminal.write(gchars.DBORDER_HORIZONTAL * (maxwidth + 2))
     terminal.write(gchars.DHBORDER_DOWN_RIGHT)
     if self.new_chat_flag:
         msg = "New Chat Message"
         pos = (tw - len(msg)) // 2
         row = 14
         emca48 = A.bold[msg, -A.bold[""]]
         text = assembleFormattedText(emca48)
         terminal.cursorPosition(pos, row)
         terminal.write(text)
Esempio n. 19
0
 def _update_player_area(self):
     """
     Set the player name as the title of the window.
     """
     player = self.user_id
     terminal = self.terminal
     tw, th = self.term_size
     max_len = tw - 2
     if len(player) > max_len:
         player = player[:max_len]
     pos = (tw - len(player)) // 2
     terminal.cursorPosition(pos, 0)
     terminal.saveCursor()
     #reverseVideo, underline, bold
     player_text = assembleFormattedText(A.bold[A.fg.blue[player]])
     terminal.write(player_text)
     terminal.restoreCursor()
Esempio n. 20
0
 def _draw_prompt(self):
     terminal = self.terminal
     dlg_left = self.left
     dlg_top = self.top
     dlg_w = self.width
     dlg_h = self.height
     equator = self.equator
     pos = dlg_left + 2
     row = dlg_top + 1
     prompt = self.prompt
     terminal.cursorPosition(pos, row)
     terminal.write(prompt)
     input_buf = self.input_buf
     line = ''.join(input_buf)
     if line is not None:
         terminal.write(" ")
         terminal.write(line)
     output_buf = self.output_buf
     row = equator + 2
     pos = dlg_left + 2
     filled = False
     for user_id, msg in reversed(output_buf):
         prefix = "[{}]: ".format(user_id)
         prefix_len = len(prefix)
         lines = wrap_paras(prefix + msg, dlg_w - 4)
         terminal.cursorPosition(pos, row)
         first = False
         for line in lines:
             if not first:
                 line = line[prefix_len:]
                 emca48 = A.bold[prefix, -A.bold[""]]
                 text = assembleFormattedText(emca48)
                 terminal.write(text)
                 first = False
             if row == (dlg_top + dlg_h - 2):
                 terminal.write("...")
                 filled = True
                 break
             terminal.write(line)
         row += 1
         if filled:
             break
Esempio n. 21
0
    def _draw_widgets(self):
        terminal = self.terminal
        dlg_left = self.left
        dlg_top = self.top
        dlg_w = self.width
        dlg_h = self.height
        werewolves = self.werewolves
        role_flags = self._get_role_flags()
        row = self.equator + 2
        col_w = (dlg_w - 2) // 2

        def bool2yn(b):
            if b:
                return "Y"
            else:
                return "N"

        flags = [
            [("Seer:", bool2yn(role_flags['seer'])),
             ("Robber:", bool2yn(role_flags['robber']))],
            [("Troublemaker:", bool2yn(role_flags['troublemaker'])),
             ("Minion:", bool2yn(role_flags['minion']))],
            [("Insomniac:", bool2yn(role_flags['insomniac'])),
             ("Hunter:", bool2yn(role_flags['hunter']))],
            [("Tanner:", bool2yn(role_flags['tanner'])),
             ("Werewolves:", str(werewolves))],
        ]
        label_len = 0
        for rinfo in flags:
            for label, flag in rinfo:
                label_len = max(label_len, len(label))
        label_len += 2
        for rinfo in flags:
            row += 1
            for n, (label, flag) in enumerate(rinfo):
                pos = dlg_left + 2 + n * col_w
                terminal.cursorPosition(pos, row)
                emca48 = A.bold[label, -A.bold[""]]
                text = assembleFormattedText(emca48)
                terminal.write(text)
                terminal.cursorPosition(pos + label_len, row)
                terminal.write(flag)
Esempio n. 22
0
 def draw(self):
     """
     Show help.
     """
     terminal = self.terminal
     tw, th = self.term_size
     help_w = int(tw * 0.8)
     help_h = int(th * 0.6)
     help_top = (th - help_h) // 2
     help_left = (tw - help_w) // 2
     self.left = help_left
     self.top = help_top
     pos = help_left
     row = help_top
     terminal.cursorPosition(pos, row)
     terminal.write(gchars.DBORDER_UP_LEFT)
     terminal.write(gchars.DBORDER_HORIZONTAL * (help_w - 2))
     terminal.write(gchars.DBORDER_UP_RIGHT)
     for n in range(help_h - 2):
         row += 1
         terminal.cursorPosition(pos, row)
         terminal.write(gchars.DBORDER_VERTICAL)
         terminal.write(" " * (help_w - 2))
         terminal.write(gchars.DBORDER_VERTICAL)
     row += 1
     terminal.cursorPosition(pos, row)
     terminal.write(gchars.DBORDER_DOWN_LEFT)
     terminal.write(gchars.DBORDER_HORIZONTAL * (help_w - 2))
     terminal.write(gchars.DBORDER_DOWN_RIGHT)
     msg = "Available Commands"
     emca48 = A.underline[msg, -A.underline[""]]
     heading = assembleFormattedText(emca48)
     text = textwrap.dedent("""\
         h        - This help.
         q or ESC - Quit dialog.
         TAB      - Toggle chat window. 
         CTRL-A   - Session admin mode.  Change game settings / restart.
         CTRL-X   - Quit to lobby.
         CTRL-D   - Disconnect (may reconnect later).
         """)
     lines = wrap_paras(text, help_w - 4)
     row_count = len(lines) + 2
     row = help_top + max((help_h - row_count) // 2, 1)
     pos = help_left + (help_w - len(msg)) // 2
     terminal.cursorPosition(pos, row)
     terminal.write(heading)
     row += 2
     text_w = max(len(line) for line in lines)
     pos = help_left + (help_w - text_w) // 2
     for line in lines:
         row += 1
         terminal.cursorPosition(pos, row)
         if row == (help_top + help_h) - 2:
             terminal.write("...")
             break
         terminal.write(line)
     footer = "Press any key to close help."
     pos = help_left + (help_w - len(footer)) // 2
     row = help_top + help_h - 2
     terminal.cursorPosition(pos, row)
     emca48 = A.bold[footer, -A.bold[""]]
     text = assembleFormattedText(emca48)
     terminal.write(text)
     terminal.cursorPosition(0, th - 1)
Esempio n. 23
0
 def show_dialog(self):
     parent = self.parent
     title = self.title
     terminal = self.parent.terminal
     tw, th = self.parent.term_size
     row = self.start_row
     dialog_x = 2
     dialog_w = tw - 4
     pos = dialog_x
     terminal.cursorPosition(pos, row)
     terminal.write(parent.DBORDER_UP_LEFT)
     terminal.write(parent.DBORDER_HORIZONTAL * (tw - 6))
     terminal.write(parent.DBORDER_UP_RIGHT)
     pos = (tw - len(title)) // 2
     terminal.cursorPosition(pos, row)
     terminal.write(title)
     msg = textwrap.dedent(u"""\
         {} - Scroll up       {}   - Scroll down
         i - invite player   q - cancel 
         """).format(parent.UP_ARROW, parent.DOWN_ARROW).encode('utf-8')
     textlines = msg.split("\n")
     termlines = []
     for textline in textlines:
         lines = textwrap.wrap(textline,
                               width=(tw - 4),
                               replace_whitespace=False)
         termlines.extend(lines)
     maxw = max(len(line) for line in termlines)
     row += 1
     self._blank_dialog_line(row)
     row += 1
     pos = (tw - maxw) // 2
     for line in termlines:
         self._blank_dialog_line(row)
         terminal.cursorPosition(pos, row)
         terminal.write(line)
         row += 1
     self._blank_dialog_line(row)
     row += 1
     self._blank_dialog_line(row)
     players = self.players
     player_count = len(players)
     player_pos = self.player_pos
     for n in range(player_pos - 1, player_pos + 2):
         if n < 0 or n >= player_count:
             player = " "
         else:
             player = players[n]
         row += 1
         self._blank_dialog_line(row)
         pos = (tw - len(player)) // 2
         terminal.cursorPosition(pos, row)
         if n == player_pos:
             player = assembleFormattedText(A.reverseVideo[player])
         terminal.saveCursor()
         terminal.write(player)
         terminal.restoreCursor()
     row += 1
     self._blank_dialog_line(row)
     row += 1
     pos = dialog_x
     terminal.cursorPosition(pos, row)
     terminal.write(parent.DBORDER_DOWN_LEFT)
     terminal.write(parent.DBORDER_HORIZONTAL * (tw - 6))
     terminal.write(parent.DBORDER_DOWN_RIGHT)