diff --git a/webgen.py b/webgen.py index 3e0c50a..3029b61 100755 --- a/webgen.py +++ b/webgen.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import sys, os, uuid, shutil, subprocess, markdown, re, datetime, locale, glob +import sys, os, uuid, shutil, signal, subprocess, markdown, re, datetime, locale, glob from dialog import Dialog @@ -11,6 +11,12 @@ sourcedir = os.path.expanduser("~/python/webgen/") fileending = "" locale.setlocale(locale.LC_ALL, "") clear = "\x1b[2J\x1b[H" +green = "\x1b[38;5;46m" +red = "\x1b[38;5;9m" +yellow = "\x1b[38;5;226m" +greenonblack = "\x1b[38;5;46m\x1b[48;5;16m" +redonblack = "\x1b[38;5;9m\x1b[48;5;16m" + xwidth = os.get_terminal_size()[0] - 3 ywidth = os.get_terminal_size()[1] - 3 os.chdir(sourcedir) @@ -24,6 +30,16 @@ creationtimeheader = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") # Initialize a dialog.Dialog instance d = Dialog(dialog="dialog") +# Let's stop everything at CTRL-c + + +def sigint_handler(signum, frame): + sys.exit(yellow + "\nPfff....I'll tell your mom!\n") + + +signal.signal(signal.SIGINT, sigint_handler) + + # call favorite editor with filename to write the text def edit(headline): editor = os.getenv("EDITOR") @@ -57,14 +73,17 @@ def selectfile(): if ausgewaehlt[0] == "cancel": newtopic = d.inputbox("Ok, gib hier ein neues Thema an:", width=xwidth, height=ywidth, title="Ein Thema wählen:", cancel="Exit") if newtopic[0] == "cancel" or newtopic[1] == "": - sys.exit("Na, dann eben nicht...") + sys.exit(yellow + "Na, dann eben nicht...") headline = newtopic[1] else: headline = "" # Clean filename from leading .md for later construction of a headline if headline == "": + headline = re.sub("\.md$", "", tabelle[int(ausgewaehlt[1])][1]) + print(headline) + a = input(yellow + "What do we dooo here?") # if the searched filename doesnt match an existing file we construct a new one if len(glob.glob(sourcedir + headline + ".md")) == 0: @@ -105,27 +124,29 @@ for wish in optwords: if len(args) == 1: headline = args[0] inputfile = headline + ".md" - outputfile = glob.glob(targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + headline + "*") + outputfile = glob.glob( + targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + headline + "*" + fileending + ) outputfilelength = len(outputfile) if outputfilelength >= 1: outputfile = outputfile[outputfilelength - 1] else: - outputfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline + outputfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline + fileending elif len(args) == 0: selection = selectfile() inputfile = selection[0] - outputfile = selection[1] + outputfile = selection[1] + fileending headline = selection[2] elif len(args) > 1: - sys.exit("Too much or wrong parameters:\n" + myname + ' [--html] [--stdout] ["Some Topic"] ') + sys.exit(red + "Too much or wrong parameters:\n" + yellow + myname + ' [--html] [--stdout] ["Some Topic"] ') # This is informal asking yes/no for editing the text if outfile == sys.stdout: outputfile = "STDOUT" -print("\nYou will edit now: '" + inputfile + "'\nOutputfile= '" + outputfile + "'") +print(yellow + "\nYou will edit now: '" + green + inputfile + yellow + "'\nOutputfile= '" + green + outputfile + "'") a = input("\nPress to continue or to stop: ") edit(inputfile)