From 5d7ad3933bc2de69c2b7d09791adf305de019d8a Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 20 Sep 2009 16:09:38 +0200 Subject: Implemented FileVT. --- Source/Kernel/Core/kmain.wtf.cpp | 2 +- Source/Kernel/Makefile | 1 + Source/Kernel/Melon.ke | Bin 158594 -> 159305 bytes Source/Kernel/Ressources/Texts/Info.txt | 2 +- Source/Kernel/VTManager/FileVT.class.cpp | 62 +++++++++++++++++++++++++++++++ Source/Kernel/VTManager/FileVT.class.h | 24 ++++++++++++ Source/Kernel/VTManager/PipeVT.class.cpp | 2 +- 7 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Source/Kernel/VTManager/FileVT.class.cpp create mode 100644 Source/Kernel/VTManager/FileVT.class.h (limited to 'Source/Kernel') diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp index 465b2f1..6ccc71e 100644 --- a/Source/Kernel/Core/kmain.wtf.cpp +++ b/Source/Kernel/Core/kmain.wtf.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile index e8e308d..c870a26 100644 --- a/Source/Kernel/Makefile +++ b/Source/Kernel/Makefile @@ -35,6 +35,7 @@ Objects = Core/loader.wtf.o \ VTManager/SimpleVT.class.o \ VTManager/ScrollableVT.class.o \ VTManager/PipeVT.class.o \ + VTManager/FileVT.class.o \ VTManager/VirtualTerminal-kbd.proto.o \ VTManager/VT.ns.o \ Library/Bitset.class.o \ diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke index 1c7b040..703a9c3 100755 Binary files a/Source/Kernel/Melon.ke and b/Source/Kernel/Melon.ke differ diff --git a/Source/Kernel/Ressources/Texts/Info.txt b/Source/Kernel/Ressources/Texts/Info.txt index 1a57fc9..56016a2 100644 --- a/Source/Kernel/Ressources/Texts/Info.txt +++ b/Source/Kernel/Ressources/Texts/Info.txt @@ -2,4 +2,4 @@ These files were just added here for fun. Oh, you wanted to know what the wf command meant ? Simple : it means Write File. Type 'wf filename' and then enter the -file's contents, ending with . +file's contents, ending with . 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 +#include + +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(" "); } } -- cgit v1.2.3