I have used Byobu for a bit and noticed something odd: I can split Byobu into tabs normally when I am using a terminal emulator, but when I am in a console or tty, pressing Shift+F2 only enters a tilde (~
) and Ctrl+F2 has no effect.
Is this a technical limitation? If so, how does it work?
That's a great question!
Sadly, the actual console TTY in Linux is not an actual Xterm, which is able to capture and support far more key presses.
I have long suspected that the Linux TTY could be taught to support the Shift-F-keys, though I've never gotten around to trying. Sorry.
A bit of background:
Historically, there have been lots of "terminal types" (a "terminal" is a keyboard & text display - xterm is a terminal type, so is the console), all of which had different keys. If you look at your keyboard now, it probably has a "Windows key", left of the spacebar. Macs don't have these, they might have an "Apple key" (google, if you want to see this). Some keyboards had a "Del" key where the backspace is on most modern keyboards. On some terminal types (e.g. teleprinters - essentially it used a printer as a screen), you could not "delete" a character. Did it have function keys? how many? Which character would make the cursor move back one character? Did the "carriage return" character move to the beginning of the current line, or the next line? How characters wide was the screen? Can you "display" do text colours? How do you change colours?
To make Unix/Linux as usable as possible, on as many terminals as possible, there are files which described what each terminal was capable of, and what keys should perform which functions (e.g. when you hit the "Del" key, it might work as "Del", or it might work as "Backspace"). These files (in Linux) can be found in /usr/sare/terminfo. Which of these is actually used is decided by the environment variable "TERM". if you "echo $TERM", you can see what it thinks you have.
If the terminal definition doesn't say you have particular keys, then there is no way for programs to receive those keys.
xterm, gnome-terminal use the 'xterm' terminal type, which supports things like function keys; the console uses (by default) the "linux" terminal type, which doesn't think it has these keys. Since the terminal type describes how to say the key has been pressed (and tells the receiving program how to listen for it, then byobu can't receive them, and so cannot act on them.
So that is "why". Now the solution. There are 3, as far as I can see (in "most convenient to least convenient order"):
Set a different terminal type, compatible with the actual terminal, but with more capabilities. NOTE: this has to be done BEFORE running byobu, not inside it. My install has over 1,600 terminal types, and if you set it to the wrong one, you may not be able to type, press enter, or the like. And setting it to something else doesn't necessarily give you that functionality - For example, if you are on the console, and you set the terminal type to "xterm", that doesn't give you the ability to resize your console with your mouse, nor will setting it to "dec" give you a "setup" key. However, most terminal types are mostly the same - 'a' will still be 'a'. You might see garbage characters, but usually not. I found that "TERM=linux-vt" seems to work pretty well. All of the keys I tried worked ok, except Alt-Function keys, and Alt-direction keys. Note that the Alt-Function keys and Alt-direction keys are handled by the console directly, to switch between virtual terminals.
Use alternative key combinations. All (as far as I'm aware) keybindings that are not accessible from the console, have alternative keybindings. For example, on the default install, Control-A followed by % will will do a horizontal split, and Control-A followed by a vertical pipe ("|") will do a vertical split. Control-A followed by a question mark will show the keybindings. I think it takes a while to understand what you're reading, but the main thing is the "-T " (root means it's always available, prefix means you have to hit Control-A first. If you "bind-key -T root a" to something, you won't be able to type 'a' anymore!). The next column (immediately after the key-table), is the key. The last column is what it runs. So if it says "bind-key -T prefix % split-window -h" then if you press the "prefix" (control-A) followed by '%', it will split the window (horizontally).
You can run these things from the commandline (often this only makes sense inside byobu), if you know what byobu calls it (and what options). Conveniently, this is the last column of the keybindings page. Just put 'byobu ' in front of it to do that from the commandline. For example, the keybindings page shows "bind-key -T prefix % split-window -h", so I can do the same by running the following command (from bash or the like) directly from inside byobu: "byobu split-window -h".