v1.3 init

This commit is contained in:
decoded
2022-02-22 05:44:31 -06:00
parent 889a945940
commit c3f7ee2769
13 changed files with 1004 additions and 43 deletions

View File

@@ -2,7 +2,8 @@
#################################################################################################### #######################
from glob import glob
from time import sleep
import sys,tty,os,termios
import sys,tty,os,termios,shutil
#################################################################################################### #######################
"""MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM #######################
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh+MMMMMMMMMMMMMMhsMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM #######################
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMm/ oMMMMMMMMMMMMMMm +NMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM #######################
@@ -130,7 +131,7 @@ class dr1p4ns1:
239: '92', 241: '93', 244: '94', 247: '95',
250: '96', 254: '97', 231: '98', }
########################################################################################################## CLASS INIT - 3
def __init__(self,ansifile="",width=80,height=25,debug=False):
def __init__(self,ansifile="",width=80,height=25,debug=False,pump=False):
self.DEBUG=debug
self.width=width
self.height=height
@@ -142,12 +143,14 @@ class dr1p4ns1:
self.op=[]
self.optype=[]
self.sauce_found=False
print('\x1bc')
self.pump=pump
self.boot()
######################################################################################################### FILE OPERATIONS
def fifo(self,s):
s=[s]
f=open('~/.weechat/weechat_fifo','w')
[f.write('*{}\n'.format(x)) for x in s]
f=open(f"{os.path.expanduser('~')}/.weechat/weechat_fifo","w")
[f.write("*{}\n".format(x)) for x in s]
f.close()
######################################################################################################### FILE OPERATIONS
def openansi(self,s):
@@ -281,6 +284,7 @@ class dr1p4ns1:
processed=[]
uniqued=[]
uniques=[]
codes=[]
processing=''
for i,_optype in enumerate(self.optype):
if _optype==2:
@@ -324,7 +328,6 @@ class dr1p4ns1:
gaps=int(80-len(self.stripcodes(processing)))
processing+=chr(32)*gaps
processed.append(processing)
processed_colors=[]; last_colors=''; color_fg=''; color_bg=''; color_set='';
for y,__ in enumerate(processed):
code_start=0; code_end=0; code_state=False; codes=[];
@@ -349,27 +352,104 @@ class dr1p4ns1:
color_bg=_
colors=f"{color_set}"
processed_colors.append(colors)
# last_processed_color_set=0
# for i,_ in enumerate(processed):
# line=''
# if last_processed_color_set:
# line+='\x1b[1m'
# if int(processed_colors[i]):
# line+=f'{_}\x1b[0m'
# else:
# line+=f'{_}'
# last_processed_color_set=int(processed_colors[i])
# for r in (('\x16',chr(9644)),('\x15','\u00A7')):
# line=line.replace(*r)
# print(line+f" - {str(i).zfill(3)}")
for _ in processed:
irc_processed=[]
terminal_processed=[]
color_table=[1,5,3,7,2,6,10,15,14,4,9,8,12,13,11,0];
default_fg_color=7
default_bg_color=0
codes=[]
for _ in processed:
line=_
for r in (('\x16',chr(9644)),('\x15','\u00A7')):
line=line.replace(*r)
print(line)
_line=line
bold_offset=0
bold_before=[]
bold_init=False
codes_root_popped=False
fg_color=color_table[default_fg_color]
bg_color=color_table[default_bg_color]
color_set='0'
for _ in [line[x[0]:x[1]+1] for x in zip([x for x in self.findall(line,'\x1b')],[line.find('m',x) for x in self.findall(line,'\x1b')])]:
codes.append(_)
code_values=_.split('[')[1].split(';')
code_replace=_
newcode=''
if len(irc_processed) == 19:
pass
for __ in code_values:
__=__.replace('m','')
if 0 <= int(__) <= 9:
color_set=int(__)
if color_set==1:
bold_offset=8
bold_before=[]
else:
bold_offset=0
elif 40 <= int(__) <= 49:
if bold_init and bold_offset==0:
bg_color=color_table[default_bg_color]
else:
bg_color=__
if not bold_offset==0 and not bold_init:
bold_before.append(int(bg_color))
elif 30 <= int(__) <= 39:
if bold_init and bold_offset==0:
fg_color=color_table[default_fg_color]
else:
fg_color=__~
if not bold_offset==0 and not bold_init:
bold_before.append(int(fg_color))
if bold_init and bold_offset==0:
bold_init=False
newcode='\x03'
bold_before.sort()
for _ in bold_before:
if 30 <= int(_) <= 39:
newcode += str(color_table[default_fg_color])
if 40 <= int(_) <= 49:
newcode += "," + str(color_table[default_bg_color])
elif not bold_offset == 0 and not bold_init:
newcode='\x03'
bold_before.sort()
for _ in bold_before:
if 30 <= int(_) <= 39:
newcode+=str(color_table[int(fg_color)-30+bold_offset])
if 40 <= int(_) <= 49:
newcode+=","+str(color_table[int(bg_color)-40])
bold_init=True
elif not bold_offset == 0 and bold_init:
for _ in bold_before:
if len(bold_before)==1:
if 30 <= int(_) <= 39:
bold_before.append(int(bg_color))
else:
bold_before.append(int(fg_color))
# else:
# print('how are you here')
newcode='\x03'
bold_before.sort()
for _ in bold_before:
if 30 <= int(_) <= 39:
newcode+=str(color_table[int(fg_color)-30+bold_offset])
if 40 <= int(_) <= 49:
newcode+=","+str(color_table[int(bg_color)-40])
pass
else:
pass #non-bold-operations
if len(codes) == 1 and not codes_root_popped:
if color_set == 0:
_line=_line.replace(codes[-1],"",1)
codes_root_popped=True
else:
_line=_line.replace(code_replace,newcode,1)
irc_processed.append(_line)
terminal_processed.append(line)
for _ in terminal_processed:
print(_)
if self.pump:
for i,theline in enumerate(irc_processed):
self.fifo(theline)
#################################################################################################################### TOOL
def getsauce(self,sauce):
self.sauce=sauce
@@ -387,12 +467,6 @@ class dr1p4ns1:
offset+=20
self.sauce_date=self.sauce[offset:offset+8].strip()
offset+=8
# SAUCE_PASS='\x1b[1;31m[ SAUCE INFO FOUND ] - X: {} Y: {}\x1b[0m\n'
# SAUCE_FAIL='\x1b[1;31m[ NO SAUCE INFO FOUND ]\x1b[0m\n'
# if self.sauce_found==True:
# print(SAUCE_PASS.format(self.width,self.height))
# else:
# print(SAUCE_FAIL.format(self))
#################################################################################################################### TOOL
def findall(self,s,w):
return [i for i in range(len(s)) if s.startswith(w, i)]
@@ -478,20 +552,24 @@ def getkey():
else:
k = ord(b)
key_mapping = {
112: 'p',
27: 'esc',
67: 'right',
68: 'left',
113: 'q',
120: 'x'
120: 'x',
99: 'c',
82: 'R'
}
return key_mapping.get(k, chr(k))
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
################################################################################################################### ENTRY - 1
if __name__ == "__main__":
#######################################
if len(sys.argv) > 1:
PATH=''
if sys.argv[1]=='.':
if sys.argv[1]=='.':
PATH=os.getcwd()
files=glob(PATH+"/*.ans")
files+=glob(PATH+"/*.ANS")
@@ -501,31 +579,68 @@ if __name__ == "__main__":
else:
files=glob('ansiscii/*.ans')
files+=glob('ansiscii/*.ANS')
#######################################
if len(files)==0:
print('ERROR: NO ANSI FILES IN THE PATH SPECIFIED',end='')
sys.exit(1)
#######################################
index=0
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
try:
print(f'loading: {files[index]}')
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
except:
pass
#######################################
try:
while True:
B='\x1b[1;94m'; C='\x1b[1;94m'; S='\x1b[1;36m'; M='\x1b[1;92m'; E='\x1b[0m'
msg=f"{B}[ {C}DR1P {B}] {S}- {B}[ {C}q{S}: {M}quit{S}, {C}left{S}: {M}previous{S}, {C}right{S}: {M}next {B}] {S}- {C}filename{S}: {M}"
msg=f"{B}[ {C}DR1P {B}] {S}- {B}[ {C}q{S}: {M}quit{S}, {C}c{S}: {M}copy{S}, {C}R{S}: {M}remove{S}, {C}p{S}: {M}pump{S}, {C}left{S}: {M}previous{S}, {C}right{S}: {M}next {B}] {S}- {C}filename{S}: {M}"
msg+=f"{d.filename}{E}"
print(msg)
k = getkey()
if k == 'left':
index-=1
if index < 0: index=len(files)-1
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
if k == 'right':
try:
print(f'{C}loading{B}: {S}{files[index]}')
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
except:
pass
elif k == 'right':
index+=1
if index >= len(files): index=0
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
if k == 'esc' or k == 'q' or k == 'x':
try:
print(f'{C}loading{B}: {S}{files[index]}')
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
except:
pass
elif k == 'esc' or k == 'q' or k == 'x':
quit()
elif k == 'R':
print('file removed: placed in /tmp directory')
sleep(3)
shutil.copyfile(d.filename,f'/tmp/{str(d.filename).split("/")[1]}')
os.remove(d.filename)
elif k == 'p':
print('pump') #
d=dr1p4ns1(ansifile=files[index],width=80,debug=False,pump=True)
sleep(1)
elif k == 'c':
try:
shutil.copyfile(d.filename,f'pump/{str(d.filename).split("/")[1]}')
print(f'{C}file copied to pump directory')
except:
print(f'{M}file was not copied')
else:
index+=1
if index >= len(files): index=0
try:
d=dr1p4ns1(ansifile=files[index],width=80,debug=False)
except:
pass
#######################################
except (KeyboardInterrupt, SystemExit):
os.system('stty sane')
#######################################
######################################################################################################################### EOF