Пример #1
0
def stdin_read(count):
    primary_prompt = '\001' + green('\002In [\001') + green('\002{0}\001', style='bold') + green('\002]: \001') + '\002'
    secondary_prompt = ' ' * len(str(count)) + '\001' + green('\002  ...: \001') + '\002'
    prompt = primary_prompt.format(count)

    prefill = ''
    entry = ''

    while True:
        entry += input_with_prefill(prompt, prefill) + '\n'
        prompt = secondary_prompt
        parens_count = balance(entry)
        if parens_count > 0:
            prefill = '  ' * parens_count
        else:
            yield entry
Пример #2
0
 def test_balance_nested_parens(self):
     self.assertEqual(0, utils.balance('(sfs (sfsfs) (sdf (sfs)))'))
     self.assertEqual(0, utils.balance('(sfs (sfsfs (sdf (sfs))))'))
     self.assertEqual(0, utils.balance('(((((sfs) sfsfs) sdf) sfs))'))
Пример #3
0
 def test_balance_unbalanced_parens(self):
     self.assertEqual(1, utils.balance('(sfs sfsfs sdf sfs'))
     self.assertEqual(-1, utils.balance('sfs sfsfs sdf sfs)'))
Пример #4
0
 def test_balance_single_parens(self):
     self.assertEqual(0, utils.balance('()'))
     self.assertEqual(-1, utils.balance(')('))
     self.assertEqual(0, utils.balance('  ( )   '))
     self.assertEqual(0, utils.balance('(sfs sfsfs sdf) sfs'))
Пример #5
0
 def test_balance_empty(self):
     self.assertEqual(0, utils.balance(''))
Пример #6
0
 def test_balance_nested_parens(self):
     self.assertEqual(0, utils.balance('(sfs (sfsfs) (sdf (sfs)))'))
     self.assertEqual(0, utils.balance('(sfs (sfsfs (sdf (sfs))))'))
     self.assertEqual(0, utils.balance('(((((sfs) sfsfs) sdf) sfs))'))
Пример #7
0
 def test_balance_unbalanced_parens(self):
     self.assertEqual(1, utils.balance('(sfs sfsfs sdf sfs'))
     self.assertEqual(-1, utils.balance('sfs sfsfs sdf sfs)'))
Пример #8
0
 def test_balance_single_parens(self):
     self.assertEqual(0, utils.balance('()'))
     self.assertEqual(-1, utils.balance(')('))
     self.assertEqual(0, utils.balance('  ( )   '))
     self.assertEqual(0, utils.balance('(sfs sfsfs sdf) sfs'))
Пример #9
0
 def test_balance_empty(self):
     self.assertEqual(0, utils.balance(''))