1
+ #!/usr/bin/env python3
1
2
import blessed
2
3
import os
3
4
from typing import Union , Optional , Callable
@@ -32,8 +33,7 @@ def takeInput() -> None:
32
33
global isCommandEnabled
33
34
global exitCommand
34
35
global selectedCommand
35
- os .system ("clear" )
36
- term .fullscreen ()
36
+ print ("\x1b [%sH" )
37
37
print (term .royalblue_on_lightblue (lineSpace (1 / 6 )))
38
38
print (term .cornflowerblue_on_lightblue ((logo [1 :- 1 ])))
39
39
print (term .royalblue_on_lightblue (lineSpace (1 / 5 , True )))
@@ -121,8 +121,8 @@ def takeInput() -> None:
121
121
+ term .royalblue_on_lightblue ("└" + infoSpaceEnd + "┘" )
122
122
+ term .bold_royalblue_on_lightblue (" " * ((term .width - infoLen - 4 ) // 2 ))
123
123
)
124
- for i in range ( 6 ):
125
- emptyLine ( )
124
+
125
+ print ( term . royalblue_on_lightblue ( lineSpace ( 1 / 4 )) )
126
126
if isCommandEnabled :
127
127
commandSpace = ""
128
128
for _ in range (int ((term .width - exitCommand .__len__ () - 11 ))):
@@ -137,55 +137,46 @@ def takeInput() -> None:
137
137
emptyLine ("" )
138
138
with term .cbreak (), term .hidden_cursor ():
139
139
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 :
157
142
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" :
163
144
if exitCommand .__len__ () > 0 :
164
145
exitCommand = exitCommand [:- 1 ]
165
146
else :
166
147
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" )
174
150
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
185
176
takeInput ()
186
177
except KeyboardInterrupt :
187
- print ("Process exited" )
188
178
os .system ("clear" )
179
+ os .system ("tput smcup" )
189
180
exit (1 )
190
181
191
182
@@ -205,9 +196,6 @@ def __init__(self):
205
196
self .Desc = ""
206
197
207
198
208
- appOptions = AppOptions ()
209
-
210
-
211
199
def createApp () -> None :
212
200
try :
213
201
global commandSpace
@@ -217,8 +205,7 @@ def createApp() -> None:
217
205
global isCommandEnabled
218
206
global exitCommand
219
207
global selectedCommand
220
- os .system ("clear" )
221
- term .fullscreen ()
208
+ print ("\x1b [%sH" )
222
209
print (term .royalblue_on_lightblue (lineSpace (1 / 6 )))
223
210
print (term .cornflowerblue_on_lightblue ((logo [1 :- 1 ])))
224
211
print (term .royalblue_on_lightblue (lineSpace (1 / 12 , True )))
@@ -579,6 +566,7 @@ def createApp() -> None:
579
566
elif inp .name is not None :
580
567
if inp .name == "KEY_ENTER" and exitCommand == ":q" :
581
568
os .system ("clear" )
569
+ print ("\x1b [?1049l" )
582
570
exit (0 )
583
571
elif inp .name == "KEY_BACKSPACE" :
584
572
if exitCommand .__len__ () > 0 :
@@ -712,7 +700,33 @@ def createApp() -> None:
712
700
).replace ("$libaloo" , alooDir + "lib" )
713
701
CMakeFile .write (CMakeSample )
714
702
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
+
715
728
print ("\t \033 [1;32m Aloo project created successfully\033 [0m" )
729
+ os .system ("tput smcup" )
716
730
exit (0 )
717
731
else :
718
732
match appOptions .InputNumber :
@@ -726,14 +740,10 @@ def createApp() -> None:
726
740
except KeyboardInterrupt :
727
741
print ("Process exited" )
728
742
os .system ("clear" )
743
+ os .system ("tput smcup" )
729
744
exit (1 )
730
745
731
746
732
- commandRan = False
733
-
734
- threadStarted = False
735
-
736
-
737
747
def cmake_thread () -> None :
738
748
global threadStarted
739
749
global commandRan
@@ -746,7 +756,6 @@ def cmake_thread() -> None:
746
756
)
747
757
threadStarted = False
748
758
commandRan = True
749
- exit (0 )
750
759
751
760
752
761
def loader (i : int ):
@@ -830,8 +839,7 @@ def buildApp() -> None:
830
839
global isCommandEnabled
831
840
global exitCommand
832
841
global selectedCommand
833
- os .system ("clear" )
834
- term .fullscreen ()
842
+ print ("\x1b [%sH" )
835
843
print (term .royalblue_on_lightblue (lineSpace (1 / 6 )))
836
844
print (term .cornflowerblue_on_lightblue ((logo [1 :- 1 ])))
837
845
emptyLine ()
@@ -877,6 +885,8 @@ def buildApp() -> None:
877
885
elif inp .name is not None :
878
886
if inp .name == "KEY_ENTER" and exitCommand == ":q" :
879
887
os .system ("clear" )
888
+ os .system ("tput rmcup" )
889
+ print ("\x1b [?25h\x1b [?7h" )
880
890
exit (0 )
881
891
elif inp .name == "KEY_BACKSPACE" :
882
892
if exitCommand .__len__ () > 0 :
@@ -892,12 +902,18 @@ def buildApp() -> None:
892
902
except KeyboardInterrupt :
893
903
print ("Process exited" )
894
904
os .system ("clear" )
905
+ os .system ("tput rmcup" )
906
+ print ("\x1b [?25h\x1b [?7h" )
895
907
exit (1 )
896
908
897
909
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
+ )
901
917
902
918
903
919
def runAnyOne () -> None :
@@ -911,8 +927,7 @@ def runAnyOne() -> None:
911
927
global exitCommand
912
928
global appRunStatus
913
929
global selectedCommand
914
- os .system ("clear" )
915
- term .fullscreen ()
930
+ print ("\x1b [%sH" )
916
931
print (term .royalblue_on_lightblue (lineSpace (1 / 6 )))
917
932
print (term .cornflowerblue_on_lightblue ((logo [1 :- 1 ])))
918
933
print (term .royalblue_on_lightblue (lineSpace (1 / 12 , True )))
@@ -998,6 +1013,9 @@ def runAnyOne() -> None:
998
1013
" " * ((term .width - len ("Running Test" )) // 2 )
999
1014
),
1000
1015
)
1016
+ t1 = threading .Thread (target = runAppOrTest , args = (runAppSelection .lower (),))
1017
+ t1 .start ()
1018
+ t1 .join ()
1001
1019
else :
1002
1020
emptyLine ()
1003
1021
print (term .royalblue_on_lightblue (lineSpace (1 / 2 )))
@@ -1023,6 +1041,7 @@ def runAnyOne() -> None:
1023
1041
elif inp .name is not None :
1024
1042
if inp .name == "KEY_ENTER" and exitCommand == ":q" :
1025
1043
os .system ("clear" )
1044
+ os .system ("tput smcup" )
1026
1045
exit (0 )
1027
1046
elif inp .name == "KEY_BACKSPACE" :
1028
1047
if exitCommand .__len__ () > 0 :
@@ -1044,20 +1063,27 @@ def runAnyOne() -> None:
1044
1063
except KeyboardInterrupt :
1045
1064
print ("Process exited" )
1046
1065
os .system ("clear" )
1066
+ os .system ("tput smcup" )
1047
1067
exit (1 )
1048
1068
1049
1069
1050
1070
if __name__ == "__main__" :
1051
1071
term = blessed .Terminal ()
1052
1072
spaces : str = " "
1073
+ commandRan = False
1074
+ appOptions = AppOptions ()
1075
+ threadStarted = False
1076
+ runAppSelection = "App"
1077
+ appRunStatus = False
1078
+
1053
1079
for i in range (
1054
1080
int ((term .width - len ("████████║ ██║ ██║ ██║ ██║ ██║" )) / 2 )
1055
1081
- 1
1056
1082
):
1057
1083
spaces += " "
1058
1084
1059
1085
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" ]
1061
1087
commandsInfo = {
1062
1088
"create-app" : {
1063
1089
"info" : "Create a new C aloo app" ,
@@ -1081,41 +1107,18 @@ def runAnyOne() -> None:
1081
1107
},
1082
1108
},
1083
1109
},
1084
- "model" : {
1085
- "info" : "Create a new model" ,
1086
- "hasSubCommands" : False ,
1087
- "fields" : {"name" : str , "field" : dict [str , alooTypes ]},
1088
- },
1089
1110
"build" : {
1090
1111
"info" : "Build the aloo project" ,
1091
1112
"hasSubCommands" : False ,
1092
1113
},
1093
1114
"run" : {
1094
- "info" : "Runs the project app/ tests" ,
1115
+ "info" : "Runs the project app/ tests (Recommended to use in Terminal to see output) " ,
1095
1116
"hasSubCommands" : True ,
1096
1117
"subCommands" : {
1097
1118
"app" : {"fields" : "Runs the aloo app" },
1098
1119
"test" : {"fields" : "Runs the aloo project tests" },
1099
1120
},
1100
1121
},
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
- },
1119
1122
}
1120
1123
1121
1124
activeSelection = [0 ]
@@ -1129,11 +1132,10 @@ def runAnyOne() -> None:
1129
1132
{ spaces } ██║ ██║ ██████║ █████╝ █████╝ { spaces }
1130
1133
"""
1131
1134
1132
- os .system ("clear" )
1133
- term .fullscreen ()
1134
-
1135
1135
exitCommand = ""
1136
1136
isCommandEnabled = False
1137
1137
selectedCommand = ""
1138
1138
commandSpace : str = ""
1139
+ os .system ("tput smcup" )
1139
1140
takeInput ()
1141
+ os .system ("tput rmcup" )
0 commit comments