Skip to content

Commit

Permalink
Windows: Detach console on startup (onivim#401)
Browse files Browse the repository at this point in the history
* Detach console on startup for windows

* Only detach if logging is not enabled

* Formatting

* Format c bindings
  • Loading branch information
bryphe authored Jul 12, 2019
1 parent 2879bff commit afed774
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/editor/Core/Cli.re
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ let parse = (setup: Setup.t) => {
header(setup.version),
);

if (! Log.canPrint^) {
/* On Windows, detach the application from the console if we're not logging to console */
Utility.freeConsole();
};

let paths = args^ |> List.rev;
let workingDirectory = Environment.getWorkingDirectory();

Expand Down
2 changes: 2 additions & 0 deletions src/editor/Core/Utility.re
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ let trimTrailingSlash = (item: string) => {
item;
};
};

external freeConsole: unit => unit = "win32_free_console";
20 changes: 20 additions & 0 deletions src/editor/Core/bindings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>

#include <caml/alloc.h>
#include <caml/callback.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>

#ifdef WIN32
#include <Windows.h>
#endif

CAMLprim value win32_free_console(value unit) {

#ifdef WIN32
printf("yo from c\n");
FreeConsole();
#endif

return Val_unit;
};
1 change: 1 addition & 0 deletions src/editor/Core/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(library
(name Oni_Core)
(public_name Oni2.core)
(c_names bindings)
(libraries
str
bigarray
Expand Down

0 comments on commit afed774

Please sign in to comment.