1

I am making an ssh function in my project. (with https://pub.dartlang.org/packages/ssh), right now session is connected with xterm, cmd can be expected, and the result from the ssh server is displayed in a Text widget, which will have the string like '[0m ... [0m', if I print the result into the console(print(result)), it will display correctly with the color specified, so how can I emulate a shell window which displays the result correctly in my app?

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

nieben
  • 49
  • 5
  • Is this the line of code that people see? `"${f["filename"]} ${f["isDirectory"]} ${f["modificationDate"]} ${f["lastAccess"]} ${f["fileSize"]} ${f["ownerUserID"]} ${f["ownerGroupID"]} ${f["permissions"]} ${f["flags"]}");` or is it the `_result` label? – gi097 Feb 13 '19 at 08:09
  • do you mean the result? i think it is returned as string including '[0m...' in program – nieben Feb 13 '19 at 08:17

1 Answers1

0

Well, the weird [0 you see are ANSI escape codes. These codes tell the terminal that a certain part of a string needs to get a color. You can find a list of colors here: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors.

Then when you have that info, you will need some tool that can style parts of a TextField. In Flutter you can use the RichText class: https://docs.flutter.io/flutter/widgets/RichText-class.html. My suggestion is to do a find and replace on the text you are showing.

References:

Display a few words in different colors in Flutter

How to change the output color of echo in Linux

gi097
  • 7,313
  • 3
  • 27
  • 49