diff options
author | Alexis211 <alexis211@gmail.com> | 2009-09-20 16:09:38 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-09-20 16:09:38 +0200 |
commit | 5d7ad3933bc2de69c2b7d09791adf305de019d8a (patch) | |
tree | f0b68e5e02ef99efdc8ffbed350c3f5cee1c7d97 /Source/Kernel | |
parent | a1ffeb45b310b2e0dd9ae6a40b13ccc447eb0ef6 (diff) | |
download | Melon-5d7ad3933bc2de69c2b7d09791adf305de019d8a.tar.gz Melon-5d7ad3933bc2de69c2b7d09791adf305de019d8a.zip |
Implemented FileVT.
Diffstat (limited to 'Source/Kernel')
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 2 | ||||
-rw-r--r-- | Source/Kernel/Makefile | 1 | ||||
-rwxr-xr-x | Source/Kernel/Melon.ke | bin | 158594 -> 159305 bytes | |||
-rw-r--r-- | Source/Kernel/Ressources/Texts/Info.txt | 2 | ||||
-rw-r--r-- | Source/Kernel/VTManager/FileVT.class.cpp | 62 | ||||
-rw-r--r-- | Source/Kernel/VTManager/FileVT.class.h | 24 | ||||
-rw-r--r-- | Source/Kernel/VTManager/PipeVT.class.cpp | 2 |
7 files changed, 90 insertions, 3 deletions
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 <DeviceManager/Kbd.ns.h> #include <DeviceManager/Time.ns.h> #include <VTManager/ScrollableVT.class.h> -#include <VTManager/PipeVT.class.h> +#include <VTManager/FileVT.class.h> #include <MemoryManager/PhysMem.ns.h> #include <MemoryManager/PageAlloc.ns.h> #include <MemoryManager/GDT.ns.h> 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 Binary files differindex 1c7b040..703a9c3 100755 --- a/Source/Kernel/Melon.ke +++ b/Source/Kernel/Melon.ke 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 <CRLF>.<CRLF> +file's contents, ending with <CR>.<CR> 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(" "); } } |