Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to write notes (in HTML format) when learning linux. When I need to note colorful terminal text output, I want the color of terminal text can be remained in my notes, eg:

Note 1: Test

The output of xx command is

<pre>
[root@webserver ~]# ll /
total 100
drwxrwxrwt.   7 root root  4096 8月  24 12:22 <span style='background-color:green; color:blue;'>tmp</span>
drwxr-xr-x.  14 root root  4096 7月  19 21:20 <span style='color:blue;'>usr</span>
</pre>

I can manually add HTML code wrapper around the plain text, but I hope there's an automatical way to achieve that.

Currently, I'm using putty on Windows to connnect to remote CentOS linux server.

share|improve this question
    
you want to copy data from terminal to buffer and when you paste it in notepad you expected to seen html near color words? –  Ishikawa Yoshi Aug 24 '12 at 7:35
    
yes, that's what i wanted. i think this can be done in terminal emulator software (translate control characters into HTML), but i don't know if there's such emulator has such function. –  LiuYan 刘研 Aug 24 '12 at 7:41
2  
    
thanks for the link, i didn't notice that option before. however that's a slight different question, i want the paste to be HTML code, not rich text format (and my RTF paste seems malformed characters). –  LiuYan 刘研 Aug 24 '12 at 8:27
1  
stackoverflow.com/questions/2033268/linux-shell-output-to-html maybe this link also helps you –  Ishikawa Yoshi Aug 24 '12 at 8:38

1 Answer 1

Use the script utility to capture the terminal output to a file (ansi color control characters included) and then convert it to html with ansi2html script. Eg:

inigo:tmp> script
Script started, file is typescript
inigo:tmp> ls
#
# lots of colour output
# 
inigo:tmp> exit
exit
Script done, file is typescript
inigo:tmp> cat typescript  | ansi2html.sh > typescript.html

If using PuTTY, "All session output" login option will also keep the ansi color codes.

share|improve this answer
    
Awesome, made my day! Thanks! –  georg Nov 12 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.