How to use the curtsies.fmtfuncs.green function in curtsies

To help you get started, we’ve selected a few curtsies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpython / curtsies / examples / gameexample.py View on Github external
def __init__(self, width, height):
        self.width = width
        self.height = height
        n = 5
        self.player = Entity(on_blue(green(bold(u'5'))), width // 2, height // 2 - 2, speed=5)
        self.npcs = [Entity(on_blue(red(u'X')), i * width // (n * 2), j * height // (n * 2))
                     for i in range(1, 2*n, 2)
                     for j in range(1, 2*n, 2)]
        self.turn = 0
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_right_sequence_in_py3(self):
        red_on_blue = fmtstr('hello', 'red', 'on_blue')
        blue_on_red = fmtstr('there', fg='blue', bg='red')
        green_s = fmtstr('!', 'green')
        full = red_on_blue + ' ' + blue_on_red + green_s
        self.assertEqual(full, on_blue(red("hello"))+" "+on_red(blue("there"))+green("!"))
        self.assertEqual(str(full), '\x1b[31m\x1b[44mhello\x1b[49m\x1b[39m \x1b[34m\x1b[41mthere\x1b[49m\x1b[39m\x1b[32m!\x1b[39m')
github bpython / curtsies / tests / test_fmtstr.py View on Github external
b = fmtstr(u'ab', 'blue', 'on_red', 'bold')
        g = fmtstr(u'cd', 'green', 'on_red', 'bold')
        s = b + g
        self.assertEqual(s.ljust(6), b + g + on_red('  '))
        self.assertEqual(s.rjust(6), on_red('  ') + b + g)

        # doesn't add empties to end
        self.assertEqual(s.ljust(4), b + g)
        self.assertEqual(s.rjust(4), b + g)

        # behavior if background different
        s = on_blue('a') + on_green('b')
        self.assertEqual(s.ljust(3), fmtstr('ab '))
        self.assertEqual(s.rjust(3), fmtstr(' ab'))
        s = blue(on_blue('a')) + green(on_green('b'))
        self.assertEqual(s.ljust(3), blue('a') + green('b') + fmtstr(' '))
        self.assertEqual(s.rjust(3), fmtstr(' ') + blue('a') + green('b'))

        #using fillchar
        self.assertEqual(s.ljust(3, '*'), fmtstr('ab*'))
        self.assertEqual(s.rjust(3, '*'), fmtstr('*ab'))
github bpython / curtsies / tests / test_fmtstr.py View on Github external
""""""
        b = fmtstr(u'ab', 'blue', 'on_red', 'bold')
        g = fmtstr(u'cd', 'green', 'on_red', 'bold')
        s = b + g
        self.assertEqual(s.ljust(6), b + g + on_red('  '))
        self.assertEqual(s.rjust(6), on_red('  ') + b + g)

        # doesn't add empties to end
        self.assertEqual(s.ljust(4), b + g)
        self.assertEqual(s.rjust(4), b + g)

        # behavior if background different
        s = on_blue('a') + on_green('b')
        self.assertEqual(s.ljust(3), fmtstr('ab '))
        self.assertEqual(s.rjust(3), fmtstr(' ab'))
        s = blue(on_blue('a')) + green(on_green('b'))
        self.assertEqual(s.ljust(3), blue('a') + green('b') + fmtstr(' '))
        self.assertEqual(s.rjust(3), fmtstr(' ') + blue('a') + green('b'))

        #using fillchar
        self.assertEqual(s.ljust(3, '*'), fmtstr('ab*'))
        self.assertEqual(s.rjust(3, '*'), fmtstr('*ab'))
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_immutibility_of_FmtStr(self):
        a = fmtstr('hi', 'blue')
        b = green(a)
        self.assertEqual(a.shared_atts['fg'], FG_COLORS['blue'])
        self.assertEqual(b.shared_atts['fg'], FG_COLORS['green'])
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_various_splices(self):
        a = blue('hi')
        b = a + green('bye')
        c = b + red('!')
        self.assertEqual(c.splice('asdfg', 1),
                         blue('h')+'asdfg'+blue('i')+green('bye')+red('!'))
        self.assertEqual(c.splice('asdfg', 1, 4),
                         blue('h')+'asdfg'+green('e')+red('!'))
        self.assertEqual(c.splice('asdfg', 1, 5),
                         blue('h')+'asdfg'+red('!'))
github bpython / curtsies / examples / chat.py View on Github external
def render(self):
        return linesplit(green(''.join(s.decode('latin-1') for s in self.received)), 80) if self.received else ['']
github bpython / curtsies / examples / gameexample.py View on Github external
"""Returns a message to be displayed if game is over, else None"""
        for npc in self.npcs:
            self.move_entity(npc, *npc.towards(self.player))
        for entity1, entity2 in itertools.combinations(self.entities, 2):
            if (entity1.x, entity1.y) == (entity2.x, entity2.y):
                if self.player in (entity1, entity2):
                    return 'you lost on turn %d' % self.turn
                entity1.die()
                entity2.die()

        if all(npc.speed == 0 for npc in self.npcs):
            return 'you won on turn %d' % self.turn
        self.turn += 1
        if self.turn % 20 == 0:
            self.player.speed = max(1, self.player.speed - 1)
            self.player.display = on_blue(green(bold(unicode_str(self.player.speed))))
github ianmiell / autotrace / autotrace / autotrace.py View on Github external
else:
			session_1_command = None
		if num_commands > 2:
			session_2_command = args.commands[2]
		if num_commands > 3:
			session_3_command = args.commands[3]
		remaining_commands    = args.commands[4:]
		self.vertically_split = args.v
		logtimestep           = args.logtimestep
		assert not args.v or session_2_command is None, 'BUG! Vertical arg should be off at this point if session_2 exists'
		args = None
		# Args, collected, set up commands and sessions

		# Setup command information, and keep a count of sessions
		session_count = 0
		main_session = PexpectSession(main_command, self, session_count, pane_name='top_left', pane_color=green, logtimestep=logtimestep)
		main_session.spawn()
		session_count += 1
		if session_1_command is None:
			if platform.system() == 'Darwin':
				#session_1_command = 'dtruss -f -p ' + str(main_session.pid)
				session_1_command = 'iostat 1'
			else:
				session_1_command = 'strace -tt -f -p ' + str(main_session.pid)
		else:
			session_1_command = replace_pid(session_1_command, str(main_session.pid))
		PexpectSession(session_1_command, self, session_count, pane_name='bottom_left', logtimestep=logtimestep)
		session_count += 1
		if session_2_command is not None:
			session_2_command = replace_pid(session_2_command, str(main_session.pid))
			PexpectSession(session_2_command, self, session_count, pane_name='bottom_right', logtimestep=logtimestep)
			session_count += 1