Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NodeJS子进程ansi在标准输出中_Javascript_Node.js_Minecraft_Child Process - Fatal编程技术网

Javascript NodeJS子进程ansi在标准输出中

Javascript NodeJS子进程ansi在标准输出中,javascript,node.js,minecraft,child-process,Javascript,Node.js,Minecraft,Child Process,我想买点像这样的东西 [06:32:35] [Server thread/INFO]: [0;36;1m | [0;36;22m|__) [0;32;22mLuckPerms [0;36;1mv4.3.73[m [06:32:35] [Server thread/INFO]: [0;36;1m |___ [0;36;22m| [0;30;1mRunning on Bukkit - CraftBukkit[m 但我明白了 [06:05:02] [Server thread

我想买点像这样的东西

[06:32:35] [Server thread/INFO]: [0;36;1m  |    [0;36;22m|__)   [0;32;22mLuckPerms [0;36;1mv4.3.73[m
[06:32:35] [Server thread/INFO]: [0;36;1m  |___ [0;36;22m|      [0;30;1mRunning on Bukkit - CraftBukkit[m
但我明白了

[06:05:02] [Server thread/INFO]:   |    |__)   LuckPerms v4.3.73
[06:05:02] [Server thread/INFO]:   |___ |      Running on Bukkit - CraftBukkit
使用子进程运行minecraft服务器时

prcs.stdout.on(“数据”,函数(d){
log(d.toString());
});

在不确切知道
d
是如何形成的情况下,这里有一些东西符合您的示例,可能不完全符合您的需要,但您可以尝试升级它(至少它不需要任何依赖项):


d
的结构是什么?已经是字符串了吗?零件之间是否有填充空间或标签?什么是
d
的重复部分?(然后,您可能可以使用正则表达式和/或字符串方法(如
split
indexOf
)对其进行排序)
d
不是!我需要从child_进程stdout输出ANSI,child_进程是nodejst的一个模块。这段代码是为了让您了解如何实现它(尽管它非常广泛,因为您没有在注释中回答我的问题)。根据你的上下文(鉴于你的文章简洁,我不太了解)调整它取决于你。你怎么不明白?我的意思是,child_进程标准输出不输出Ansiy你的问题是向字符串中添加ANSI转义序列。引用:我想要类似于[ANSI增强字符串]的东西,但我得到的是[standard strings]。如果你不喜欢这个答案,重新思考这个问题。
const versionRegExp = /v[0-9]+(\.[0-9]+)*$/;
d.toString().split("\n").forEach((line) => {
  // no idea what the spaces are made of
  const exploded = line.trim().split(/[ \t]+/);
  // add paddings to the first two structures
  const first = exploded.shift().padEnd(5, ' ');
  const second = exploded.shift().padEnd(7, ' ');
  // work out the content
  // condition based on `second`, or should it be remainder.match(versionRegExp) ?
  const remainder = 0 === second.indexOf('|__)')
    ? `[0;30;1m${exploded.join(' ').replace(versionRegExp, '[0;36;1m$&')}[m`
    : `[0;32;22m${exploded.join(' ')}[m`
  ;
  // format line and display
  console.log(`[0;36;1m${first}[0;36;22m${second}${remainder}`);
});