236 Commits

Author SHA1 Message Date
David Herrmann
7c8eb3b108 console: fix bug in buffer-erase helper
We didn't check for NULL line so we got segfaults when erasing empty
lines. Fix this.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 15:44:20 +01:00
David Herrmann
d3951da865 console: add helper to erase current position
This helper erases the current cursor position.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 15:14:45 +01:00
David Herrmann
b02e8c8332 console: fix pending-wrap bug in erase helpers
When erasing from the cursor position to line/screen end we must include
the current cursor position in the clear-region. We already did this but
missed the fact that there might be a pending-wrap so we might miss the
current position. Fix this.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 15:11:34 +01:00
David Herrmann
fb6dd53aa8 console: enable auto_wrap by default
vt100 have auto_wrap enabled by default so we should do so, too.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 15:10:12 +01:00
David Herrmann
9a5f1df8cd console: fix bug in *_erase_screen()
We must erase the whole screen and not only until the current cursor
position. Probably a copy-paste typo.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 15:06:06 +01:00
David Herrmann
5e53cda8f5 console: fix bug in *_move_left()
We must take care of pending-wraps when moving left so we do not miss a
single character.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 15:04:43 +01:00
David Herrmann
f0bcc37cee console: add to line movement helpers
Add two helpers to move to the end or home of the current line.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-05 14:36:32 +01:00
David Herrmann
f85244ead9 console: add erase-helpers
Add functions to erase several parts of the screen.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 18:31:10 +01:00
Ran Benita
37cb482bbc ring: fix is_empty
Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 16:30:24 +01:00
David Herrmann
138c0aa5ee console: add function to erase buffer
New function which helps erasing a whole region of the buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 16:24:01 +01:00
David Herrmann
d8ff83c5cb console: add basic cursor movements
Add functions to move the cursor up/down/left/right. We must take care
of integer overflows here as the application may send us arbitrarily big
numbers.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 15:50:03 +01:00
David Herrmann
466fcc3b06 console: add auto-wrap mode
If auto-wrap mode is enabled we automatically advance the cursor to the
next line if we hit the end of line. Otherwise, we simply continue
overwriting the last character in the line.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 15:49:14 +01:00
David Herrmann
497d3840dc console: add *_move_to() function
*_move_to() can be used to position the pointer at an arbitrary position
inside the buffer. If in relative-addressing mode, you cannot position
it outside the scroll-region, though.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 15:25:44 +01:00
David Herrmann
5a0ba19d91 console: make console wrapper margin aware
Keep reference to top-most and bottom-most line of scroll buffer in
console wrapper. The margin_top and margin_bottom indexes are different
from them used in the buffer handler! We use indexes now instead of line
counts. This makes the handling much easier.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 14:49:06 +01:00
David Herrmann
2b8caca91c console: remove *_buffer_newline()
This function is no longer needed as we now have proper scrolling
functions. This also adjusts the buffer tests to be more appropriate.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 14:34:33 +01:00
David Herrmann
bff87253a8 console: fix bug in console resizing
When resizing the scroll buffer to a bigger size we try to get lines
from the scroll-back buffer into our current buffer. However, we do not
know how many lines we can get so we start filling the bottom of the
buffer and when no more lines are available, we simply move these lines
to the top of the buffer.
However, we didn't clear the bottom of the buffer after that operation
so if the scroll-back buffer is too small to get us enough lines for
resizing, we currently have a corrupted buffer-bottom. This fixes this
bug by simply setting those lines to NULL as anyone would expect.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-04 14:32:09 +01:00
David Herrmann
0c7e50433a console: implement proper scrolling
Add two new functions to rotate the scroll-area of the buffer. We push
lines to the scroll-back buffer if they are pushed out to the top. Lines
pushed out to the bottom are simply freed.
We never take back lines from the scrollback buffer as applications
expect the new lines to be empty.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-03 23:47:09 +01:00
David Herrmann
ff408d6fb9 test_buffer: add margin tests
Modify the buffer test to add margin tests.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-03 18:43:56 +01:00
David Herrmann
b367a9682c console: add margin API
Allow external subsystems to modify the margin sizes. When setting the
margins we must take care to first perform the shrink operation and then
the grow operations. For instance, if our current top margin is 10 and
the bottom margin is 0 and the application requests to swap the margin
sizes, we should *first* shrink the top margin to 0 and then grow the
bottom margin to 10. Otherwise, we might end up with garbled margins on
a buffer which is smaller than 20 lines.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-03 17:48:35 +01:00
David Herrmann
cd62b330be console: add margin support
Margins are a method to stick lines to the top and bottom of a buffer
and ignore them during console-rotations. We keep 3 different buffers,
two static buffers for the top and bottom margin and one buffer for the
scroll region. The scroll region is always big enough to hold all three
buffers even though it does not contain them. This allows us to merge
the margins back to the scroll-buffer very fast without reallocations.

The buffer layout is the top-margin at the top. The scroll region is
below and the bottom margin is at the bottom. If we rotate the buffer,
we do not touch the margins but simply rotate the scroll buffer. This
may corrupt the scroll-back buffer but there is no sane way to implement
this. The original VTs did not support this either.

Even though we have multiple buffers we keep the buffer-fill logic. That
is, the scroll buffer is not always fully filled. However, if we merge
back the bottom buffer to the scroll buffer, we set the scroll buffer to
be fully filled. Otherwise, we would have artifacts at the bottom.
The top margin does not show this behavior as it is not affected by
rotations below the fill-line.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-03 17:47:46 +01:00
David Herrmann
c4a4e796e7 console: rename buffer to scroll-buffer
The main buffer of the console buffer is now renamed to scroll-buffer.
This allows us to add other buffers like a margin-buffer to the same
buffer object.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-03 15:22:36 +01:00
David Herrmann
d06e28aa05 console: do not fill buffer if not required
We allow NULL lines in the buffer so we no longer have to create empty
lines when writing anywhere in the buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 17:52:54 +01:00
David Herrmann
8ed50af667 console: allow NULL lines in buffer
If we see a NULL line inside the buffer we assume the line is empty.
That is, we now longer abort the drawing but continue with the next
line.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 17:44:54 +01:00
David Herrmann
ebef2a016b console: allow to push empty lines to scrollback buffer
When pushing a line=NULL to the scrollback buffer we now assume that the
line was empty and we allocate a new empty line. If the allocation fails
we simply drop that line.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 17:41:43 +01:00
David Herrmann
af3a1f3e50 console: move kmscon_console_rotate to *_newline
We do no rotation so rename the function to the more appropriate name
kmscon_console_newline.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 17:01:54 +01:00
David Herrmann
09e15d84e8 console: add function to clear scrollback buffer
The new function can be used by the UI to clear the current scrollback
buffer to free resources or whatever. It will also be used by the CSI
handler to reset the console.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 16:47:43 +01:00
David Herrmann
3560ae8eb1 console: add function to set max scrollback buffer size
The maximum scrollback-buffer size can now be changed on the fly. We
also reduce the current buffer size to the new size so we do not need to
clear the console to flush the scrollback buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 16:43:15 +01:00
David Herrmann
bb918d9361 console: set sb_max to 0 by default
The scrollback-buffer maximum is 0 by default to avoid strange
hard-coded default values.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 16:33:00 +01:00
David Herrmann
54a552b852 console: allow scrollback-buffer maximum = 0
The scrollback buffer has a variable maximum of lines which can be set
by the application. We currently require it to be greater than 0. This
allows sb_max to be 0 so we can have a console buffer without a
scroll-back buffer.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-02 16:30:18 +01:00
Ran Benita
fb14273bf7 eloop: add timer support
Add support for dispatching events every given interval. timerfd is used
for hooking up to the event loop, similar to how signalfd is used.

Only relative, monotonic and possibly repeating timer events are
supported. It can be enhanced if there's ever a need.

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-01 22:35:54 +01:00
David Herrmann
8fa3336a6b vte: add stub CSI parser
The new parser reads CSI parameters correctly and saves them in an array
for later evaluation. We currently do not handle the CSI commands. This
needs to be added now.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-01 19:33:38 +01:00
David Herrmann
0e31653eb1 vte: parse basic control codes
This adds a parser for basic control codes but does not implement their
functionality, yet. Only the newline handler is kept.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-01 17:13:22 +01:00
David Herrmann
c4683b34ef vte: first check for special keys then for ucs4 char
We should first check whether we recognize the XK_* identifier before we
rely on the converted UCS4 character.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-01 16:03:54 +01:00
David Herrmann
23b7270790 vte: implement basic key mappings
The system keys are mapped to their ASCII equivalents. We do not support
CR/NL mode nor scroll-lock yet (is this supported by any term?).

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-02-01 15:59:53 +01:00
David Herrmann
d5c4d80562 doc: add VTE links and resources
The vte.txt file will contain information about the terminal emulator
used by KMSCON. Our main goal is xterm-compatibility but for now it
might be easier to try to be linux-console compatible.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-31 19:59:02 +01:00
David Herrmann
7a31fa98d6 pty: avoid 4KB buffers on the stack
Allocate the IO-buffer dynamically on the heap for every pty object to
avoid 4KB objects on the stack. This may not be a problem now but we
might get stack overflows later if we continue to use such huge arrays
on the stack.

This doesn't affect the runtime performance as the buffer is still
allocated only once on pty-creation.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-30 22:01:32 +01:00
Ran Benita
9d4cd66631 pty: increase input buffer size
Increase the buffer size to match the kernel's. This should guarantee
(practically) that we read() everything queued up for us.

This speeds us up considerably when running something like
$ find /
Such a process spends most of its time blocking on write() waiting for
us. By increasing the buffer size we avoid repeated
read pty -> draw screen -> read pty
cycles, which take most of our time.

To time it, before:
real  0m22.588s
user  0m00.000s
sys   0m00.020s

After:
real  0m00.680s
user  0m00.023s
sys   0m00.000s

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-30 20:51:27 +01:00
Ran Benita
9c97408910 kbd: correctly initialize refcount
The ->ref field was always zero and so the object was never released.

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-30 20:48:31 +01:00
Ran Benita
6eb0f706d7 xkb: fix invalid read from uninitialized memory
The memset was missing a sizeof(..) multiplication.

Really the entire function is more complex than need be, so simplify it.

Signed-off-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-30 20:48:13 +01:00
David Herrmann
f8b17b1ffc Remove TODO
The TODO is now located in the wiki at github.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-29 17:10:51 +01:00
David Herrmann
e138e4ada0 vte: handle keyboard "return"/linefeed
This makes the VTE subsystem emulate a linefeed if XK_Return is read
from the keyboard.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-29 14:51:35 +01:00
David Herrmann
ff0e91ec45 terminal: use UTF8 state machine
This adds a converter from UTF8 stream to UCS4 data so the VTE subsystem
can handle the input correctly without complicated UTF8 input.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-29 14:23:27 +01:00
David Herrmann
885bdef87b pty: change callback parameters to "const xy"
There is no reason to allow the callbacks to modify our internal data so
make it constant.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-29 14:22:48 +01:00
David Herrmann
2ddd47e858 test_buffer: add utf8 state machine test
Add trivial test to show how to use the utf8 state machine.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-29 14:21:19 +01:00
David Herrmann
046d397987 unicode: add utf8 state machine
The state machine is used to convert a stream of UTF8 data into UCS4
characters. It is slightly based on the machine found in the
wayland-compositor demos.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-29 14:19:49 +01:00
David Herrmann
79e1ada7e5 vte: handle keyboard input (stub)
Make the vte subsystem handle the keyboard input instead of doing this
inside of test_terminal.

The handling is just a stub function. No actual keys are parsed yet.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-28 22:14:20 +01:00
David Herrmann
55d4132931 console: add header protection
The header was missing a #ifndef to protect against multiple inclusions.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-28 18:08:10 +01:00
David Herrmann
f63eaffc95 pty: remove unneeded variable in setup_child
We can use "ret" instead of "saved_errno" here.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-28 17:43:26 +01:00
David Herrmann
d8d0e24a22 pty: move fork_pty_child to setup_child
The name fork_pty_child was misleading. It doesn't fork at all but
instead sets up the child's environment.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-28 17:39:20 +01:00
David Herrmann
31fc374065 pty: avoid FIONREAD ioctl
This ioctl is really not needed and performs needles kernel context
switches. We can simply read into our buffer without checking how many
data is available.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
2012-01-28 17:23:49 +01:00