2012-07-22 22:01:12 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2012.
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
This file is part of Sortix.
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2012-07-22 22:01:12 +00:00
|
|
|
|
2013-07-10 13:26:01 +00:00
|
|
|
sortix/kernel/textbuffer.h
|
|
|
|
Provides a indexable text buffer for used by text mode terminals.
|
2012-07-22 22:01:12 +00:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SORTIX_TEXTBUFFER_H
|
|
|
|
#define SORTIX_TEXTBUFFER_H
|
|
|
|
|
|
|
|
#include <sortix/kernel/kthread.h>
|
|
|
|
#include <sortix/kernel/refcount.h>
|
|
|
|
|
|
|
|
namespace Sortix {
|
|
|
|
|
|
|
|
struct TextPos
|
|
|
|
{
|
|
|
|
TextPos() { }
|
|
|
|
TextPos(size_t x, size_t y) : x(x), y(y) { }
|
|
|
|
size_t x;
|
|
|
|
size_t y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TextChar
|
|
|
|
{
|
|
|
|
TextChar() { }
|
|
|
|
TextChar(char c, uint8_t vgacolor) : c(c), vgacolor(vgacolor) { }
|
|
|
|
char c;
|
|
|
|
uint8_t vgacolor; // Format of <sortix/vga.h>
|
|
|
|
};
|
|
|
|
|
|
|
|
class TextBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~TextBuffer() { }
|
|
|
|
virtual size_t Width() const = 0;
|
|
|
|
virtual size_t Height() const = 0;
|
|
|
|
virtual TextChar GetChar(TextPos pos) const = 0;
|
|
|
|
virtual void SetChar(TextPos pos, TextChar c) = 0;
|
|
|
|
virtual uint16_t GetCharAttr(TextPos pos) const = 0;
|
|
|
|
virtual void SetCharAttr(TextPos pos, uint16_t attr) = 0;
|
|
|
|
virtual void Scroll(ssize_t off, TextChar fillwith) = 0;
|
|
|
|
virtual void Move(TextPos to, TextPos from, size_t numchars) = 0;
|
|
|
|
virtual void Fill(TextPos from, TextPos to, TextChar fillwith,
|
|
|
|
uint16_t fillattr) = 0;
|
|
|
|
virtual bool GetCursorEnabled() const = 0;
|
|
|
|
virtual void SetCursorEnabled(bool enablecursor) = 0;
|
|
|
|
virtual TextPos GetCursorPos() const = 0;
|
|
|
|
virtual void SetCursorPos(TextPos cursorpos) = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// The purpose of this handle class is such that the terminal driver can have
|
|
|
|
// its backing storage replaced at runtime, for instance if the user changes
|
|
|
|
// the screen resolution or the graphics driver. The backing text buffer can
|
|
|
|
// only be changed when there are no references (but our own) to the text buffer
|
|
|
|
// so don't forget to release it when you are done.
|
2012-08-07 22:19:44 +00:00
|
|
|
class TextBufferHandle : public Refcountable
|
2012-07-22 22:01:12 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextBufferHandle(TextBuffer* textbuf = NULL, bool deletebuf = true,
|
|
|
|
TextBuffer* def = NULL, bool deletedef = true);
|
2012-08-07 22:19:44 +00:00
|
|
|
virtual ~TextBufferHandle();
|
2012-07-22 22:01:12 +00:00
|
|
|
TextBuffer* Acquire();
|
|
|
|
void Release(TextBuffer* textbuf);
|
|
|
|
void Replace(TextBuffer* newtextbuf, bool deletebuf = true);
|
|
|
|
|
|
|
|
private:
|
|
|
|
kthread_mutex_t mutex;
|
|
|
|
kthread_cond_t unusedcond;
|
|
|
|
TextBuffer* textbuf;
|
|
|
|
TextBuffer* def;
|
|
|
|
size_t numused;
|
|
|
|
bool deletedef;
|
|
|
|
bool deletebuf;
|
2012-09-07 18:46:06 +00:00
|
|
|
|
2012-07-22 22:01:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Sortix
|
|
|
|
|
|
|
|
#endif
|