mirror of
https://github.com/usatiuk/ficus.git
synced 2025-10-28 16:17:51 +01:00
FbTty: clear lines
This commit is contained in:
@@ -10,19 +10,33 @@
|
|||||||
FbTty::FbTty(Framebuffer *fb) : _fb(fb) {
|
FbTty::FbTty(Framebuffer *fb) : _fb(fb) {
|
||||||
_max_col = _fb->dimensions().x / 8;
|
_max_col = _fb->dimensions().x / 8;
|
||||||
_max_row = _fb->dimensions().y / 16;
|
_max_row = _fb->dimensions().y / 16;
|
||||||
|
_buf.resize(_max_col);
|
||||||
|
for (auto &b: _buf) {
|
||||||
|
b.resize(_max_row);
|
||||||
|
for (int i = 0; i < _max_row; i++)
|
||||||
|
b[i] = ' ';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FbTty::draw_char(int col, int row) {
|
||||||
|
for (int x = 0; x < 8; x++) {
|
||||||
|
for (int y = 0; y < 16; y++) {
|
||||||
|
uint32_t color = (fonts_Terminess_Powerline[_buf[col][row]][y] & (1 << (8 - x))) ? 0xFFFFFF : 0;
|
||||||
|
_fb->set(col * 8 + x, row * 16 + y, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FbTty::putchar(char c) {
|
void FbTty::putchar(char c) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
next_row();
|
next_row();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int x = 0; x < 8; x++) {
|
_buf[_cur_col][_cur_row] = c;
|
||||||
for (int y = 0; y < 16; y++) {
|
|
||||||
uint32_t color = (fonts_Terminess_Powerline[c][y] & (1 << (8 - x))) ? 0xFFFFFF : 0;
|
draw_char(_cur_col, _cur_row);
|
||||||
_fb->set(_cur_col * 8 + x, _cur_row * 16 + y, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
next_col();
|
next_col();
|
||||||
}
|
}
|
||||||
void FbTty::putstr(const char *str) {
|
void FbTty::putstr(const char *str) {
|
||||||
@@ -40,10 +54,19 @@ char FbTty::readchar() {
|
|||||||
void FbTty::next_col() {
|
void FbTty::next_col() {
|
||||||
_cur_col++;
|
_cur_col++;
|
||||||
_cur_col = _cur_col % _max_col;
|
_cur_col = _cur_col % _max_col;
|
||||||
if (_cur_col == 0) next_row();
|
if (_cur_col == 0) {
|
||||||
|
next_row();
|
||||||
|
} else {
|
||||||
|
_buf[_cur_col][_cur_row] = ' ';
|
||||||
|
draw_char(_cur_col, _cur_row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void FbTty::next_row() {
|
void FbTty::next_row() {
|
||||||
_cur_col = 0;
|
_cur_col = 0;
|
||||||
_cur_row++;
|
_cur_row++;
|
||||||
_cur_row = _cur_row % _max_row;
|
_cur_row = _cur_row % _max_row;
|
||||||
|
for (int i = 0; i < _max_col; i++) {
|
||||||
|
_buf[i][_cur_row] = ' ';
|
||||||
|
draw_char(i, _cur_row);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,15 @@
|
|||||||
|
|
||||||
#ifndef FBTTY_HPP
|
#ifndef FBTTY_HPP
|
||||||
#define FBTTY_HPP
|
#define FBTTY_HPP
|
||||||
|
|
||||||
#include <PS2Keyboard.hpp>
|
#include <PS2Keyboard.hpp>
|
||||||
#include <Tty.hpp>
|
#include <Tty.hpp>
|
||||||
|
#include <Vector.hpp>
|
||||||
|
|
||||||
class Framebuffer;
|
class Framebuffer;
|
||||||
class FbTty : public Tty {
|
class FbTty : public Tty {
|
||||||
public:
|
public:
|
||||||
FbTty(Framebuffer *fb);
|
FbTty(Framebuffer *fb);
|
||||||
virtual ~FbTty() = default;
|
virtual ~FbTty() = default;
|
||||||
|
|
||||||
void putchar(char c) override;
|
void putchar(char c) override;
|
||||||
@@ -19,6 +20,8 @@ public:
|
|||||||
char readchar() override;
|
char readchar() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void draw_char(int col, int row);
|
||||||
|
|
||||||
Framebuffer *_fb;
|
Framebuffer *_fb;
|
||||||
|
|
||||||
int _cur_col = 0;
|
int _cur_col = 0;
|
||||||
@@ -27,6 +30,8 @@ private:
|
|||||||
int _max_row = 0;
|
int _max_row = 0;
|
||||||
int _max_col = 0;
|
int _max_col = 0;
|
||||||
|
|
||||||
|
Vector<Vector<char>> _buf;
|
||||||
|
|
||||||
void next_col();
|
void next_col();
|
||||||
void next_row();
|
void next_row();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef VECTOR_H
|
#ifndef VECTOR_H
|
||||||
#define VECTOR_H
|
#define VECTOR_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -146,6 +147,34 @@ public:
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resize(size_t size) {
|
||||||
|
if (size == _cur_size) return;
|
||||||
|
|
||||||
|
if (size < _cur_size) {
|
||||||
|
for (int i = size; i < _cur_size; i++) {
|
||||||
|
if constexpr (!std::is_trivially_destructible<T>::value)
|
||||||
|
std::destroy_at(_data + i);
|
||||||
|
}
|
||||||
|
_cur_size = size;
|
||||||
|
compact();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > _cur_size) {
|
||||||
|
if (_capacity < size) {
|
||||||
|
_capacity = size;
|
||||||
|
_data = (T *) krealloc(reinterpret_cast<char *>(_data), _capacity * sizeof(T));
|
||||||
|
}
|
||||||
|
for (int i = _cur_size; i < size; i++) {
|
||||||
|
if constexpr (!std::is_trivially_constructible<T>::value)
|
||||||
|
new (_data + i) T();
|
||||||
|
else
|
||||||
|
memset((char *) (_data + i), 0, sizeof(T));
|
||||||
|
}
|
||||||
|
_cur_size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
T *data() { return _data; }
|
T *data() { return _data; }
|
||||||
const T *data() const { return _data; }
|
const T *data() const { return _data; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user