Java JTextArea handling undisplayable ASCII sequences
Streaming the output of a Linux command to a JTextArea. How can I handle the ASCII sequences. The sequences 开发者_运维百科would normally be used to highlight text within a shell environment.
The JTEXTAREA looks like this:
ls -altr
drwx------ 2 user 80 2009-11-25 07:23 [01;34mDocuments[00m
drwxr-xr-x 2 user 48 2009-11-25 07:23 [01;34mbin[00m
-rw-r--r-- 1 user 1177 2009-11-25 07:23 [00m.bashrc[00m
drwx------ 8 user 608 2009-11-25 07:23 [01;34m.[00m
drwxr-xr-x 88 user 2096 2011-03-09 08:47 [01;34m..[00m
-rw------- 1 user 472 2011-03-12 11:38 [00m.bash_history[00m
Where as it I should strip or deal with the strange ASCII sequences '[01;34m'. I can't filters char's because it's a sequences of chars.
Idea's ?
I can't filters char's because it's a sequences of chars.
You can use a Document Filter. A String of characters to be added to the Document is passed to the filter. You can remove any character from the string before updating the document.
ANSI escape sequences start with <esc>[
and end with m
- you can filter them
That seams to be color escape sequences.
There must be some option to disable colors in the ls
listing, like --color=never
.
And maybe --hide-control-chars
to avoid non graphic characters.
精彩评论