Skip to content

Commit

Permalink
Working on input
Browse files Browse the repository at this point in the history
  • Loading branch information
BhJaipal committed Oct 1, 2024
1 parent 9fa5e26 commit 8c517e5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 28 deletions.
3 changes: 3 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
blessed==1.20.0
six==1.16.0
wcwidth==0.2.13
101 changes: 73 additions & 28 deletions scripts/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@
import os

term = blessed.Terminal()
spaces = " "
for i in range(int((term.width - len("████████║ ██║ ██║ ██║ ██║ ██║"))/2)-1):
spaces += " "
spaces: str = " "
for i in range(
int((term.width - len("████████║ ██║ ██║ ██║ ██║ ██║")) / 2) - 1
):
spaces += " "

def lineSpace(n=1):
lineSpaces = ""
for i in range(n*(term.height-5)//4):
lineSpaces += " "
for _ in range(term.width-1):
lineSpaces += " "
lineSpaces += "\n"
lineSpaces= lineSpaces[:-1]
commands: str = ""


def lineSpace(n: float = 1 / 4, isEnd=False):
lineSpaces = ""
global commands
for i in range(
int(n * (term.height - 5)) - (0 if commands == "" or not isEnd else 2)
):
lineSpaces += " "
for _ in range(term.width - 1):
lineSpaces += " "
lineSpaces += "\n"
lineSpaces = lineSpaces[:-1]
return lineSpaces

return lineSpaces

print(term.home + term.clear + term.move_y(term.height))

Expand All @@ -31,23 +39,60 @@ def lineSpace(n=1):
term.fullscreen()
print(term.blue_on_lightblue(lineSpace()))
print(term.blue_on_lightblue((logo[1:-1])))
print(term.blue_on_lightblue(lineSpace(3)))
commands = ""
print(term.blue_on_lightblue(lineSpace(3 / 4)))


def takeInput():
try:
with term.cbreak(), term.hidden_cursor():
inp = term.inkey()
if inp == ":":
global commands
commands+= ":"
if inp != "q":
takeInput()
else:
term.clear
except KeyboardInterrupt:
print("Process exited")
exit(1)
try:
global commands
if commands != "":
os.system("clear")
term.fullscreen()
print(term.blue_on_lightblue(lineSpace()))
print(term.blue_on_lightblue((logo[1:-1])))
if commands.__len__() != 0:
print(term.blue_on_lightblue(lineSpace(1 / 5, True)))
print(
term.bold_blue_on_lightblue(term.center("┌─────────────────────┐"))
)
print(
term.bold_blue_on_lightblue(
term.center("│ " + commands + " " * (20 - len(commands)) + "│")
)
)
print(
term.bold_blue_on_lightblue(term.center("└─────────────────────┘"))
)
print(term.blue_on_lightblue(lineSpace(1 / 2)))
else:
print(term.blue_on_lightblue(lineSpace(3 / 4)))
with term.cbreak(), term.hidden_cursor():
inp = term.inkey()
if ord(inp) == 27:
commands = ""
takeInput()
if ord(inp) >= 32 and ord(inp) <= 126:
commands += inp
if inp.name == "KEY_BACKSPACE":
if commands.__len__() == 1:
commands = ""
elif commands.__len__() > 1:
commands = commands[:-1]
takeInput()
if inp.name == "KEY_ENTER":
print(commands)
if commands != ":q":
takeInput()
else:
os.system("clear")
exit(0)
else:
term.clear
takeInput()
except KeyboardInterrupt:
print("Process exited")
os.system("clear")
exit(1)


takeInput()
os.system("clear")

0 comments on commit 8c517e5

Please sign in to comment.