-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsrun_console.c
More file actions
53 lines (48 loc) · 1.34 KB
/
tsrun_console.c
File metadata and controls
53 lines (48 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// tsrun_console.c - Default console implementation for tsrun
#include "tsrun_console.h"
#include <stdio.h>
void tsrun_console_stdio(
TsRunConsoleLevel level,
const char* message,
size_t message_len,
void* userdata
) {
// Determine output streams
FILE* out_stream = stdout;
FILE* err_stream = stderr;
if (userdata != NULL) {
TsRunConsoleStreams* streams = (TsRunConsoleStreams*)userdata;
if (streams->out != NULL) {
out_stream = streams->out;
}
if (streams->err != NULL) {
err_stream = streams->err;
}
}
// Select stream based on level
FILE* stream;
switch (level) {
case TSRUN_CONSOLE_LOG:
case TSRUN_CONSOLE_INFO:
case TSRUN_CONSOLE_DEBUG:
stream = out_stream;
break;
case TSRUN_CONSOLE_WARN:
case TSRUN_CONSOLE_ERROR:
stream = err_stream;
break;
case TSRUN_CONSOLE_CLEAR:
fprintf(out_stream, "--- Console cleared ---\n");
fflush(out_stream);
return;
default:
stream = out_stream;
break;
}
// Write message (message_len bytes, not null-terminated)
if (message_len > 0) {
fwrite(message, 1, message_len, stream);
}
fputc('\n', stream);
fflush(stream);
}