mirror of
https://github.com/erkin/ponysay.git
synced 2024-11-26 06:07:59 +01:00
fully functional meta data editor
This commit is contained in:
parent
8e08ca9780
commit
82edd2297d
1 changed files with 74 additions and 32 deletions
106
ponysay-tool.py
106
ponysay-tool.py
|
@ -115,9 +115,10 @@ class PonysayTool():
|
||||||
sep = 1
|
sep = 1
|
||||||
while data[sep] != '$$$':
|
while data[sep] != '$$$':
|
||||||
sep += 1
|
sep += 1
|
||||||
meta = data[1:][:sep]
|
meta = data[1 : sep]
|
||||||
image = data[sep + 1:]
|
image = data[sep + 1:]
|
||||||
|
|
||||||
|
|
||||||
class PhonyArgParser:
|
class PhonyArgParser:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.argcount = 3
|
self.argcount = 3
|
||||||
|
@ -129,14 +130,14 @@ class PonysayTool():
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
comment = []
|
comment = []
|
||||||
for line in data:
|
for line in meta:
|
||||||
if ': ' in line:
|
if ': ' in line:
|
||||||
key = line.replace('\t', ' ')
|
key = line.replace('\t', ' ')
|
||||||
key = key[:key.find(': ')]
|
key = key[:key.find(': ')]
|
||||||
key = key.strip(' ')
|
key = key.strip(' ')
|
||||||
if key == key.upper():
|
if key == key.upper():
|
||||||
value = line.replace('\t', ' ')
|
value = line.replace('\t', ' ')
|
||||||
value = keyvalue[key.find(': ') + 2:]
|
value = value[value.find(': ') + 2:]
|
||||||
if key not in data:
|
if key not in data:
|
||||||
data[key] = value.strip(' ')
|
data[key] = value.strip(' ')
|
||||||
else:
|
else:
|
||||||
|
@ -226,7 +227,7 @@ class PonysayTool():
|
||||||
class Saver:
|
class Saver:
|
||||||
def __init__(self, ponyfile, ponyheight, ponywidth, data, image):
|
def __init__(self, ponyfile, ponyheight, ponywidth, data, image):
|
||||||
(self.ponyfile, self.ponyheight, self.ponywidth, self.data, self.image) = (ponyfile, ponyheight, ponywidth, data, image)
|
(self.ponyfile, self.ponyheight, self.ponywidth, self.data, self.image) = (ponyfile, ponyheight, ponywidth, data, image)
|
||||||
def ____(self):
|
def __call__(self): # functor
|
||||||
comment = self.data['comment']
|
comment = self.data['comment']
|
||||||
comment = ('\n' + comment + '\n').replace('\n$$$\n', '\n\\$$$\n')[:-1]
|
comment = ('\n' + comment + '\n').replace('\n$$$\n', '\n\\$$$\n')[:-1]
|
||||||
|
|
||||||
|
@ -280,22 +281,15 @@ class TextArea:
|
||||||
@param saver Save method
|
@param saver Save method
|
||||||
'''
|
'''
|
||||||
def run(self, saver):
|
def run(self, saver):
|
||||||
dispfields = [item + ': ' for item in self.fields]
|
innerleft = UCS.dispLen(max(self.fields, key = UCS.dispLen)) + self.left + 3
|
||||||
innerleft = UCS.dispLen(max(dispfields, key = UCS.dispLen)) + self.left
|
|
||||||
|
|
||||||
leftlines = []
|
leftlines = []
|
||||||
datalines = []
|
datalines = []
|
||||||
|
|
||||||
firstline = True
|
|
||||||
y = self.top
|
|
||||||
for key in self.fields:
|
for key in self.fields:
|
||||||
first = True
|
|
||||||
for line in self.datamap[key].split('\n'):
|
for line in self.datamap[key].split('\n'):
|
||||||
print('\033[%i;%iH\033[%s34m%s:\033[%s39m' % (y, self.left, '1;' if firstline else '', '>' if (key == 'comment') and not first else key, '21;' if firstline else''), end='')
|
|
||||||
leftlines.append(key)
|
leftlines.append(key)
|
||||||
datalines.append(line)
|
datalines.append(line)
|
||||||
first = firstline = False
|
|
||||||
y += 1
|
|
||||||
|
|
||||||
(termh, termw) = self.termsize
|
(termh, termw) = self.termsize
|
||||||
(y, x) = (0, 0)
|
(y, x) = (0, 0)
|
||||||
|
@ -318,20 +312,31 @@ class TextArea:
|
||||||
override = False
|
override = False
|
||||||
|
|
||||||
(oldy, oldx, oldmark) = (y, x, mark)
|
(oldy, oldx, oldmark) = (y, x, mark)
|
||||||
stored = None
|
stored = chr(ord('L') - ord('@'))
|
||||||
alerted = False
|
alerted = False
|
||||||
edited = False
|
edited = False
|
||||||
|
print('\033[%i;%iH' % (self.top + y, innerleft + x), end='')
|
||||||
while True:
|
while True:
|
||||||
if (oldmark is not None) and (oldmark >= 0):
|
if (oldmark is not None) and (oldmark >= 0):
|
||||||
if oldmark < oldx:
|
if oldmark < oldx:
|
||||||
print('\033[%i;%iH\033[49m%s\033[%i;%iH' % (self.top + oldy, innerleft + oldmark, datalines[y][oldmark : oldx], self.top + y, innerleft + x), end='')
|
print('\033[%i;%iH\033[49m%s\033[%i;%iH' % (self.top + oldy, innerleft + oldmark, datalines[oldy][oldmark : oldx], self.top + y, innerleft + x), end='')
|
||||||
elif oldmark > oldx:
|
elif oldmark > oldx:
|
||||||
print('\033[%i;%iH\033[49m%s\033[%i;%iH' % (self.top + oldy, innerleft + oldx, datalines[y][oldx : oldmark], self.top + y, innerleft + x), end='')
|
print('\033[%i;%iH\033[49m%s\033[%i;%iH' % (self.top + oldy, innerleft + oldx, datalines[oldy][oldx : oldmark], self.top + y, innerleft + x), end='')
|
||||||
if (mark is not None) and (mark >= 0):
|
if (mark is not None) and (mark >= 0):
|
||||||
if mark < x:
|
if mark < x:
|
||||||
print('\033[%i;%iH\033[44m%s\033[49m\033[%i;%iH' % (self.top + y, innerleft + mark, datalines[y][mark : x], self.top + y, innerleft + x), end='')
|
print('\033[%i;%iH\033[44;37m%s\033[49;39m\033[%i;%iH' % (self.top + y, innerleft + mark, datalines[y][mark : x], self.top + y, innerleft + x), end='')
|
||||||
elif mark > x:
|
elif mark > x:
|
||||||
print('\033[%i;%iH\033[44m%s\033[49m\033[%i;%iH' % (self.top + y, innerleft + x, datalines[y][x : mark], self.top + y, innerleft + x), end='')
|
print('\033[%i;%iH\033[44;37m%s\033[49;39m\033[%i;%iH' % (self.top + y, innerleft + x, datalines[y][x : mark], self.top + y, innerleft + x), end='')
|
||||||
|
if y != oldy:
|
||||||
|
if (oldy > 0) and (leftlines[oldy - 1] == leftlines[oldy]) and (leftlines[oldy] == leftlines[-1]):
|
||||||
|
print('\033[%i;%iH\033[34m%s\033[39m' % (self.top + oldy, self.left, '>'), end='')
|
||||||
|
else:
|
||||||
|
print('\033[%i;%iH\033[34m%s:\033[39m' % (self.top + oldy, self.left, leftlines[oldy]), end='')
|
||||||
|
if (y > 0) and (leftlines[y - 1] == leftlines[y]) and (leftlines[y] == leftlines[-1]):
|
||||||
|
print('\033[%i;%iH\033[1;34m%s\033[21;39m' % (self.top + y, self.left, '>'), end='')
|
||||||
|
else:
|
||||||
|
print('\033[%i;%iH\033[1;34m%s:\033[21;39m' % (self.top + y, self.left, leftlines[y]), end='')
|
||||||
|
print('\033[%i;%iH' % (self.top + y, innerleft + x), end='')
|
||||||
(oldy, oldx, oldmark) = (y, x, mark)
|
(oldy, oldx, oldmark) = (y, x, mark)
|
||||||
if edited:
|
if edited:
|
||||||
edited = False
|
edited = False
|
||||||
|
@ -374,7 +379,15 @@ class TextArea:
|
||||||
else:
|
else:
|
||||||
alert('No mark is activated')
|
alert('No mark is activated')
|
||||||
elif ord(d) == ord('S') - ord('@'):
|
elif ord(d) == ord('S') - ord('@'):
|
||||||
# TODO saver()
|
last = ''
|
||||||
|
for row in range(0, len(datalines)):
|
||||||
|
current = leftlines[row]
|
||||||
|
if current == last:
|
||||||
|
self.datamap[current] += '\n' + datalines[row]
|
||||||
|
else:
|
||||||
|
self.datamap[current] = datalines[row]
|
||||||
|
last = current
|
||||||
|
saver()
|
||||||
status('unmodified' + (' override' if override else ''))
|
status('unmodified' + (' override' if override else ''))
|
||||||
alert('Saved')
|
alert('Saved')
|
||||||
elif ord(d) == ord('C') - ord('@'):
|
elif ord(d) == ord('C') - ord('@'):
|
||||||
|
@ -400,7 +413,21 @@ class TextArea:
|
||||||
print('\033[%i;%iH%s%s\033[%i;%iH' % (self.top + y, innerleft, dataline, ' ' * removed, self.top + y, innerleft + x), end='')
|
print('\033[%i;%iH%s%s\033[%i;%iH' % (self.top + y, innerleft, dataline, ' ' * removed, self.top + y, innerleft + x), end='')
|
||||||
edited = True
|
edited = True
|
||||||
elif ord(d) < ord(' '):
|
elif ord(d) < ord(' '):
|
||||||
if ord(d) == ord('F') - ord('@'):
|
if ord(d) == ord('P') - ord('@'):
|
||||||
|
if y == 0:
|
||||||
|
alert('At first line')
|
||||||
|
else:
|
||||||
|
y -= 1
|
||||||
|
mark = None
|
||||||
|
x = 0
|
||||||
|
elif ord(d) == ord('N') - ord('@'):
|
||||||
|
if y == len(datalines) - 1:
|
||||||
|
datalines.append('')
|
||||||
|
leftlines.append(leftlines[-1])
|
||||||
|
y += 1
|
||||||
|
mark = None
|
||||||
|
x = 0
|
||||||
|
elif ord(d) == ord('F') - ord('@'):
|
||||||
if x < len(datalines[y]):
|
if x < len(datalines[y]):
|
||||||
x += 1
|
x += 1
|
||||||
print('\033[C', end='')
|
print('\033[C', end='')
|
||||||
|
@ -414,24 +441,39 @@ class TextArea:
|
||||||
else:
|
else:
|
||||||
alert('At beginning')
|
alert('At beginning')
|
||||||
alerted = True
|
alerted = True
|
||||||
|
elif ord(d) == ord('O') - ord('@'):
|
||||||
|
leftlines[y : y] = [leftlines[y]]
|
||||||
|
datalines[y : y] = ['']
|
||||||
|
y += 1
|
||||||
|
mark = None
|
||||||
|
x = 0
|
||||||
|
stored = chr(ord('L') - ord('@'))
|
||||||
|
elif ord(d) == ord('L') - ord('@'):
|
||||||
|
empty = '\033[0m' + (' ' * self.width + '\n') * len(datalines)
|
||||||
|
print('\033[%i;%iH%s' % (self.top, self.left, empty), end='')
|
||||||
|
for row in range(0, len(leftlines)):
|
||||||
|
leftline = leftlines[row] + ':'
|
||||||
|
if (leftlines[row - 1] == leftlines[row]) and (leftlines[row] == leftlines[-1]):
|
||||||
|
leftline = '>'
|
||||||
|
print('\033[%i;%iH\033[%s34m%s\033[%s39m' % (self.top + row, self.left, '1;' if row == y else '', leftline, '21;' if row == y else ''), end='')
|
||||||
|
for row in range(0, len(datalines)):
|
||||||
|
print('\033[%i;%iH%s\033[49m' % (self.top + row, innerleft, datalines[row]), end='')
|
||||||
|
print('\033[%i;%iH' % (self.top + y, innerleft + x), end='')
|
||||||
elif d == '\033':
|
elif d == '\033':
|
||||||
d = sys.stdin.read(1)
|
d = sys.stdin.read(1)
|
||||||
if d == '[':
|
if d == '[':
|
||||||
d = sys.stdin.read(1)
|
d = sys.stdin.read(1)
|
||||||
if d == 'C':
|
if d == 'A':
|
||||||
if x < len(datalines[y]):
|
stored = chr(ord('P') - ord('@'))
|
||||||
x += 1
|
elif d == 'B':
|
||||||
print('\033[C', end='')
|
if y == len(datalines) - 1:
|
||||||
|
alert('At last line')
|
||||||
else:
|
else:
|
||||||
alert('At end')
|
stored = chr(ord('N') - ord('@'))
|
||||||
alerted = True
|
elif d == 'C':
|
||||||
|
stored = chr(ord('F') - ord('@'))
|
||||||
elif d == 'D':
|
elif d == 'D':
|
||||||
if x > 0:
|
stored = chr(ord('B') - ord('@'))
|
||||||
x -= 1
|
|
||||||
print('\033[D', end='')
|
|
||||||
else:
|
|
||||||
alert('At beginning')
|
|
||||||
alerted = True
|
|
||||||
elif d == '2':
|
elif d == '2':
|
||||||
d = sys.stdin.read(1)
|
d = sys.stdin.read(1)
|
||||||
if d == '~':
|
if d == '~':
|
||||||
|
@ -468,7 +510,7 @@ class TextArea:
|
||||||
x = len(datalines[y])
|
x = len(datalines[y])
|
||||||
print('\033[%i;%iH' % (self.top + y, innerleft + x), end='')
|
print('\033[%i;%iH' % (self.top + y, innerleft + x), end='')
|
||||||
elif d == '\n':
|
elif d == '\n':
|
||||||
break
|
stored = chr(ord('N') - ord('@'))
|
||||||
else:
|
else:
|
||||||
insert = d
|
insert = d
|
||||||
if len(insert) == 0:
|
if len(insert) == 0:
|
||||||
|
|
Loading…
Reference in a new issue