Compare commits

..

1 Commits

Author SHA1 Message Date
f972b9b5cd
Update details in file header for the fork.
Also remove trailing whitespace in the header.
2025-06-01 20:59:25 -04:00

View File

@ -6,8 +6,7 @@
## \__|_|_\__,_\___(_)__|_| \__,_|_|_||_| ## \__|_|_\__,_\___(_)__|_| \__,_|_|_||_|
## ##
## tilde.train is an instance of TerminalTrain. It was originally developed ## tilde.train is an instance of TerminalTrain. It was originally developed
## by cmccabe on tilde.town (https://tildegit.org/cmccabe/TerminalTrain) but is now ## by cmccabe on tilde.town but is now maintained by vilmibm.
## maintained by vilmibm.
## ##
## If you want to contribute code improvements, create a pull request here: ## If you want to contribute code improvements, create a pull request here:
## https://git.tilde.town/vilmibm/tilde-train ## https://git.tilde.town/vilmibm/tilde-train
@ -42,8 +41,6 @@ import curses
from signal import signal, SIGINT from signal import signal, SIGINT
import time ## allowing the loop steps of train animation to be slowed import time ## allowing the loop steps of train animation to be slowed
import string ## for input validation import string ## for input validation
from inspect import cleandoc
from pathlib import Path
traincarFN = ".choochoo" traincarFN = ".choochoo"
max_x = 35 ## max length of train car. max_x = 35 ## max length of train car.
@ -54,84 +51,79 @@ print_train = False ## print train to file (instead of the screen scroll)
train = [""]*max_y ## empty train of correct height. train = [""]*max_y ## empty train of correct height.
cars = [] cars = []
engine = [ engine = r""" ____
r" ____ ", |____| ------------
r" |____| ------------", | | === | ------ |
r" | | === | ------ |", ___| |__| |_____| | O | |
r" ___| |__| |_____| | O | |", | | | |__/V\_| |
r" | | | |__/V\_| |", [[ | |
r" [[ | |", | | ------------ | ~town |
r" | | ------------ | ~town |", |__|______________|__________|
r" |__|______________|__________|", //// / _\__/__\__/__\ / \
r" //// / _\__/__\__/__\ / \ ", //// \__/ \__/ \__/ \__/ """
r"//// \__/ \__/ \__/ \__/ ", engine = engine.split("\n")
]
caboose = [ caboose = r""" ||
r" || ", ============= ||
r" ============= || ", =========| |==========
r"=========| |========== ", | ---- ---- |
r" | ---- ---- | ", | | | | | |
r" | | | | | | ", | ---- ---- |
r" | ---- ---- | ", | tilde.town railways |
r" | tilde.town railways | ", ==| |==
r"==| |== ", == - / \-/ \-----/ \-/ \ - ==
r"== - / \-/ \-----/ \-/ \ - == ", \__/ \__/ \__/ \__/ """
r" \__/ \__/ \__/ \__/ ", caboose = caboose.split("\n")
]
default_car = r""" ----------------------------
| |
| YOUR TRAIN CAR HERE! |
| Just create a |
| ~/.choochoo file! |
| __ __ __ __ |
- / \-/ \------/ \-/ \ -
\__/ \__/ \__/ \__/"""
default_car = default_car.split("\n")
default_car = [
r" ---------------------------- ",
r"| |",
r"| YOUR TRAIN CAR HERE! |",
r"| Just create a |",
r"| ~/.choochoo file! |",
r"| __ __ __ __ |",
r" - / \-/ \------/ \-/ \ - ",
r" \__/ \__/ \__/ \__/ ",
]
def print_help(): def print_help():
print( print("")
cleandoc( print("~ ~ Hooray! You've found the tilde.train! ~ ~")
f""" print("")
~ ~ Hooray! You've found the tilde.train! ~ ~ print("To add your own car to a future train, create")
print("a .choochoo file in your home directory and")
To add your own car to a future train, create print("make sure it is 'other' readable, for example:")
a .choochoo file in your home directory and print("")
make sure it is 'other' readable, for example: print(" chmod 644 ~/.choochoo")
print("")
chmod 644 ~/.choochoo print("The file should contain an ascii drawing of a")
print("train car no more than " + str(max_x) + " characters wide")
The file should contain an ascii drawing of a print("and " + str(max_y) + " characters tall.")
train car no more than {max_x} characters wide print("")
and {max_y} characters tall. print("Only printable ascii characters are accepted for now.")
print("Run the command again followed by a -t switch to test")
Only printable ascii characters are accepted for now. print("your .choochoo file and report any non accepted chars.")
Run the command again followed by a -t switch to test print("")
your .choochoo file and report any non accepted chars. print("Each train contains a random selection of cars")
print("from across tilde.town user home directories.")
Each train contains a random selection of cars print("Don't worry, yours will be coming around the")
from across tilde.town user home directories. print("bend soon!")
Don't worry, yours will be coming around the print("")
bend soon! print("~ ~ ~ ~ ~ ~")
print("")
~ ~ ~ ~ ~ ~
"""
)
)
def test_user_car(): def test_user_car():
fname = Path.home() / traincarFN username = getpass.getuser()
fname = "/home/" + username + "/" + traincarFN
try: try:
choochoo_string = fname.read_text("utf-8") myfile = open(fname, 'r')
except OSError as err: except:
raise OSError( print("ERROR: Couldn't open " + fname)
f"Couldn't open {fname}\n" print("Either it doesn't exist, or is not readble by the tilde.train script.")
"Either it doesn't exist, or is not readble by the tilde.train script." exit()
) from err
choochoo_string = myfile.read()
choochoo_list = choochoo_string.split("\n") choochoo_list = choochoo_string.split("\n")
car = "\n".join(choochoo_list) car = "\n".join(choochoo_list)
@ -166,7 +158,7 @@ def test_user_car():
print(string.printable.strip()) print(string.printable.strip())
print("") print("")
print("Yours contained " + bad_chars) print("Yours contained " + bad_chars)
sys.exit(1) exit()
# print("") # print("")
# print("Test results:") # print("Test results:")
@ -177,24 +169,27 @@ def test_user_car():
if train_height > max_y+1: if train_height > max_y+1:
print("FAIL. Your train car is too tall.") print("FAIL. Your train car is too tall.")
print("It should be no taller than " + str(max_y) + " lines in height.") print("It should be no taller than " + str(max_y) + " lines in height.")
sys.exit(1) myfile.close()
exit()
if train_length > max_x: if train_length > max_x:
print("FAIL. Your train car is too long.") print("FAIL. Your train car is too long.")
print("It should be no longer than " + str(max_x) + " characters in length.") print("It should be no longer than " + str(max_x) + " characters in length.")
sys.exit(1) myfile.close()
exit()
print("PASS. Your train car will work on the tilde.town tracks! :)") print("PASS. Your train car will work on the tilde.town tracks! :)")
sys.exit() myfile.close()
exit()
def link_car(car: list[str]): def link_car(car):
for idx,row in enumerate(car): for idx,row in enumerate(car):
car[idx] = " " + row car[idx] = " " + row
car[len(car)-3] = "+" + car[len(car)-3][1:] car[len(car)-3] = "+" + car[len(car)-3][1:]
car[len(car)-2] = "+" + car[len(car)-2][1:] car[len(car)-2] = "+" + car[len(car)-2][1:]
return car return car
def validate_car(car: list[str]): def validate_car(car):
## this function (1) checks that a train car isn't too tall or too long ## this function (1) checks that a train car isn't too tall or too long
## (2) pads it vertically or on the right side if it is too short or if ## (2) pads it vertically or on the right side if it is too short or if
## not all lines are the same length and (3) removes bad characters. ## not all lines are the same length and (3) removes bad characters.
@ -257,7 +252,7 @@ def print_all_cars():
# print "Cannot open " + fname # for debuggering purposes # print "Cannot open " + fname # for debuggering purposes
def chuggachugga(stdscr: curses.window): def chuggachugga(stdscr):
curses.curs_set(0) curses.curs_set(0)
h, w = stdscr.getmaxyx() h, w = stdscr.getmaxyx()
x_pos = w-1 x_pos = w-1
@ -299,24 +294,24 @@ def chuggachugga(stdscr: curses.window):
def handler(signal_received, frame): def handler(signal_received, frame):
print("Oops. The train broke. The engineer is looking into it!") print("Oops. The train broke. The engineer is looking into it!")
print("(Note: the train does not work in all terminals yet.)") print("(Note: the train does not work in all terminals yet.)")
sys.exit(1) exit(0)
default_car = validate_car(default_car) default_car = validate_car(default_car)
if len(sys.argv) == 2 and ("-h" in sys.argv[1] or "help" in sys.argv[1]): if len(sys.argv) == 2 and ("-h" in sys.argv[1] or "help" in sys.argv[1]):
print_help() print_help()
sys.exit() quit()
if len(sys.argv) == 2 and ("-t" in sys.argv[1] or "test" in sys.argv[1]): if len(sys.argv) == 2 and ("-t" in sys.argv[1] or "test" in sys.argv[1]):
test_user_car() test_user_car()
sys.exit() quit()
if len(sys.argv) == 2 and ("-p" in sys.argv[1] or "print" in sys.argv[1]): if len(sys.argv) == 2 and ("-p" in sys.argv[1] or "print" in sys.argv[1]):
print_train = True print_train = True
if len(sys.argv) == 2 and ("-a" in sys.argv[1] or "all" in sys.argv[1]): if len(sys.argv) == 2 and ("-a" in sys.argv[1] or "all" in sys.argv[1]):
print_all_cars() print_all_cars()
sys.exit() quit()
## start a loop that collects all .choochoo files and processes on in each loop ## start a loop that collects all .choochoo files and processes on in each loop
@ -365,7 +360,7 @@ if print_train:
print("<pre>") print("<pre>")
print(train_str) print(train_str)
print("</pre>") print("</pre>")
sys.exit() quit()
pad_str = " "*train_len pad_str = " "*train_len
train.insert(0,pad_str) train.insert(0,pad_str)