用xterm颤动模拟外壳窗口

时间:2019-02-13 07:41:36

标签: flutter

我正在项目中执行ssh函数。 (使用https://pub.dartlang.org/packages/ssh),现在会话已与xterm连接,可以预期使用cmd,并且ssh服务器的结果将显示在Text小部件中,该小部件的字符串将类似于'[0m ... [0m ',如果我将结果打印到控制台(print(result))中,它将以指定的颜色正确显示,那么如何模拟一个可在我的应用程序中正确显示结果的shell窗口?

The output of the app now

Output in console which I want to emulate in my app

another example of cmd 'top' in app

output in console that i want to realize

1 个答案:

答案 0 :(得分:0)

好吧,您看到的奇怪的[0是ANSI转义码。这些代码告诉终端,字符串的某个部分需要获得颜色。您可以在这里找到颜色列表:https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

然后,当您获得该信息时,将需要一些工具来为TextField的各个部分设置样式。在Flutter中,您可以使用RichText类:https://docs.flutter.io/flutter/widgets/RichText-class.html。我的建议是查找并替换显示的文本。

参考文献:

Display a few words in different colors in Flutter

How to change the output color of echo in Linux