Skip to content

Commit 16bd7df

Browse files
committed
Fixed: Some bugs on macOS ARM terminal
1 parent a90e65f commit 16bd7df

File tree

6 files changed

+74
-35
lines changed

6 files changed

+74
-35
lines changed

tools/hbuild/dub.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"copyright": "Copyright © 2023, Hipreme",
66
"dependencies": {
77
"arsd-official:terminal": "~>11.5.0",
8-
"redub": "~>1.24.7",
8+
"redub": "~>1.24.9",
99
"handy-httpd": "~>8.4.3",
1010
"archive": "~>0.7.1",
1111
"my-ip": "~>0.2.0",

tools/hbuild/source/app.d

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ Choice* selectChoice(ref Terminal terminal, ref RealTimeConsoleInput input, Choi
7474
selectedChoice);
7575
}
7676

77-
78-
configs["selectedChoice"] = cast(long)selectedChoice;
79-
updateConfigFile();
77+
if(!choices[selectedChoice].disableSelectedConfigCache)
78+
{
79+
configs["selectedChoice"] = cast(long)selectedChoice;
80+
updateConfigFile();
81+
}
8082
return &choices[selectedChoice];
8183
}
8284

@@ -307,9 +309,6 @@ string updateSelectedCompiler()
307309

308310
ChoiceResult exitFn(Choice* c, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions cOpts)
309311
{
310-
t.showCursor();
311-
configs["selectedChoice"] = 0;
312-
updateConfigFile();
313312
return ChoiceResult.Continue;
314313
}
315314

@@ -412,7 +411,7 @@ void main(string[] args)
412411
Choice("Select Game", &selectGameFolder),
413412
Choice("Release Game", &releaseGame),
414413
Choice("Selected Compiler: ", &changeCompiler, false, &updateSelectedCompiler),
415-
Choice("Exit", &exitFn)
414+
Choice("Exit", &exitFn, false, null, false, true)
416415
];
417416

418417
bool usesDflags = "DFLAGS" in environment;
@@ -458,5 +457,8 @@ void main(string[] args)
458457
}
459458
else break;
460459
}
461-
exitServer();
460+
exitServer(terminal);
461+
destroy(terminal);
462+
import core.stdc.stdlib;
463+
exit(0);
462464
}

tools/hbuild/source/commons.d

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ string pathBeforeNewLdc;
2121
struct Terminal
2222
{
2323
import std.stdio;
24+
import core.sync.mutex;
25+
2426
arsd.terminal.Terminal* arsdTerminal;
27+
Mutex mtx;
2528
this(arsd.terminal.Terminal* arsdTerminal)
2629
{
2730
this.arsdTerminal = arsdTerminal;
31+
mtx = new Mutex();
2832
}
2933

30-
void color(Color main, Color secondary){if(arsdTerminal) arsdTerminal.color(main, secondary);}
34+
void color(Color main, Color secondary)
35+
{
36+
if(arsdTerminal) synchronized(mtx)
37+
arsdTerminal.color(main, secondary);
38+
}
3139
int cursorY()
3240
{
33-
if(arsdTerminal)
41+
if(arsdTerminal) synchronized(mtx)
3442
{
3543
arsdTerminal.updateCursorPosition();
3644
return arsdTerminal.cursorY;
@@ -39,20 +47,20 @@ struct Terminal
3947
}
4048
string getline(string message)
4149
{
42-
if(arsdTerminal) return arsdTerminal.getline(message);
50+
if(arsdTerminal) synchronized(mtx) return arsdTerminal.getline(message);
4351
std.stdio.writeln("Can't get line with message [", message, "]");
4452
return "";
4553
}
46-
void moveTo(int x, int y){if(arsdTerminal) arsdTerminal.moveTo(x, y);}
47-
void clear(){if(arsdTerminal) arsdTerminal.clear();}
54+
void moveTo(int x, int y){if(arsdTerminal) synchronized(mtx) arsdTerminal.moveTo(x, y);}
55+
void clear(){if(arsdTerminal) synchronized(mtx) arsdTerminal.clear();}
4856
void write(T...)(T args)
4957
{
50-
if(arsdTerminal) arsdTerminal.write(args);
58+
if(arsdTerminal) synchronized(mtx) arsdTerminal.write(args);
5159
else std.stdio.write(args);
5260
}
5361
void flush()
5462
{
55-
if(arsdTerminal)
63+
if(arsdTerminal) synchronized(mtx)
5664
{
5765
arsdTerminal.flush();
5866
arsdTerminal.updateCursorPosition();
@@ -65,11 +73,11 @@ struct Terminal
6573
return std.process.wait(pid);
6674
}
6775

68-
void hideCursor(){ if(arsdTerminal) arsdTerminal.hideCursor();}
69-
void showCursor(){ if(arsdTerminal) arsdTerminal.showCursor();}
76+
void hideCursor(){ if(arsdTerminal) synchronized(mtx) arsdTerminal.hideCursor();}
77+
void showCursor(){ if(arsdTerminal) synchronized(mtx) arsdTerminal.showCursor();}
7078
void clearToEndOfLine()
7179
{
72-
if(arsdTerminal) arsdTerminal.clearToEndOfLine();
80+
if(arsdTerminal) synchronized(mtx) arsdTerminal.clearToEndOfLine();
7381
flush();
7482
}
7583
void clearLine()
@@ -81,12 +89,14 @@ struct Terminal
8189

8290
void writeln(T...)(T args)
8391
{
84-
if (arsdTerminal) arsdTerminal.writeln(args);
92+
if (arsdTerminal) synchronized(mtx) arsdTerminal.writeln(args);
8593
else std.stdio.writeln(args);
8694
}
8795
~this()
8896
{
89-
if(arsdTerminal) destroy(*arsdTerminal);
97+
showCursor();
98+
if(arsdTerminal) synchronized(mtx) destroy(*arsdTerminal);
99+
mtx = null;
90100
}
91101
}
92102

@@ -146,17 +156,24 @@ struct Choice
146156
bool shouldTime;
147157
string function() updateChoice;
148158
bool scriptOnly;
159+
bool disableSelectedConfigCache;
160+
161+
162+
163+
164+
149165

150166
this(string name,
151167
ChoiceResult function(Choice* self, ref Terminal t, ref RealTimeConsoleInput input, in CompilationOptions opts) onSelected,
152168
bool shouldTime = false,
153-
string function() updateChoice = null, bool scriptOnly = false)
169+
string function() updateChoice = null, bool scriptOnly = false, bool disableSelectedConfigCache = false)
154170
{
155171
this.name = updateChoice ? updateChoice() : name;
156172
this.onSelected = onSelected;
157173
this.shouldTime = shouldTime;
158174
this.updateChoice = updateChoice;
159175
this.scriptOnly = scriptOnly;
176+
this.disableSelectedConfigCache = disableSelectedConfigCache;
160177
}
161178

162179
bool opEquals(ref const Choice other) const
@@ -882,7 +899,7 @@ private ChoiceResult _backFn(Choice* c, ref Terminal t, ref RealTimeConsoleInput
882899
}
883900
Choice getBackChoice()
884901
{
885-
return Choice("Back", &_backFn);
902+
return Choice("Back", &_backFn, false, null, false, true);
886903
}
887904

888905

@@ -1055,9 +1072,17 @@ int waitRedub(ref Terminal t, DubArguments dArgs, out ProjectDetails proj, strin
10551072
void inParallel(scope void delegate()[] args...)
10561073
{
10571074
import std.parallelism;
1058-
foreach(action; parallel(args))
1059-
action();
10601075

1076+
// version(AArch64)
1077+
// {
1078+
// foreach(action; args)
1079+
// action();
1080+
// }
1081+
// else
1082+
// {
1083+
foreach(action; parallel(args))
1084+
action();
1085+
// }
10611086
}
10621087

10631088
int waitDub(ref Terminal t, DubArguments dArgs, string copyLinkerFilesTo = null)

tools/hbuild/source/global_opts.d

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ private Thread serverThread;
1313
shared ushort gameServerPort;
1414
shared string gameServerHost;
1515

16-
void startServer(shared ushort* usingPort, shared string* usingHost)
16+
17+
private Terminal* term;
18+
19+
void startServer(shared ushort* usingPort, shared string* usingHost, ref Terminal t)
1720
{
1821
if(serverStarted) return;
1922
import server;
2023
import core.stdc.stdlib;
2124
serverStarted = true;
25+
term = &t;
2226
Semaphore s = new Semaphore();
2327
serverThread = new Thread(()
2428
{
@@ -35,7 +39,11 @@ void startServer(shared ushort* usingPort, shared string* usingHost)
3539
{
3640
if (ctrlType == CTRL_C_EVENT) // CTRL+C signal
3741
{
38-
try exitServer();
42+
try
43+
{
44+
exitServer(*term);
45+
destroy(*term);
46+
}
3947
catch(Exception e){}
4048
exit(0);
4149
}
@@ -53,7 +61,8 @@ void startServer(shared ushort* usingPort, shared string* usingHost)
5361
import core.sys.posix.signal;
5462
static extern(C) void handleCtrlC(int signum)
5563
{
56-
exitServer();
64+
exitServer(*term);
65+
destroy(*term);
5766
exit(0);
5867
}
5968
alias fn = extern(C) void function(int) nothrow @nogc;
@@ -63,13 +72,14 @@ void startServer(shared ushort* usingPort, shared string* usingHost)
6372
s.wait;
6473
}
6574

66-
void exitServer()
75+
void exitServer(ref Terminal t)
6776
{
68-
if(!serverStarted) return;
69-
import core.stdc.stdlib;
77+
if(!serverStarted)
78+
return;
79+
import std.conv: to;
7080
import server;
71-
serverStarted = false;
81+
t.writelnHighlighted("Shutting down the server at ", cast()gameServerHost, ":", cast()gameServerPort.to!string);
7282
serverThread = null;
83+
serverStarted = false;
7384
stopServer();
74-
exit(0);
7585
}

tools/hbuild/source/server.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ string contentTypeFromFileExtension(string filename)
166166

167167
void stopServer()
168168
{
169+
if(context is null)
170+
return;
169171
pushWebsocketMessage("close");
170172
context.server.stop();
171173
}

tools/hbuild/source/targets/wasm.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ChoiceResult prepareWASM(Choice* c, ref Terminal t, ref RealTimeConsoleInput inp
4949
t.writelnError("Could not build for WebAssembly.");
5050
return ChoiceResult.Error;
5151
}
52-
import wasm_sourcemaps.generate;
52+
// import wasm_sourcemaps.generate;
5353

5454
///In the current status, wasm sourcemap generation invalidates cache, but since the compilation is really fast right now
5555
///We can keep that
@@ -69,7 +69,7 @@ ChoiceResult prepareWASM(Choice* c, ref Terminal t, ref RealTimeConsoleInput inp
6969
if(!serverStarted)
7070
{
7171
t.writelnHighlighted("Attempt to start WebAssembly development server.");
72-
startServer(&gameServerPort, &gameServerHost);
72+
startServer(&gameServerPort, &gameServerHost, t);
7373
t.writelnSuccess("Development started at localhost:"~gameServerPort.to!string);
7474
cached(() => cast(void)openDefaultBrowser("http://"~gameServerHost~":"~gameServerPort.to!string));
7575
}

0 commit comments

Comments
 (0)