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>
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>
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>
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>
*_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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
If the child returns EWOULDBLOCK on write we need to save the input in a
buffer to avoid loosing data. We need to work in non-blocking mode to
avoid UI hangs so we simply use the new ring-buffer object to store
data.
This also changes the callback behavior. The pty is no longer closed
implicitely so the owner must call pty_close now even if the close
callback is called. This avoids circular callbacks.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>