How to use the curtsies.fmtfuncs.blue 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 / testcache.py View on Github external
from curtsies.fmtfuncs import blue, red, bold, on_red

from curtsies.window import FullscreenWindow

import time

if __name__ == '__main__':

    print(blue('hey') + ' ' + red('there') + ' ' + red(bold('you')))
    n = int(sys.argv[1]) if len(sys.argv) > 1 else 100

    with FullscreenWindow() as window:
        rows, columns = window.get_term_hw()
        t0 = time.time()
        for i in range(n):
            a = [blue(on_red('qwertyuiop'[i%10]*columns)) for _ in range(rows)]
            window.render_to_terminal(a)
        t1 = time.time()
        t2 = time.time()
        for i in range(n):
            a = [blue(on_red('q'[i%1]*columns)) for _ in range(rows)]
            window.render_to_terminal(a)
        t3 = time.time()
        t4 = time.time()
        a = [blue(on_red('q'*columns)) for _ in range(rows)]
        arrays = []
        for i in range(n):
            a[i // columns] = a[i // columns].setitem(i % columns, 'x')
            arrays.append([fs.copy() for fs in a])
        for i in range(n):
            window.render_to_terminal(arrays[i])
        t5 = time.time()
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_linessplit(self):
        text = blue('the sum of the squares of the sideways')
        result = [blue('the')+blue(' ')+blue('sum'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('squares'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('sideway'),
                  blue('s')
                  ]
        self.assertEqual(linesplit(text, 7), result)
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_split(self):
        self.assertEqual(blue('hello there').split(' '), [blue('hello'), blue('there')])
        s = blue('hello there')
        self.assertEqual(s.split(' '), [s[:5], s[6:]])

        # split shouldn't create fmtstrs without chunks
        self.assertEqual(fmtstr('a').split('a')[0].chunks, fmtstr('').chunks)
        self.assertEqual(fmtstr('a').split('a')[1].chunks, fmtstr('').chunks)

        self.assertEqual((fmtstr('imp') + ' ').split('i'), [fmtstr(''), fmtstr('mp') + ' '])
        self.assertEqual(blue('abcbd').split('b'), [blue('a'), blue('c'), blue('d')])
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_linessplit(self):
        text = blue('the sum of the squares of the sideways')
        result = [blue('the')+blue(' ')+blue('sum'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('squares'),
                  blue('of')+blue(' ')+blue('the'),
                  blue('sideway'),
                  blue('s')
                  ]
        self.assertEqual(linesplit(text, 7), result)
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_split(self):
        self.assertEqual(blue('hello there').split(' '), [blue('hello'), blue('there')])
        s = blue('hello there')
        self.assertEqual(s.split(' '), [s[:5], s[6:]])

        # split shouldn't create fmtstrs without chunks
        self.assertEqual(fmtstr('a').split('a')[0].chunks, fmtstr('').chunks)
        self.assertEqual(fmtstr('a').split('a')[1].chunks, fmtstr('').chunks)

        self.assertEqual((fmtstr('imp') + ' ').split('i'), [fmtstr(''), fmtstr('mp') + ' '])
        self.assertEqual(blue('abcbd').split('b'), [blue('a'), blue('c'), blue('d')])
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_split_with_spaces(self):
        self.assertEqual(blue('a\nb').split(), [blue('a'), blue('b')])
        self.assertEqual(blue('a   \t\n\nb').split(), [blue('a'), blue('b')])
        self.assertEqual(blue('hello   \t\n\nthere').split(), [blue('hello'), blue('there')])
github bpython / curtsies / tests / test_fmtstr.py View on Github external
def test_slice(self):
        self.assertEqual(fmtstr('Hi!', 'blue')[1:2], fmtstr('i', 'blue'))
        self.assertEqual(fmtstr('Hi!', 'blue')[1:], fmtstr('i!', 'blue'))
        s = fmtstr('imp') + ' '
        self.assertEqual(s[1:], fmtstr('mp')+' ')
        self.assertEqual(blue('a\nb')[0:1], blue('a'))
github bpython / curtsies / examples / example.py View on Github external
from curtsies.window import Window
from curtsies.terminal import Terminal

if __name__ == '__main__':

    print(blue('hey') + ' ' + red('there') + ' ' + red(bold('you')))

    with Terminal(sys.stdin, sys.stdout) as tc:
        with Window(tc) as t:
            rows, columns = t.tc.get_screen_size()
            while True:
                c = t.tc.get_event()
                if c == "":
                    sys.exit() # same as raise SystemExit()
                elif c == "a":
                    a = [blue(on_red(c*columns)) for _ in range(rows)]
                elif c == "b":
                    a = t.array_from_text("a small array")
                else:
                    a = t.array_from_text("try a, b, or ctrl-D")
                t.render_to_terminal(a)
github ianmiell / autotrace / autotrace / autotrace.py View on Github external
assert draw_type in ('sessions','help','clearscreen')
		self.screen_arr = curtsies.FSArray(self.wheight, self.wwidth)
		# Header
		if self.status_message:
			header_text = 'Autotrace state: ' + invert(self.status) + ', ' + self.status_message
		else:
			header_text = 'Autotrace state: ' + invert(self.status)
		if self.colors_on:
			self.screen_arr[0:1,0:len(header_text)] = [blue(header_text)]
		else:
			self.screen_arr[0:1,0:len(header_text)] = [header_text]
		# Footer
		space = (self.wwidth - len(quick_help))*' '
		footer_text = space + quick_help
		if self.colors_on:
			self.screen_arr[self.wheight-1:self.wheight,0:len(footer_text)] = [invert(blue(footer_text))]
		else:
			self.screen_arr[self.wheight-1:self.wheight,0:len(footer_text)] = [invert(footer_text)]
		# Draw the sessions.
		if draw_type == 'sessions':
			# Is there a zoomed session? Just write that one out.
			if self.zoomed_session:
				self.do_layout('zoomed')
				self.zoomed_session.write_out_session_to_fit_pane()
			else:
				for session in self.pexpect_sessions:
					session.write_out_session_to_fit_pane()
		elif draw_type == 'help':
			self.draw_help()
		elif draw_type == 'clearscreen':
			self.clear_screen_arr()
		if not self.debug: