forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
54 lines (44 loc) · 1.29 KB
/
__init__.py
File metadata and controls
54 lines (44 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# java2python.lib -> common library bits.
from functools import partial
class FS(object):
""" Format string abbreviations. """
l = '{left}'
r = '{right}'
c = ':'
lc = l + c
lr = l + r
lsr = l + ' ' + r
lsrc = lsr + c
@classmethod
def op(cls, op):
""" Returns a format string for the given operation. """
l, r = cls.l, cls.r
if op == '>>>':
return '(' + l + ' & (2**32+' + l + ')) >> ' + r
if op == '>>>=':
return l + ' = bsr(' + l + ', ' + r + ')'
return l + ' ' + op + ' ' + r
escapes = {
'BLACK' : '\033[90m',
'BLUE' : '\033[94m',
'CYAN' : '\033[96m',
'GREEN' : '\033[92m',
'MAGENTA' : '\033[95m',
'NORMAL' : '\033[0m',
'RED' : '\033[91m',
'WHITE' : '\033[97m',
'YELLOW' : '\033[93m',
}
def escape(color, value):
return escapes.get(color, '') + str(value) + escapes.get('NORMAL', '')
class colors:
black = partial(escape, 'BLACK')
blue = partial(escape, 'BLUE')
cyan = partial(escape, 'CYAN')
green = partial(escape, 'GREEN')
magenta = partial(escape, 'MAGENTA')
red = partial(escape, 'RED')
white = partial(escape, 'WHITE')
yellow = partial(escape, 'YELLOW')