0

I am using nodejs in my application and need to deal with ANSI character. I am looking for a way to translate a ANSI to a normal string. For example, I get this ANSI characters:

db[3G[Jdb[5G

then translate should be:

`[3G`  -> go to the 3rd column which is d
`[j]`  -> earse below
`[5G`  -> move cursor to 5th column

after that the string character should be db. But if I use strip-ansi library, it will give a string dbdb which includes db twice. Is there a way for me to deal with the ANSI character gracefully?

I have tried utf8 module but the encode and decode methods don't help.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • Possible duplicate of [Nodejs convert string into UTF-8](https://stackoverflow.com/questions/20174280/nodejs-convert-string-into-utf-8) – Ragul Parani Aug 04 '17 at 05:03
  • I have tried `utf8` module but not help – Joey Yi Zhao Aug 04 '17 at 05:07
  • There is no straight-forward answer here because ANSI can cause the cursor to move and do other things, so asking to convert ANSI to a "normal string" doesn't make sense. Especially considering there is no easy way to get existing characters on the screen. – mscdex Aug 04 '17 at 06:00
  • or is there a way for me to emulate the hehaviour of terminal in order to get the ANSI string? – Joey Yi Zhao Aug 04 '17 at 07:03
  • You might be able to use [`terminal.js`](https://github.com/Gottox/terminal.js) to emulate a terminal. – robertklep Aug 04 '17 at 07:17

0 Answers0