ELinks: Web-browsing Made Fun

Introduction

With the rise of browsers such as Firefox and Mozilla, it might seem odd that one would want to use any other browser -- both Mozilla and Firefox are fine applications, and are able to render pages well, with the option of a lot of added extras. Problem with that is both browsers are slow. And they consume vast amounts of RAM. There's been a few instanes where a sluggish PC has been easily remidied by restarting Firefox or Mozilla.

ELinks, however, is purely text-based, that is, it runs at the console, inside of terminal emulators, and so forth. Being text-based means it can run anywhere -- it's not tied down to using X, for instance.

Why do I like ELinks? Anyone that knows me will already have some idea. Essentially, I like it because when viewing webpages, the one thing I am interested in above anything else is the text. I don't care much for layout -- although ELinks does seem to render pages extremely well in that regard. If I care for the images, I can always view them externally using a predefined viewer -- that ELinks intelligently guesses, and that I can redefine. (OK, so it guesses it from /etc/mailcap but that's not really the point).

Annotated Screenshot

The following figure shows an annotated screenshot of ELinks, with most of its features visible, although some are not so.

ELinks Annotated

Features

This list is by no means exhaustive, but some of the things ELinks has that I like are:

Interesting Uses

Tabbed Browsing

Tabbed browsing is nothing new -- but to have it in a text-browser was quite suprising. ELinks works by tabs anyway, rather than perhaps spawining off other windows which is what would have happened in a GUI web-browser. Indeed, to start a new tab, I could use:

File -> Open new tab

... or I could press 't', or press F10 and select the menu entry that way. Both operations open up a 'go to URL' dialogue box in which to enter a URL.

If I wanted to go to a new page in the current tab using the keyboard rather than the menu, I could just press 'g'.


URI re-writing

ELinks already comes with predefined sets of shortcuts one can use when entering URLs that are most frequently visited, or that often accept POST data to generate something -- such as a search or query. Known as Smart rewrites, these automatically fill in blanks for you. For instance, I might want to search google for 'The Happy Hippo'. All I would do then is to type:

gg:"The Happy Hippo"

... and the query would be performed. There's a stack of these predefined -- indeed, pressing 'o' will bring up the options manager --- an easy way of configuring all things ELinks. The other way would be to go to:

Setup -> Options Manager -> Protocols -> {Dumb,Smart} Prefixes

HTML re-writing

Other interesting things that one can do with ELinks is rewriting the HTML before it is rendered. ELinks supports some scripting languages: Perl, Lua, Guile, Ruby. This is particularly useful for sites that leave huge gaps, or have side banners that don't render properly. I use something similar to rerender the fvwm forum pages. The following screenshot shows what that is:

Screenshot of Fvwm Forums

What's been rewritten is the code in the left table, to change the colour of the text to green for read posts, and red for unread posts. I did this using Ruby:

    def ELinks::pre_format_html_hook(url, html)
      if url.grep("fvwm.lair.be\/(index|viewforum)*.\.php")
        # I don't like the fact that the <img> tags provide labels as
        # well as span classes.  So we'll remove them.
          html.gsub!(/(<img src.*\"No new
          posts\".*\>)/,"<font color=\"green\">No New Posts</font></td>")
          html.gsub!(/(<img src.*\"New
          posts\".*\>)/,"<font color=\"red\">New Posts</font></td>")
          html.gsub!(/<td><span class=\"gensmall\">([nN]o)|[Nn]ew      
          posts\<\/span\>\<\/td\>/,"<td></td>")
      end
      return html
  end

There's a number of pre-defined "hooks" that get referenced as a page loads. Here, the function ELinks::pre_format_html_hook will do any changes to an HTML document before it's rendered.


HTML-rewriting (continued)

Whilst the above section is simple, I find that for those sites which are frequented often (such as any phpBB forums) making it a little more permenant is a much "better" thing. For a standard site running phpBB the default display in ELinks is horrible. There's heavy use of CSS and ELinks' support for it is still very limited. Here's an annotated screenshot of some of the things I dislike about the layout:

elinks-prerender

In addition to that, the table borders for the main page should be shown as well. I'm also handling the matter of new/no posts by removing the words and creating coloured backgrounds. So far I've come across the following which I have assigned a colour value to. Visually I can then determine whether the selected thread has a new reply or not.

Type Colour
New Posts  
No New Posts  
Locked Posts  
Moved Posts  

There have been some other customisations, such as changing the alt attributes of some of the links so that they're shortened -- some of which are only available if one is a moderator or an administrator. Although an example screenshot of some of the customisations can be seen below.

elinks-postrender

All of the HTML rewrites are done using Ruby, which assumes that ELinks has been compiled with Ruby support. You can find the hooks.rb file (which you'd place in ~/.elinks/) here.


Opening webpages from external applications

One of the cool features of ELinks is that it supports Mozilla-like remote commands. For instance, if one spends a lot of time on IRC, then opening URLs is very easy.

elinks -remote $URL

... which, assuming ELinks is running, will connect to it, and open the page up in a new tab. I often scrape URLs out of irssi, using 'log.pl' and 'urlview' to do this.


Colours for ELinks

To get the most out of ELinks, it's probably best to run it in an environment that supports 256 colours. Xterm will do this, providing it has been told to do so at compile time.

The key combination '%' (Shift + 5) toggles between the colours of documents.

To change the colours of the interface, press 'o' for the Options Manager, and go to:

User Interface -> Color Settings -> Color Terminals

From there, one can change the colours of main ELinks interface. On my screenshots, the statusbar background is 'pink'. The tabs background is 'darkgrey', and the separators are 'yellow'.


External Editor Support

Sometimes, textareas that ELinks renders are too small, or annoying to type into. Assuming ELinks has been compiled, with external editor support, then it is possible to use such an editor. ELinks will use the environment variable $EDITOR. One can define that for ELinks thus:

EDITOR="gvim -f" /usr/local/bin/elinks

Then, when in a text-field, pressing "CTRL-T" will open the editor defined. Any existing text therein, is also made available for editing.

Note that you can also specify the editor that ELinks can use within ELinks itself, overriding the EDITOR environment variable. Found in:

Setup -> Option Manager -> Document -> Browing -> Forms -> External editor

URI-passing

The ability to pass URIs from within ELinks to external applications is something I really do find useful. For instance, you might decide that you want to open the current page in Firefox, or that you want to put the current URI of the page (or link) into the clipboard. The latter is what I tend to find the most useful.

The first step was to decide on a key-binding to use. Since there's two ways ELinks references links, I'd need a separate key for each. I decided I'd use Alt-o for the hilighted link, and Alt-p for the current page being viewed. Hence in ELinks, pressing k for the key-bindings dialogue meant I could find:

Main Mapping -> link-external-command

And assign that a binding of Alt-o. Likewise, I'd do the same for Alt-p -- however, I'd be assigning that to tab-external-command as that references the current page/tab I am looking in, as opposed to the selected link.

Main Mapping -> tab-external-command

Having done that, we then need to define a URI action that will take place. Currently (from what I can tell), it's not possible to define a specific action to a specific key. Instead, all actions appear in a central location. This is defined as being:

Setup -> Option Manager -> Document -> URI Passing

Then one simply has to Add an item to that location -- I've called mine clip. Once it is added, it hilight it and click on edit -- it's at this point the command you want to associate with the label clip is apparent. Since (in this example) the URI of the current page/tab or link needs to be made available, and that I do most of my work in X11, I used the following:

echo -n %c | xclip -i

And since the action is the same for both a page/tab and/or link, there's no need to define separate actions for both -- they're just calling that script within a different context. Note that I could add more entries for different actions with keybindings. If there's more than one entry, a menu pops up to select the action defined.


~/.elinks/elinks.conf

Some people have expressed an interest in my ~/.elinks/elinks.conf file, which you can find here.


Links

Some links to some other sites to do with ELinks: