Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[resolved] Print terminal output to html??
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Dirk.R.Gently
Guru
Guru


Joined: 29 Jan 2007
Posts: 546
Location: Titan

PostPosted: Wed Apr 09, 2008 5:27 am    Post subject: [resolved] Print terminal output to html?? Reply with quote

pretty much as the title states. Anyone know of a program or way to grab terminal output with colors and output this to html?
_________________
Helpful Linux Tidbits


Last edited by Dirk.R.Gently on Fri Apr 11, 2008 5:47 am; edited 1 time in total
Back to top
View user's profile Send private message
tobr
Guru
Guru


Joined: 29 May 2006
Posts: 330

PostPosted: Wed Apr 09, 2008 9:04 pm    Post subject: Reply with quote

The question is what exactly you want to do.

If you want to convert the output of some program into HTML it should be possible by piping through a small perl script or something. If you want to do it with an interactive session this could be harder, especially if you also want to include the stuff you type.

Perhaps there's an easier way if you tell us what you’re trying to accomplish.

HTH
_________________
Please add [SOLVED] to your message title if your problem is solved.

Death to all blobs!
Back to top
View user's profile Send private message
Dirk.R.Gently
Guru
Guru


Joined: 29 Jan 2007
Posts: 546
Location: Titan

PostPosted: Wed Apr 09, 2008 10:53 pm    Post subject: Reply with quote

yes, let me expand on that. I am hoping to be able to print on a webpage the standard output I see in the terminal. More specifically Portage emerges, and grep output. I was hoping/thinking there would be a program around that would be able to print both colored output and translate whatever HTML character entities it runs into.
_________________
Helpful Linux Tidbits
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Thu Apr 10, 2008 12:50 am    Post subject: Reply with quote

The KBtin MUD client (get it here) includes a decent ansi2html filter.
There's no need to build or install the whole thing, the filter is completely self-contained:
Code:
tar xzvf kbtin-1.0.11.tar.gz
cd kbtin-1.0.11
( . /etc/make.conf; gcc $CFLAGS -o ansi2html ansi2html.c )
strip ansi2html
install -m 755 ansi2html /usr/local/bin
install -m 644 ansi2html.1 /usr/local/man/man1

I know the above works because I have no need of a MUD client but stumbled onto its Subversion repository by googling for "ansi2html." :lol:

Writing the above as an ebuild is left as an exercise for the reader, I'm feeling entirely too lazy. :P
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
tarpman
Veteran
Veteran


Joined: 04 Nov 2004
Posts: 1083
Location: Victoria, BC, Canada

PostPosted: Thu Apr 10, 2008 4:53 pm    Post subject: Reply with quote

Sure, I'll bite.
app-text/ansi2html-1.0.11.ebuild:
# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

DESCRIPTION="Convert text with ANSI escape codes to HTML"
HOMEPAGE="http://kbtin.sourceforge.net"
SRC_URI="mirror://sourceforge/kbtin/kbtin-${PV}.tar.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""

DEPEND=""
RDEPEND=""

S="${WORKDIR}/kbtin-${PV}"

src_compile() {
   econf || die "econf failed"
   emake ansi2html || die "emake failed"
}

src_install() {
   dobin ansi2html || die
   doman ansi2html.1 || die
}

Enjoy. Seems to work nicely - I'll be keeping this one around.

Note, though, that if portage detects that its output isn't going to a terminal it will automatically disable coloured output. You can force it with the --color option, like so:
Code:
emerge -vp --color y portage | ansi2html > portage-with-colour.html

_________________
Saving the world, one kilobyte at a time.
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Thu Apr 10, 2008 7:25 pm    Post subject: Reply with quote

tarpman wrote:
Sure, I'll bite.
Gotta love that community spirit. Thanks. :)

tarpman wrote:
Seems to work nicely - I'll be keeping this one around.

Note, though, that if portage detects that its output isn't going to a terminal it will automatically disable coloured output.
Likewise.
Most tools that colorize output (ls, grep, etc.--not just emerge) suppress color unless told otherwise when they detect standard output is not a tty. Many if not all provide a switch to force color, but it varies.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
Dirk.R.Gently
Guru
Guru


Joined: 29 Jan 2007
Posts: 546
Location: Titan

PostPosted: Fri Apr 11, 2008 5:44 am    Post subject: Reply with quote

Thanks timebandit for letting me know about this and thanks tarpman for the ebuild! I blog pretty often about linux and this helps tremendously. Good to know this is possible.

:D :D :D
_________________
Helpful Linux Tidbits
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum