terminal: close pty before opening it

There is no explicit call to reopen the underlying pty so we simply
force-close it before (re)-opening it. This will allow the UI to reopen a
pty when the child died.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
ui: reopen terminal on HUP

We now automatically reopen the pty when the child process died. This will
most-often simply restart the shell or login program.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: allow retrieving cursor state

This adds two functions to retrieve x/y positions of the cursor. This can
be used to save and restore cursor positions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: implement DECSC DECRC

DECSC is used to save the current console state. DECRC can restore the
console to a previously saved state.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: reset margins on soft-reset

Instruct console code to reset the console margins to default values (that
is, destroy the margins) on console soft-reset.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: add tab-ruler support

The tab-ruler is used to set console tab-stops. We use an array with one
cell per column that is set to true if it is a tab-stop and false if it is
not.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Add optional dbus support

As we might need dbus for inter-process-communication later, this adds a
very rudimentary dbus client integration for epoll-based loops.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: implement console soft-reset

On soft-reset we reset the console to the initial state but keep current
line-state. That is, scrollback and cursor position are kept but the
non-visible state is reset.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: fix tab ruler to be horizontal

Whoops, current tab ruler turned out to be vertical. That's definitely not
what we want. Therefore, turn it around to be horizontal so we can
correctly move forward/backward in the console.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: add tab-stop helpers

Add three helpers to set and reset tab-stops. They will be used by the VTE
layer to add and remove tab-stops when requested by the application.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: allow setting tab-stops

Allow applications to set new tab-stops according to vt220 rules.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: implement TBC

Implement TBC CSI which clears the current or all tab-stops. This is
according to VT220 rules.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: support "protect" character attribute

VT220 allows protecting attributes. That is, they are not erased by
special new erase-commands. The normal erase-commands still erase all
characters.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console/vte: implement ICH DCH

ICH is used to insert characters into the current line. DCH is used to
delete characters from the current line. They act as described in vt220
manual.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: tune SGR handling

We definitely do not need to check the unset parameters so shorten the
loop so unparsed parameters are not checked.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: hide cursor if requested

When the HIDE_CURSOR flag is set, we must not draw the cursor.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: fix application cursor keys

This is probably a copy/paste bug but we sent the wrong application cursor
key sequences. This is only visible in xterm-mode so nobody noticed until
now.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
vte: extend SGR/color handling

This adds full xterm 256color support and improves SGR handling in
general.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: allow erasing partial lines

Later VTs allow erasing only partial lines so add support for that in the
console backend.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
console: fix invalid cursor state after resize

Set cursor state to next valid position on resize to avoid invalid cursor
states.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>