다음 스크립트가 있습니다. 이것은 Telnet(심지어 ztelnet)과도 완벽하게 작동합니다. 문제는 다른 용어로 모든 질문에 답할 수 없다는 것입니다. Telnet 또는 ztelnet은 제외됩니다. 그래서 저는 BBS에 텔넷으로 연결하고 터미널 프로그램(igTerm)과 다음 텔넷 클라이언트를 사용하여 서버를 통해 이 스크립트를 실행합니다.https://github.com/seamiddleditch/libtelnet(텔넷 클라이언트). igTerm 또는 telnet-client와 함께 작동하도록 노력 중입니다. 나는 이것을 알아낼 수 없다. 이는 디스플레이 루틴과 관련이 있습니다. 또한 이상한 이유로 Linux 콘솔에서는 완벽하게 작동합니다. 어쨌든, 여기에 스크립트가 있습니다. 예, 여기에 "더티 코드"가 있다는 것을 알고 있습니다. :)
#!/usr/bin/env python3
from os import system
import curses
import readline
import sys
import os
import os.path
import time
from math import *
from sites import sites
commands = ["\n\n\n add ", " connect ", " information ", " help ", " quit "];
def pause():
programPause = input("[16;5H[1;37mpress <[0;37mreturn[1;37m>[0;37m [16;19H")
def execute_cmd(cmd_string):
system("clear");
a = system(cmd_string);
path = 'bbses/'
isExist = os.path.exists(path)
if not isExist:
os.makedirs(path)
print("The new directory is created!")
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
screen.keypad( 1 )
curses.init_pair(1,curses.COLOR_WHITE, curses.COLOR_BLUE)
highlightText = curses.color_pair( 1 )
normalText = curses.A_NORMAL
max_row = 10 #max number of rows
max_row2 = 5
box = curses.newwin(0,0,5,2)
option = 0;
row_num = len( sites )
row_num2 = len( commands )
pages = str( row_num / max_row )
position = 1
page = 1
for i in range( 1, max_row + 1 ):
if (i == position):
box.addstr( i, 2, str( i ) + " - " + sites[ i - 1 ][0], highlightText )
else:
box.addstr( i, 2, str( i ) + " - " + sites[ i - 1 ][0], normalText )
if i == row_num:
break
pages2 = int( ceil( row_num2 / max_row2 ) )
position2 = 1
page2 = 1
box.addstr("\n\n\n\n\n")
for j in range( 1, max_row2 + 1 ):
if (j == position2):
box.addstr(commands[ j - 1 ], highlightText )
else:
box.addstr(commands[ j - 1 ], normalText )
if j == row_num2:
break
screen.refresh()
box.refresh()
os.system("cat bbslist.ans")
x = screen.getch()
while x != ord('q') and x != ord('Q'): # Enter in ascii
if x == curses.KEY_DOWN:
if page == 1:
if position < i:
position = position + 1
option = option + 1
else:
page = page + 1
position = 1 + ( max_row * ( page - 1 ) )
elif page == pages:
if position < row_num:
position = position + 1
else:
if position < max_row + ( max_row * ( page - 1 ) ):
position = position + 1
else:
page = page + 1
position = 1 + ( max_row * ( page - 1 ) )
if x == curses.KEY_UP:
if page == 1:
if position > 1:
position = position - 1
option = option - 1
else:
if position > ( 1 + ( max_row * ( page - 1 ) ) ):
position = position - 1
else:
page = page - 1
position = max_row + ( max_row * ( page - 1 ) )
if x == curses.KEY_RIGHT:
if page2 == 1:
if position2 < j:
position2 = position2 + 1
else:
if pages2 > 1:
page2 = page2 + 1
position2 = 1 + ( max_row2 * ( page2 - 1 ) )
elif page == pages:
if position2 < row_num2:
position2 = position2 + 1
else:
if position2 < max_row2 + ( max_row2 * ( page2 - 1 ) ):
position2 = position2 + 1
else:
page2 = page2 + 1
position2 = 1 + ( max_row2 * ( page2 - 1 ) )
if x == curses.KEY_LEFT:
if page2 == 1:
if position2 > 1:
position2 = position2 - 1
else:
if position2 > ( 1 + ( max_row2 * ( page2 - 1 ) ) ):
position2 = position2 - 1
else:
page = page - 1
position2 = max_row2 + ( max_row2 * ( page2 - 1 ) )
if x == ord( "\n" ) and row_num != 0 and row_num2 != 0:
if x == 10 and position2 == 1:
curses.endwin();
print("[H[7;5H[1;30m+---------------------------------------------------------------+[0;37m")
print("[8;5H[1;30m [1;34mbbs name[1;30m : [1;37m ")
print("[9;5H[1;30m [1;34msysop name[1;30m : [1;37m ")
print("[10;5H[1;30m [1;34mtelnet or ssh[1;30m : [1;37m ")
print("[11;5H[1;30m [1;34mbbs address[1;30m : [1;37m ")
print("[12;5H[1;30m [1;34mbbs software[1;30m : [1;37m ")
print("[13;5H[1;30m [1;34mbbs theme[1;30m : [1;37m ")
print("[14;5H[1;30m [1;34mother info[1;30m : [1;37m ")
print("[15;5H[1;30m+---------------------------------------------------------------+[0;37m")
bbsname = input("[8;5H[1;30m [1;34mbbs name[1;30m : [1;37m ")
type(bbsname);
sysopname = input("[9;5H[1;30m [1;34msysop name[1;30m : [1;37m ")
type(sysopname);
protocol = input("[10;5H[1;30m [1;34mtelnet or ssh[1;30m : [1;37m ")
type(protocol)
address = input("[11;5H[1;30m [1;34mbbs address[1;30m : [1;37m ")
type(address);
software = input("[12;5H[1;30m [1;34mbbs software[1;30m : [1;37m ")
type(software);
bbstheme = input("[13;5H[1;30m [1;34mbbs theme[1;30m : [1;37m ")
type(bbstheme);
otherinfo = input("[14;5H[1;30m [1;34mother info[1;30m : [1;37m ")
type(otherinfo);
print("[15;5H[1;30m+---------------------------------------------------------------+[0;37m")
save_path = 'bbses/'
completeName = os.path.join(save_path, address)
saveFile = open(completeName,"a")
file = open("sites.py", "a+")
saveFile.write("[H[7;5H[1;30m+---------------------------------------------------------------+[0;37m")
saveFile.write("[8;5H[1;30m [1;34mbbs name[1;30m : [1;37m ")
saveFile.write(bbsname)
saveFile.write("\n")
saveFile.write("[9;5H[1;30m [1;34msysop name[1;30m : [1;37m ")
saveFile.write(sysopname)
saveFile.write("\n")
saveFile.write("[10;5H[1;30m [1;34mtelnet or ssh[1;30m : [1;37m ")
saveFile.write(protocol)
saveFile.write("\n")
saveFile.write("[11;5H[1;30m [1;34mbbs address[1;30m : [1;37m ")
saveFile.write(address)
saveFile.write("\n")
saveFile.write("[12;5H[1;30m [1;34mbbs software[1;30m : [1;37m ")
saveFile.write(software)
saveFile.write("\n")
saveFile.write("[13;5H[1;30m [1;34mbbs theme[1;30m : [1;37m ")
saveFile.write(bbstheme)
saveFile.write("\n")
saveFile.write("[14;5H[1;30m [1;34mother info[1;30m : [1;37m ")
saveFile.write(otherinfo)
saveFile.write("\n")
saveFile.write("[15;5H[1;30m+---------------------------------------------------------------+[0;37m")
saveFile.close()
system("perl -00pe 's/](?!.*])//s' sites.py > sites")
system("cat sites.py | sed -e 's/];//g' > sites")
system("mv sites sites.py")
file = open("sites.py", "a")
file.write(',')
file.write('[')
file.write('"')
file.write(bbsname)
file.write('", "')
file.write(protocol)
file.write('", "')
file.write(address)
file.write('"')
file.write(']];')
file.close()
elif x == 10 and position2 == 2:
i = position;
screen.clear();
os.system("stty raw");
execute_cmd(sites[i - 1][1] + " " + sites[i - 1][2]);
curses.endwin();
if x == 10 and position2 == 3:
i = position;
os.system("cat " + "bbses/" + sites[i - 1][2]);
pause()
curses.endwin()
if x == 10 and position2 == 4:
system("cat bbslisthelp.ans")
pause()
curses.endwin()
if x == 10 and position2 == 5:
quit(1);
box.erase()
screen.border(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ')
for i in range( 1 + ( max_row * ( page - 1 ) ), max_row + 1 + ( max_row * ( page - 1 ) ) ):
if row_num == 0:
box.addstr( 1, 1, "There aren't strings", highlightText )
else:
if ( i + ( max_row * ( page - 1 ) ) == position + ( max_row * ( page - 1 ) ) ):
box.addstr( i - ( max_row * ( page - 1 ) ), 2, str( i ) + " - " + sites[ i - 1 ][0], highlightText )
else:
box.addstr( i - ( max_row * ( page - 1 ) ), 2, str( i ) + " - " + sites[ i - 1 ][0], normalText )
if i == row_num:
break
box.addstr("\n\n\n\n\n")
for j in range( 1 + ( max_row2 * ( page2 - 1 ) ), max_row2 + 1 + ( max_row2 * ( page2 - 1 ) ) ):
if ( j + ( max_row2 * ( page2 - 1 ) ) == position2 + ( max_row2 * ( page2 - 1 ) ) ):
box.addstr(commands[ j - 1 ], highlightText )
else:
box.addstr(commands[ j - 1 ], normalText )
if j == row_num2:
break
screen.refresh()
box.refresh()
os.system("cat bbslist.ans")
x = screen.getch()
curses.endwin()
exit()