The twin window manager

The Text WINdow manager, twin, is quite a nice piece of software if you don’t
want to have to run X, though it can run within an X term.

GitHub – cosmos72/twin: Text mode window environment. A “retro” program for embedded or remote systems, that doubles as X11 terminal and text-mode equivalent of VNC server

I have found that it works extremely well with the ‘leggie’ fonts, from
Leggie, a legible, pretty bitmap font

Here is an example of a twin session, captured using fbcat.

4 windows within a twin session
twin is great for running a bunch of text applications

So this was a twin session, using the leggie18 font, on a netbook.

Top-left is a Gopherus session, top right is a window on my tilde.club account, bottom-left is Vim editing a LaTeX file and bottom-right is an Alpine
mail window.

twin has many capabilities — this only shows you what it looks like. One cannot run framebuffer graphics inside twin windows — eg fbi, or dosbox (which uses sdl) — but I have found that a twin window on one virtual console, and then a ‘bare’ framebuffer on a second one makes for a good combination for working without X.

I have noticed that some fonts give ugly outlines on the windows (rows of diamonds or non-characters). The leggie fonts on 32-bit Debian give neat lines around the windows. YMMV.

Some nice features include a built-in clock (see bottom-right corner), and the ability to type in a window while keeping it behind others. That’s why the screen capture command is invisible in the screen grab above. Alpine, links, lynx and other text-based network tools work fine, plus all your other console tools. It is very light on resources, too. top suggests it uses about 0.5% of my memory and CPU — and I am running an old netbook with 1GB RAM and an Atom N550 chip!

Could form the basis of a Linux distro to challenge TinyCore,

 

twin

LibreOffice command line — fabulously useful

The open source office suite, LibreOffice, is not only a very fine piece of software, it has some capabilities that leave many commercial products in the shade. One of them is a very powerful command line. It can do a lot of stuff without ever loading up the GUI. That makes it useful for batch processing of files and also for file format conversions.

For example, image you want to convert a Word (docx) file to PDF. You can open it in Word or LibreOffice and save to PDF. Or, at least on Linux (but Windows can do the same if you put the LibreOffice executables into your PATH), you can type one of the following:

$ libreoffice --convert-to pdf test.docx
$ soffice --convert-to pdf text.docx

(The $ is the prompt.) This will produce test.pdf, which you can then view or use as you see fit.

I have recently been playing around on Linux without the GUI (because I have an old netbook that gets a bit slow when lots of GUI stuff is loaded up).

Say I want to view a Word (or LibreOffice, or … whatever) document. My first port of call is a command like that above. Then I can type:

$ fbgs -xxl test.pdf

And I can view the PDF in the framebuffer, no X windows, no GUI, no lag. This is what it looks like:

Screenshot of text about using pandoc
A page of a Word document about pandoc, rendered as PDF by LibreOffice and viewed using fbgs

But of course this is really a corner case. Such a conversion is most likely to be useful when you want to convert a lot of files from one format to another. Opening them in the GUI and one by one saving would be a real pain. In Linux you could just type:

$ for f in *.docx ; do libreoffice --convert-to pdf $f ; done

and it would convert all the docx files in the directory. (See comments for further info on this.)

Now, of course, the quality of the conversion is limited by LibreOffice’s ability to interpret the file format of interest. But I have found it useful.

Libre!

ex-X: Linux without X windows

What works without X?

Screen shot of WordGrinder runnin in FBterm with a very big Glass TTY VT220 font.
Green on black is easy on the eyes!

Here is a screenshot of the Glass TTY VT220 font. Not sure how to grab a screen while inside the program, though. This was grabbed by exiting then running:

$ fbcat > screen.ppm
  • w3m with w3m-img (web browser)
  • cmatrix (screen saver —  actually works in any terminal)
cmatrix -- green letters cascading down the screen
cmatrix at work
  • Alpine (mail)
  • acpi (battery status)
  • shutdown -h now (don’t use sudo halt)
  • alsamixer (to set volume)
  • ogg123 and mpg123 (music player)
  • apt-cache search <searchterm> (find Debian packages without synaptic)
  • gnuplot-nox (plotting)
  • vim (of course)
  • DOSBox (uses SDL, so works too. That means you can run Windows 3.1 on Linux without running X. Fiddling with the config file lets it run fullscreen. The main trick is that usescancodes=false MUST be selected in the dosbox.conf file, or there’s a good chance it will misread the keyboard, preventing you from typing any commands or even using Alt+Ctrl+Fn to change virtual terms. This may force a hard reset.)
  • twin — text-mode window manager (https://github.com/cosmos72/twin)
  • tty-clock
  • cal/ncal/calendar
  • bastet (tetris…)
  • freesweep (minesweeper)
  • sopwith (sopwith)
  • sc (spreadsheet)

LaTeX plus fbgs works perfectly well for writing documents. If Vim is set up to allow compiling and viewing from within Vim, then LaTeX works really seamlessly. I added a command to my .vimrc:

cat ~/.vimrc

syntax enable

command L !latex %
command B !bib.sh %
command V !dviv.sh %
command A !dvia.sh %
command D !dvips.sh %
command G !gv.sh %
command M !maki.sh %
command F !pdfv.sh %
command I !spell.sh %
command PP !ps2pdf.sh %
command PDF !pdflatex %
command W !wc %
command XF !xfig &
command T !dvi2tty.sh %
command WT !wctty.sh %
command VT !viewtty.sh %
command FB !viewfb.sh %

So within Vim in command mode I run :L to LaTeX a file (makes the dvi) then :D to make the PostScript and  :FB to view it in the framebuffer viewer. When I exit the viewer, I drop back into Vim. Could also run fbgs in a second virtual term.

$ cat ~/bin/viewfb.sh

#!/bin/bash
NM=`basename $1 .tex`.ps
fbgs -r 300 $NM

Or we can go totally text and view the output of dvi2tty; this script runs dvi2tty then views the result:

#!/bin/bash
NM=`basename $1 .tex`.tty
IM=`basename $1 .tex`.dvi
dvi2tty -w80 $IM > $NM
echo Created $NM, piping into view
sleep 2s
view $NM

Ahh… it’s like being in DOS.

Edit bdf fonts — gbdfed on Cygwin

gbdfed is a nice bdf font editor. It can export to PSF, which is the format used in virtual terminals (ie without X). So if we want to use a personal favourite font in a VT or framebuffer console, it could be part of translating it from one format to another. To my imperfect knowledge, FontForge, brilliant as it is, does not do this.

To install it on Cygwin, first install all the Cygwin FreeType stuff using setup.exe, the Cygwin installer; also needs gtk2 and some other stuff; see the README. Then:

$ git clone https://github.com/andrewshadura/gbdfed.git
$ cd gbdfed/
$ vim README
$ ./configure 2> config.log2 > config.log1
$ make 2> make.log2 > make.log1
$ make install
./mkinstalldirs /usr/local/bin /usr/local/share/man/man1
cp gbdfed /usr/local/bin/gbdfed
cp gbdfed.man /usr/local/share/man/man1/gbdfed.1

That’s it. Here’s a picture:

Screen shot of the font editor editor
MZ font in gbdfed on Cygwin

 

Noice.

Choosing a virtual terminal font on Debian

I’ve been playing around in the framebuffer/text console, partly because my old netbook is, well, not the most powerful machine going around. I’ve figured out how to boot into the console and to get the interwebs to go. Now, the default console font it too small, so I want to explore options for custom terminal fonts — ideally, something bigger and may be nicer.

The first thing is to explore the options using:

$ sudo dpkg-reconfigure console-setup

And then decide on a font. This link may be useful: https://unix.stackexchange.com/questions/198791/how-do-i-permanently-change-the-console-tty-font-type-so-it-holds-after-reboot

Eventually, I edited /etc/default/console-setup to look like:

# CONFIGURATION FILE FOR SETUPCON
# Consult the console-setup(5) manual page.
ACTIVE_CONSOLES="/dev/tty[1-6]"
#CHARMAP="UTF-8"
#CODESET="Lat15"
#FONTFACE="TerminusBold"
#FONTSIZE="24x12"
FONT="Lat7-TerminusBold24x12.psf.gz"
VIDEOMODE=
# The following is an example how to use a braille font
# FONT='lat9w-08.psf.gz brl-8x8.psf'

And then ran:

$ setupcon

(Run as sudo it changes all virtual terms, run as user it changes the current one.) And that works fine, though I found that I have to run it each time I log in. So I just added it to .profile; could also mess with setfont.

Now, the mouse. The simplest way is to use gpm. I am just using it as a 2-button mouse because my touchpad has 2 buttons, and since I’m not using a GUI, right click is not needed for context menu, so can be paste.

$ sudo gpm -2 -m /dev/input/mice -t imps2

So at this point I have control over the console font (look for others in (/usr/share/consolefonts/), I have interweb and mouse, it’s just a question of applications.

One last thing; the console fonts are PSF fonts (often psf.gz). If you find the range of options limited, there are tools out there to convert other fonts to PSF, possibly via other formats (likely bdf); you may need to explore the command line options to get a font that works at the size and in the encoding that you want. For example, http://www.seasip.info/Unix/PSF/, otf2bdf, ttf2bdf, bdf2psf, gbdfed. (And FontForge of course.) I have not tested all there tools myself yet!

gbdfed

Getting wireless networking without running X windows — Debian

I can boot into a text terminal now but I have no internet, since it seems to be handled by the GUI (NetworkManager rings a bell), so that’s an issue. With some googling, I get the solution. The magic is at: https://linuxcommando.blogspot.com/2013/10/how-to-connect-to-wpawpa2-wifi-network.html

This is a step-to-step guide for connecting to a WPA/WPA2 WiFi network via the Linux command line interface. The tools are:
wpa_supplicant
iw
ip
ping

1. Find the wireless device name:

$ /sbin/iw dev
phy#0

#iw dev

Interface wlan0
ifindex 3
wdev 0x1
addr 88:xx:xx:xx:xx:xx
type managed
txpower 0.00 dBm

2. See what it’s doing:

$ ip link show wlan0

3: wlan0: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 88:xx:xx:xx:xx:5a brd ff:ff:ff:ff:ff:ff

3. Turn it on — maybe twice if need be:

$ sudo ip link set wlan0 up
$ sudo ip link set wlan0 up

4. Check if that worked:

$ ip link show wlan0

And look for ‘UP’

5. So the interface is up, but is it connected to the wider net? No, but we can show this:

$ sudo iw wlan0 link
Not connected.

6. Look for a network to connect to; look for a line that says ‘SSID’:

$ sudo iw wlan0 scan | grep SSID

SSID: Fred 123

7. Then copy that to a config file (use quotes if there are any non-alphanumeric characters, like spaces):

$ su
# wpa_passphrase "Fred 123" >> /etc/wpa_supplicant.conf
# wpa_supplicant -B -D wext -i wlan0 -c /etc/wpa_supplicant.conf

8. Now, this is where I found the instructions at the Linux Commando page did not work for me (they may well work for you). I found that I had to get rid of the ‘-D wext’ bit and trust to the automagic abilities of the command:

# wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf

9. Use dhcp to assign IP numbers

# dhclient wlan0
# exit

10. Check that we’re connected:

$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=94.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=172 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=522 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=55 time=71.7 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3002ms

OK!

OK, so that was the first connection. We set up the config files, and we don’t need to do that twice. For future use, wrapped it up in ~/bin/wireless.sh:

$ cat ~/bin/wireless.sh
#! /bin/bash
ip link show wlan
sleep 2s
sudo ip link set wlan0 up
sleep 2s
sudo ip link set wlan0 up
sleep 2s
echo Yes, run twice
sleep 2s
ip link show wlan0
sleep 2s
sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
sleep 2s
sudo dhclient wlan0
sleep 2s
echo
echo Ctrl+c to quit ping and see if it has worked
echo
ping 8.8.8.8

Seems to work. I could run it from .profile, but I’ve left it as a separate thing. Sometimes, it’s better to be off the ‘net!

&nbsp;

Booting Debian into a text/framebuffer console

Trying to put together a boot menu option to boot into a text/framebuffer environment and not start X. Debian 9.9 (default install, so uses systemd), i386, so a pretty common platform. Some googling suggests:

$ sudo systemctl set-default multi-user.target
$ sudo reboot

But this did not work. Tried:

$ sudo vim /etc/grub.d/40_custom

then added:

menuentry "Text console" {
set root=(hd0,1)
linux /vmlinuz root=/dev/sda1 systemd.unit=multi-user.target ro
initrd /initrd.img
}
$ sudo update-grub
$ sudo reboot

Nope, does not work. Still boots into wdm. Try some tests.

$ sudo systemctl set-default multi-user.target
$ sudo systemctl get-default
multi-user.target

So the default has changed — it just has no effect. Is this a bug? I guess I can hit ‘e’ on boot and change the Linux line to end in 3… try that… does not work. I guess I should not expect runlevels to work on a systemd system. Now:

$ cat /lib/systemd/system/default.target

shows that the target has not been changed. It still points to graphical.target. In other words, the advertised process does not (seem to) work. Now, I don’t want my default target to be text mode, I want a boot option for that.

What if I create a custom target by simply copying multi? Maybe it needs a custom name to work?!?!

$ cd /lib/systemd/system
$ sudo cp multi-user.target custom.target
$ sudo cp -r multi-user.target.wants custom.target

Then:

$ sudo systemctl set-default custom.target
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /lib/systemd/system/custom.target.

This output did not happen before.

$ sudo systemctl get-default
custom.target

$ ls -l default.target
lrwxrwxrwx 1 root root 16 Apr 8 20:51 default.target -> graphical.target

Nope — does not work!

What if I make a grub entry use custom and reboot? Other option would be to hand make the symlink… but I want options on the boot menu. OK, first set default back anyway, even though it does nothing:

$ sudo systemctl set-default graphical.target

All is now put back how it was, so now change 40_custom to say custom.target (did not work when changed to multi-user.target, but…), so it looks like:

#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Text console" {
set root=(hd0,1)
linux /vmlinuz root=/dev/sda1 ro systemd.unit=custom.target
initrd /initrd.img
}

Reboot, choose that option and … worked! I can now boot into a text console, with 6 virtual terminals but no X server.

 

Boots.

Gmail for older computers and the command line — Alpine

We used to be able to access Gmail from browsers without JavaScript, but that’s no longer the case. So now, if going by browser, I need to install a relatively heavy-duty piece of kit like Firefox or Chrome (heavy compared with say Links or Dillo). But can still get at the email without…

I started by installing Alpine mail reader. On Debian, it’s

$ sudo apt install alpine

I then logged into my Gmail account as usual (ie in Firefox) and went to Settings → Forwarding and POP/IMAP and chose Enable IMAP (IMAP is preferable to POP if I want to use this method on more than one computer — it does a better job of syncing between sessions).

Then clicked on Configuration instructions, opened up Alpine and did what the Google instructions said.

Updated my details as per the gmail website instructions. These websites are also handy:

Compile: http://www.chiark.greenend.org.uk/doc/alpine-doc/tech-notes/installation.html

Save password: https://scienceblogs.com/gregladen/2009/10/08/do-you-want-the-alpine-email-c

But the best guide is at:

https://bcacciaaudio.com/2018/10/09/alpine-mail-setup-with-gmail/

Especially:

Navigate to Setup > Config and check off the following items:

  • Compensate for deficient IMAP servers

  • Combined Folder Display

  • Enable incoming folders collection

  • Enable incoming folders checking

but note that an app-specific password is necessary (or was for me) — this is a 16-letter combination you can generate after logging into your Google account and going to Security (you must have turned on 2-factor authentication, too). Also, unless you want to have to note it down and reenter it multiple times, go to the ‘Save password’ link noted above and turn on Alpine password saving (on Linux, $ touch ~/.pine-passfile). Note that this may be a security issue; the encryption in this file is (apparently) not that strong. I don’t know.

So ran Alpine, went (S)etup and Co(L)lections and (A)dd, then entered:

Nickname : Gmail
Server : imap.gmail.com/ssl/user=first.second@gmail.com
Path :
View :

On hitting ‘Enter’ after the imap line, I was asked for my password. Used the 16-letter app-specific password.

Then, back to the main menu of Alpine and:

(S)etup (C)onfig

Personal Name = <No Value Set: using "Username">
User Domain = gmail.com
SMTP Server (for sending) = smtp.gmail.com:587/tls/user=first.second@gmail.com

See also the Gmail help page — https://support.google.com/mail/answer/7126229.

Also, went to Gmail on the web, and set:

Limit IMAP folders to contain no more than this many messages = 1000

And that allows use of Gmail without JavaScript or even a GUI — no need for X windows, for example. I’m sure other mail clients would work just as well.
screen shot showing the main menu -- Help, Compose, Message Index, Folder List, Address book, Set up and Quit
The Alpine front page
viewing system mail -- three messages
A typical Alpine screen

netsurf and netsurf-fb

I (re)installed netsurf on Debian:

$ sudo apt-get --reinstall install netsurf

I can run it from the Applications menu, but typing netsurf at an xterm prompt gives me:

$ netsurf
Unable to initialise the font system

but that’s because I should be running

$ netsurf-gtk

And that works great. Now, I have also been playing with frame buffer applications, and working without X in general. Netsurf plays a very rare role there, because it includes a frame buffer version, netsurf-fb.

At first I could not get netsurf-fb to run, but after some searching… found this page. I’ll link to the original source:

https://askubuntu.com/questions/817937/how-to-run-netsurf-fb-fails-with-unable-to-set-video-could-not-set-console-s

In summary:

$ sudo apt install xserver-xorg-video-fbdev fbset
$ sudo cp /usr/share/fonts/truetype/dejavu/DejaVu* /usr/share/netsurf

Then, in a virtual terminal (not a terminal emulator running under X):

$ sudo gpm -3 -m /dev/input/mice -t imps2
$ netsurf-fb --window_width 1000 --window_height 1000

Hint: Frame buffer stuff can make your computer hang such that it needs a hard reset, so don’t have any files open when you play with it.

Yay! It worked. Some oddities:

(1) I seemed to get a UK keyboard (shift-2 gave me a quote mark rather than a @ when typing an email address)

(2) I could not download anything

(3) After doing this, I could run netsurf in an X term (no -gtk) and get a browser session, but it looked like the barer framebuffer session. I think copying the fonts was the key step.

Petty good, really. There’s some documentation at https://ci.netsurf-browser.org/jenkins/vcdiew/Categorized/job/docs-netsurf/doxygen/md_docs_using-framebuffer.html that shows that this version was never meant to be as feature-full as the gtk-type ones. It still works very well for graphical browsing without X, though logging in to things like gmail and such may be a problem.

netsurf-fb -- screenshot
netsurf-fb in the framebuffer — a more minimal interface, but works well

Other good browser options include links and lynx for text browsing and links2 -g for graphical-ish browsing.

 

Notes in the void