在 CI 上,将简单地创建几个管道并使用 dup2 覆盖 std 文件描述符,而在另一端,我将利用阻塞 IO 在无限循环上为每个输出管道(sdtout、sdterr)创建一个线程管道更新适合控制台建议的 textArea/canvas。至于标准输入,我会监听此类组件上的关键事件,并将其写入管道。
但是我怎样才能在 Java 上用 swing 来执行呢?
我不能将本机代码混合为项目指令。到目前为止,我已经违反了许多项目指令,所以我不能继续这样做......
此外,提供某种级别的终端仿真(例如 VT100)也很酷,但是如何在 unix 上通知 java 应用程序这种功能,我将设置 TERM envvar。
在 CI 上将执行以下操作:
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
static pthread_t workers[2];
static void *_worker(void *file)
{
int c;
if(!file) pthread_exit(NULL);
while((c=fgetc(file))!=EOF) {
// Sync and put C on the screen
}
pthread_exit(NULL);
}
int initConsole()
{
int stdin_pipe[2], stdout_pipe[2], stderr_pipe[2];
if(!(pipe(stdin_pipe)||pipe(stdout_pipe)||pipe(stderr_pipe))) {
if(dup2(stdin_pipe[0], STDIN_FILENO)<0) return -1;
if(dup2(stdout_pipe[1], STDOUT_FILENO)<0) return -1;
if(dup2(stderr_pipe[1], STDERR_FILENO)<0) return -1;
pthread_create(&workers[0], NULL, _worker, fdopen(stdout_pipe[0], "r"));
pthread_create(&workers[1], NULL, _worker, fdopen(stderr_pipe[0], "r"));
// Register a handler within the toolkit to push chars into the stdin_pipe
return 0;
}
return -1;
}