Skip to content

Commit f1842cb

Browse files
committed
Last changes in Aloo TUI
1 parent 9cfbb4e commit f1842cb

File tree

7 files changed

+220
-159
lines changed

7 files changed

+220
-159
lines changed

scripts/src/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin/)
99

1010
find_package(PkgConfig REQUIRED)
1111
pkg_check_modules(GTK4 REQUIRED gtk4)
12-
pkg_check_modules(SQLITE REQUIRED sqlite3)
1312

1413
include_directories(
1514
"$include_dir"
1615
${GTK4_INCLUDE_DIRS}
17-
${SQLITE_INCLUDE_DIRS}
1816
"/usr/include/tirpc"
1917
)
2018

@@ -23,12 +21,10 @@ add_executable(test.exe "test/main.c")
2321
target_link_libraries(app.exe
2422
"$libaloo"
2523
${GTK4_LIBRARIES}
26-
${SQLITE_LIBRARIES}
2724
)
2825
target_link_libraries(test.exe
2926
"$libaloo"
3027
${GTK4_LIBRARIES}
31-
${SQLITE_LIBRARIES}
3228
)
3329

3430
set(CMAKE_BUILD_TYPE "$ENV{Release}")

scripts/src/__init__.py

100644100755
+92-90
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
import blessed
23
import os
34
from typing import Union, Optional, Callable
@@ -32,8 +33,7 @@ def takeInput() -> None:
3233
global isCommandEnabled
3334
global exitCommand
3435
global selectedCommand
35-
os.system("clear")
36-
term.fullscreen()
36+
print("\x1b[%sH")
3737
print(term.royalblue_on_lightblue(lineSpace(1 / 6)))
3838
print(term.cornflowerblue_on_lightblue((logo[1:-1])))
3939
print(term.royalblue_on_lightblue(lineSpace(1 / 5, True)))
@@ -121,8 +121,8 @@ def takeInput() -> None:
121121
+ term.royalblue_on_lightblue("└" + infoSpaceEnd + "┘")
122122
+ term.bold_royalblue_on_lightblue(" " * ((term.width - infoLen - 4) // 2))
123123
)
124-
for i in range(6):
125-
emptyLine()
124+
125+
print(term.royalblue_on_lightblue(lineSpace(1 / 4)))
126126
if isCommandEnabled:
127127
commandSpace = ""
128128
for _ in range(int((term.width - exitCommand.__len__() - 11))):
@@ -137,55 +137,46 @@ def takeInput() -> None:
137137
emptyLine("")
138138
with term.cbreak(), term.hidden_cursor():
139139
inp = term.inkey()
140-
if inp.name is not None and inp.name == "KEY_TAB":
141-
selectedCommand = commands[activeSelection[0]]
142-
activeSelection.append(0)
143-
match selectedCommand:
144-
case "create-app":
145-
isCommandEnabled = False
146-
createApp()
147-
case "model":
148-
pass
149-
case "build":
150-
buildApp()
151-
case "run":
152-
runAnyOne()
153-
else:
154-
if inp.name is not None and inp.name == "KEY_ESCAPE":
155-
isCommandEnabled = True
156-
elif inp.name is None and isCommandEnabled:
140+
if isCommandEnabled:
141+
if inp.name is None:
157142
exitCommand += inp
158-
elif (
159-
inp.name is not None
160-
and isCommandEnabled
161-
and inp.name == "KEY_BACKSPACE"
162-
):
143+
elif inp.name == "KEY_BACKSPACE":
163144
if exitCommand.__len__() > 0:
164145
exitCommand = exitCommand[:-1]
165146
else:
166147
isCommandEnabled = False
167-
if (
168-
inp.name is not None
169-
and inp.name == "KEY_ENTER"
170-
and isCommandEnabled
171-
and exitCommand == ":q"
172-
):
173-
os.system("clear")
148+
if inp.name == "KEY_ENTER" and exitCommand == ":q":
149+
os.system("tput rmcup")
174150
exit(0)
175-
if inp.name is not None and inp.name == "KEY_DOWN":
176-
if activeSelection[0] == commands.__len__() - 1:
177-
activeSelection[0] = 0
178-
else:
179-
activeSelection[0] += 1
180-
if inp.name is not None and inp.name == "KEY_UP":
181-
if activeSelection[0] == 0:
182-
activeSelection[0] = commands.__len__() - 1
183-
else:
184-
activeSelection[0] -= 1
151+
else:
152+
if inp.name is not None:
153+
if inp.name == "KEY_ENTER":
154+
selectedCommand = commands[activeSelection[0]]
155+
activeSelection.append(0)
156+
match selectedCommand:
157+
case "create-app":
158+
isCommandEnabled = False
159+
createApp()
160+
case "build":
161+
buildApp()
162+
case "run":
163+
runAnyOne()
164+
elif inp.name == "KEY_ESCAPE":
165+
isCommandEnabled = True
166+
elif inp.name == "KEY_DOWN":
167+
if activeSelection[0] == commands.__len__() - 1:
168+
activeSelection[0] = 0
169+
else:
170+
activeSelection[0] += 1
171+
elif inp.name == "KEY_UP":
172+
if activeSelection[0] == 0:
173+
activeSelection[0] = commands.__len__() - 1
174+
else:
175+
activeSelection[0] -= 1
185176
takeInput()
186177
except KeyboardInterrupt:
187-
print("Process exited")
188178
os.system("clear")
179+
os.system("tput smcup")
189180
exit(1)
190181

191182

@@ -205,9 +196,6 @@ def __init__(self):
205196
self.Desc = ""
206197

207198

208-
appOptions = AppOptions()
209-
210-
211199
def createApp() -> None:
212200
try:
213201
global commandSpace
@@ -217,8 +205,7 @@ def createApp() -> None:
217205
global isCommandEnabled
218206
global exitCommand
219207
global selectedCommand
220-
os.system("clear")
221-
term.fullscreen()
208+
print("\x1b[%sH")
222209
print(term.royalblue_on_lightblue(lineSpace(1 / 6)))
223210
print(term.cornflowerblue_on_lightblue((logo[1:-1])))
224211
print(term.royalblue_on_lightblue(lineSpace(1 / 12, True)))
@@ -579,6 +566,7 @@ def createApp() -> None:
579566
elif inp.name is not None:
580567
if inp.name == "KEY_ENTER" and exitCommand == ":q":
581568
os.system("clear")
569+
print("\x1b[?1049l")
582570
exit(0)
583571
elif inp.name == "KEY_BACKSPACE":
584572
if exitCommand.__len__() > 0:
@@ -712,7 +700,33 @@ def createApp() -> None:
712700
).replace("$libaloo", alooDir + "lib")
713701
CMakeFile.write(CMakeSample)
714702

703+
colorsCSS = open(
704+
currFilePath + "styles/colors.css",
705+
"r",
706+
).read()
707+
materialCSS = open(
708+
currFilePath + "styles/material.css",
709+
"r",
710+
).read()
711+
712+
while colorsCSS.index("\t") != -1:
713+
colorsCSS = colorsCSS.replace("\t", "")
714+
while colorsCSS.index("\n") != -1:
715+
colorsCSS = colorsCSS.replace("\n", "")
716+
717+
while materialCSS.index("\t") != -1:
718+
materialCSS = materialCSS.replace("\t", "")
719+
while materialCSS.index("\n") != -1:
720+
materialCSS = materialCSS.replace("\n", "")
721+
os.mkdir(appInfo["project-name"] + "styles")
722+
cssBundle = open(
723+
appInfo["project-name"] + "styles/material.bundle.min.css",
724+
"w+",
725+
)
726+
cssBundle.write(materialCSS + colorsCSS)
727+
715728
print("\t\033[1;32m󰄭 Aloo project created successfully\033[0m")
729+
os.system("tput smcup")
716730
exit(0)
717731
else:
718732
match appOptions.InputNumber:
@@ -726,14 +740,10 @@ def createApp() -> None:
726740
except KeyboardInterrupt:
727741
print("Process exited")
728742
os.system("clear")
743+
os.system("tput smcup")
729744
exit(1)
730745

731746

732-
commandRan = False
733-
734-
threadStarted = False
735-
736-
737747
def cmake_thread() -> None:
738748
global threadStarted
739749
global commandRan
@@ -746,7 +756,6 @@ def cmake_thread() -> None:
746756
)
747757
threadStarted = False
748758
commandRan = True
749-
exit(0)
750759

751760

752761
def loader(i: int):
@@ -830,8 +839,7 @@ def buildApp() -> None:
830839
global isCommandEnabled
831840
global exitCommand
832841
global selectedCommand
833-
os.system("clear")
834-
term.fullscreen()
842+
print("\x1b[%sH")
835843
print(term.royalblue_on_lightblue(lineSpace(1 / 6)))
836844
print(term.cornflowerblue_on_lightblue((logo[1:-1])))
837845
emptyLine()
@@ -877,6 +885,8 @@ def buildApp() -> None:
877885
elif inp.name is not None:
878886
if inp.name == "KEY_ENTER" and exitCommand == ":q":
879887
os.system("clear")
888+
os.system("tput rmcup")
889+
print("\x1b[?25h\x1b[?7h")
880890
exit(0)
881891
elif inp.name == "KEY_BACKSPACE":
882892
if exitCommand.__len__() > 0:
@@ -892,12 +902,18 @@ def buildApp() -> None:
892902
except KeyboardInterrupt:
893903
print("Process exited")
894904
os.system("clear")
905+
os.system("tput rmcup")
906+
print("\x1b[?25h\x1b[?7h")
895907
exit(1)
896908

897909

898-
runAppSelection = "App"
899-
900-
appRunStatus = False
910+
def runAppOrTest(runWhat: str) -> None:
911+
subprocess.run(
912+
f"./bin/{runWhat}.exe",
913+
shell=True,
914+
stdout=subprocess.DEVNULL,
915+
stderr=subprocess.DEVNULL,
916+
)
901917

902918

903919
def runAnyOne() -> None:
@@ -911,8 +927,7 @@ def runAnyOne() -> None:
911927
global exitCommand
912928
global appRunStatus
913929
global selectedCommand
914-
os.system("clear")
915-
term.fullscreen()
930+
print("\x1b[%sH")
916931
print(term.royalblue_on_lightblue(lineSpace(1 / 6)))
917932
print(term.cornflowerblue_on_lightblue((logo[1:-1])))
918933
print(term.royalblue_on_lightblue(lineSpace(1 / 12, True)))
@@ -998,6 +1013,9 @@ def runAnyOne() -> None:
9981013
" " * ((term.width - len("Running Test")) // 2)
9991014
),
10001015
)
1016+
t1 = threading.Thread(target=runAppOrTest, args=(runAppSelection.lower(),))
1017+
t1.start()
1018+
t1.join()
10011019
else:
10021020
emptyLine()
10031021
print(term.royalblue_on_lightblue(lineSpace(1 / 2)))
@@ -1023,6 +1041,7 @@ def runAnyOne() -> None:
10231041
elif inp.name is not None:
10241042
if inp.name == "KEY_ENTER" and exitCommand == ":q":
10251043
os.system("clear")
1044+
os.system("tput smcup")
10261045
exit(0)
10271046
elif inp.name == "KEY_BACKSPACE":
10281047
if exitCommand.__len__() > 0:
@@ -1044,20 +1063,27 @@ def runAnyOne() -> None:
10441063
except KeyboardInterrupt:
10451064
print("Process exited")
10461065
os.system("clear")
1066+
os.system("tput smcup")
10471067
exit(1)
10481068

10491069

10501070
if __name__ == "__main__":
10511071
term = blessed.Terminal()
10521072
spaces: str = " "
1073+
commandRan = False
1074+
appOptions = AppOptions()
1075+
threadStarted = False
1076+
runAppSelection = "App"
1077+
appRunStatus = False
1078+
10531079
for i in range(
10541080
int((term.width - len("████████║ ██║ ██║ ██║ ██║ ██║")) / 2)
10551081
- 1
10561082
):
10571083
spaces += " "
10581084

10591085
alooTypes = Union["str", "int", "float", "bool", "object"]
1060-
commands: list[str] = ["create-app", "model", "build", "run", "connect-db"]
1086+
commands: list[str] = ["create-app", "build", "run"]
10611087
commandsInfo = {
10621088
"create-app": {
10631089
"info": "Create a new C aloo app",
@@ -1081,41 +1107,18 @@ def runAnyOne() -> None:
10811107
},
10821108
},
10831109
},
1084-
"model": {
1085-
"info": "Create a new model",
1086-
"hasSubCommands": False,
1087-
"fields": {"name": str, "field": dict[str, alooTypes]},
1088-
},
10891110
"build": {
10901111
"info": "Build the aloo project",
10911112
"hasSubCommands": False,
10921113
},
10931114
"run": {
1094-
"info": "Runs the project app/ tests",
1115+
"info": "Runs the project app/ tests (Recommended to use in Terminal to see output)",
10951116
"hasSubCommands": True,
10961117
"subCommands": {
10971118
"app": {"fields": "Runs the aloo app"},
10981119
"test": {"fields": "Runs the aloo project tests"},
10991120
},
11001121
},
1101-
"connect-db": {
1102-
"info": "Works with connection with databases",
1103-
"hasSubCommands": True,
1104-
"subCommands": {
1105-
"new": {
1106-
"info": "Create a new connection with database",
1107-
"field": {"modelName": str},
1108-
},
1109-
"restart": {
1110-
"info": "Deletes all data from sqlite",
1111-
"field": {"modelName": str},
1112-
},
1113-
"add": {
1114-
"info": "Add database model",
1115-
"field": {"modelName": str},
1116-
},
1117-
},
1118-
},
11191122
}
11201123

11211124
activeSelection = [0]
@@ -1129,11 +1132,10 @@ def runAnyOne() -> None:
11291132
{spaces}██║ ██║ ██████║ █████╝ █████╝ {spaces}
11301133
"""
11311134

1132-
os.system("clear")
1133-
term.fullscreen()
1134-
11351135
exitCommand = ""
11361136
isCommandEnabled = False
11371137
selectedCommand = ""
11381138
commandSpace: str = ""
1139+
os.system("tput smcup")
11391140
takeInput()
1141+
os.system("tput rmcup")

0 commit comments

Comments
 (0)