summaryrefslogtreecommitdiff
path: root/Source/Kernel/VTManager
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/VTManager')
-rw-r--r--Source/Kernel/VTManager/FileVT.class.cpp62
-rw-r--r--Source/Kernel/VTManager/FileVT.class.h24
-rw-r--r--Source/Kernel/VTManager/PipeVT.class.cpp2
3 files changed, 87 insertions, 1 deletions
diff --git a/Source/Kernel/VTManager/FileVT.class.cpp b/Source/Kernel/VTManager/FileVT.class.cpp
new file mode 100644
index 0000000..0acc623
--- /dev/null
+++ b/Source/Kernel/VTManager/FileVT.class.cpp
@@ -0,0 +1,62 @@
+#include "FileVT.class.h"
+
+FileVT::FileVT(String filename, u8int mode, FSNode *start, u8int encoding) :
+ m_file(filename, mode, start, encoding), m_buffer() {
+ if (mode != FM_READ) {
+ m_isWriting = true;
+ m_bufferPos = 0;
+ } else {
+ m_isWriting = false;
+ m_buffer = m_file.readLine();
+ }
+}
+
+void FileVT::setCursorCol(u32int col) {
+ if (!m_isWriting) return;
+ while (m_buffer.size() < col) {
+ put(" ");
+ }
+}
+
+void FileVT::put(WChar c, bool updatecsr) {
+ if (!m_isWriting) return;
+ if (c.value == '\n') {
+ m_file.write(m_buffer, true);
+ m_buffer.clear();
+ } else if (c.value == '\t') {
+ u32int nc = (m_buffer.size() + 8) &~(8 - 1);
+ while (m_buffer.size() < nc) put(" ");
+ } else {
+ m_buffer += c;
+ }
+}
+
+Kbd::keypress_t FileVT::getKeypress(bool show, bool block) {
+ Kbd::keypress_t ret;
+ if (m_isWriting) return ret;
+
+ if (m_bufferPos == m_buffer.size()) {
+ ret.hascmd = true;
+ ret.command = KBDC_ENTER;
+ if (m_file.eof()) {
+ m_buffer = ".";
+ } else {
+ m_buffer = m_file.readLine();
+ }
+ m_bufferPos = 0;
+ } else {
+ WChar c = m_buffer[m_bufferPos];
+ m_bufferPos++;
+ if (c.value == '\t') {
+ ret.hascmd = true;
+ ret.command = KBDC_TAB;
+ } else if (c.value == '\b') {
+ ret.hascmd = true;
+ ret.command = KBDC_BACKSPACE;
+ } else {
+ ret.haschar = true;
+ ret.character = c;
+ }
+ }
+ return ret;
+}
diff --git a/Source/Kernel/VTManager/FileVT.class.h b/Source/Kernel/VTManager/FileVT.class.h
new file mode 100644
index 0000000..61f4d6f
--- /dev/null
+++ b/Source/Kernel/VTManager/FileVT.class.h
@@ -0,0 +1,24 @@
+#ifndef DEF_FILEVT_CLASS_H
+#define DEF_FILEVT_CLASS_H
+
+#include <VFS/TextFile.class.h>
+#include <VTManager/VirtualTerminal.proto.h>
+
+class FileVT : public VirtualTerminal {
+ protected:
+ TextFile m_file;
+ bool m_isWriting; //True = write only, false = read only
+ String m_buffer;
+ u32int m_bufferPos;
+
+ public:
+ FileVT(String filename, u8int mode = FM_READ, FSNode* start = 0, u8int encoding = UE_UTF8);
+
+ bool isBoxed() { return false; }
+ void setCursorCol(u32int col);
+
+ void put(WChar c, bool updatecsr = true);
+ Kbd::keypress_t getKeypress(bool show = true, bool block = true);
+};
+
+#endif
diff --git a/Source/Kernel/VTManager/PipeVT.class.cpp b/Source/Kernel/VTManager/PipeVT.class.cpp
index bcaa531..10c7e7b 100644
--- a/Source/Kernel/VTManager/PipeVT.class.cpp
+++ b/Source/Kernel/VTManager/PipeVT.class.cpp
@@ -6,7 +6,7 @@ PipeVT::PipeVT() {
void PipeVT::setCursorCol(u32int col) {
while (col > m_col) {
- put(' ');
+ put(" ");
}
}