Back to main page
summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorMax <mahn.maxwell@gmail.com>2021-10-25 12:51:26 -0400
committerMax <mahn.maxwell@gmail.com>2021-10-25 12:51:26 -0400
commit91f766aa78037c33d662e3d3590f1c26a9af960a (patch)
tree8b29acd1f80c698d084434efab1a7c4d84322821 /main.py
initial commitHEADmain
Diffstat (limited to 'main.py')
-rw-r--r--main.py127
1 files changed, 127 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..9464e20
--- /dev/null
+++ b/main.py
@@ -0,0 +1,127 @@
+winsizeX = 75
+winsizeY = 20
+
+global show_help
+show_help = False
+password = ""
+
+help_menu = [
+"Press m to toggle help",
+"Navigation:",
+" Arrow keys,",
+" WASD,",
+" HJKL",
+"Press Enter or Space to generate a password",
+"Press Shift-Q to quit"
+]
+
+
+import random
+import curses
+import math
+from english_words import english_words_lower_alpha_set
+
+numbers_list = '0123456789'
+characters_list = '{}[]()!@#$%^&*,./<>?\\|`~-_=+\'\";:'
+
+stdscr = curses.initscr()
+curses.noecho()
+curses.curs_set(0)
+
+height, width = stdscr.getmaxyx()
+
+distanceX = width - winsizeX
+distanceY = height - winsizeY
+
+mainwin = curses.newwin(0, 0, distanceY, distanceX)
+
+mainwin.mvwin(math.floor(distanceY / 2), math.floor(distanceX / 2))
+
+curses.start_color()
+
+from config import config
+
+options = [
+# name value min max
+["Words", 2, 2, 12],
+["Numbers", 0, 0, 12],
+["Special Characters", 0, 0, 12]
+]
+
+global curspos
+curspos = 0 # cursor position
+
+def Left():
+ if options[curspos][1] > options[curspos][2]:
+ options[curspos][1] -= 1
+
+def Right():
+ if options[curspos][1] < options[curspos][3]:
+ options[curspos][1] += 1
+
+def Up():
+ global curspos
+ if curspos > 0:
+ curspos -= 1
+
+def Down():
+ global curspos
+ if curspos < len(options) - 1:
+ curspos += 1
+
+def Generate():
+ global password
+ password = ""
+ new_list = []
+
+ for i in range(options[0][1]):
+ new_list.append(random.choice(list(english_words_lower_alpha_set)))
+ for i in range(options[1][1]):
+ new_list.append(random.choice(list(numbers_list)))
+ for i in range(options[2][1]):
+ new_list.append(random.choice(list(characters_list)))
+
+ random.shuffle(new_list)
+ for item in new_list:
+ password = password + item
+
+def Render():
+ mainwin.clear()
+ mainwin.box()
+
+ mainwin.addstr(1, 1, help_menu[0], curses.color_pair(3))
+ if show_help:
+ for i in range(len(help_menu)):
+ if i == 0:
+ continue
+ mainwin.addstr(i + 1, 1, help_menu[i], curses.color_pair(3))
+ else:
+ for i in range(len(options)):
+ color = 1
+ if i == curspos:
+ mainwin.addstr(i + 2, winsizeX - 3 - len(str(options[i][1])), "<", curses.color_pair(2))
+ mainwin.addstr(i + 2, winsizeX - 2, ">", curses.color_pair(2))
+ color = 2
+ mainwin.addstr(i + 2, 1, options[i][0], curses.color_pair(color))
+ mainwin.addstr(i + 2, winsizeX - 2 - len(str(options[i][1])), str(options[i][1]), curses.color_pair(1))
+ mainwin.addstr(winsizeY - 2, 1, password)
+
+while True:
+ Render()
+ key = mainwin.getch()
+ if key in config.key_quit:
+ break
+ if key in config.key_left:
+ Left()
+ elif key in config.key_right:
+ Right()
+ elif key in config.key_up:
+ Up()
+ elif key in config.key_down:
+ Down()
+ elif key in config.key_enter:
+ Generate()
+ elif key in config.key_help:
+ show_help = not show_help
+
+curses.endwin()