diff options
author | Alexis211 <alexis211@gmail.com> | 2009-08-31 00:25:21 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-08-31 00:25:21 +0200 |
commit | 68a8fb4e3b3e9087904b17ce6d81983950b9dca9 (patch) | |
tree | 57518642ab813fddfb3887a47f7a01d839d9bb70 /Source/Kernel/VTManager | |
parent | 9ad8e2fe0242da26dae7fca2b180640637c8c062 (diff) | |
download | Melon-68a8fb4e3b3e9087904b17ce6d81983950b9dca9.tar.gz Melon-68a8fb4e3b3e9087904b17ce6d81983950b9dca9.zip |
We now have complete support for keybord, IN UTF-8 !!
Diffstat (limited to 'Source/Kernel/VTManager')
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp | 69 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal.class.cpp | 6 | ||||
-rw-r--r-- | Source/Kernel/VTManager/VirtualTerminal.class.h | 11 |
3 files changed, 83 insertions, 3 deletions
diff --git a/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp b/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp new file mode 100644 index 0000000..a5b5ea6 --- /dev/null +++ b/Source/Kernel/VTManager/VirtualTerminal-kbd.class.cpp @@ -0,0 +1,69 @@ +#include "VirtualTerminal.class.h" +#include <TaskManager/Task.ns.h> + +using namespace Kbd; + +void VirtualTerminal::keyPress(keypress_t kp) { + m_kbdbuff.push(kp); + if (!m_kbdMutex.locked()) { + if (kp.haschar && !kp.hascmd) { + put(kp.character); + } else if (kp.hascmd && kp.command == KBDC_ENTER) { + put("\n"); + } else if (kp.hascmd && kp.command == KBDC_TAB) { + put("\t"); + } else if (kp.hascmd && kp.command == KBDC_BACKSPACE) { + put("\b"); + } + } +} + +keypress_t VirtualTerminal::getKeypress(bool show, bool block) { + m_kbdMutex.waitLock(); + + if (m_kbdbuff.empty() && !block) { + m_kbdMutex.unlock(); + return keypress_t(); + } + + while (m_kbdbuff.empty()) + Task::currentThread->sleep(10); + + keypress_t ret = m_kbdbuff[0]; + + for (u32int i = 1; i < m_kbdbuff.size(); i++) { + m_kbdbuff[i - 1] = m_kbdbuff[i]; + } + m_kbdbuff.pop(); + + if (show) { + if (ret.haschar && !ret.hascmd) { + put(ret.character); + } else if (ret.hascmd && ret.command == KBDC_ENTER) { + put("\n"); + } else if (ret.hascmd && ret.command == KBDC_TAB) { + put("\t"); + } else if (ret.hascmd && ret.command == KBDC_BACKSPACE) { + put("\b"); + } + } + + m_kbdMutex.unlock(); + return ret; +} + +String VirtualTerminal::readLine(bool show) { + String ret = ""; + keypress_t tmp = getKeypress(show); + while (!(tmp.hascmd and tmp.command == KBDC_ENTER)) { + if (tmp.hascmd and tmp.command == KBDC_BACKSPACE) { + if (!ret.empty()) ret = ret.substr(0, ret.size() - 1); + else put(" "); //Put a space so that cursor stays at same place + } else if (tmp.haschar) { + ret += tmp.character; + } + tmp = getKeypress(show); + } + if (!show) put("\n"); //Put a return if it hasn't been shown on getChar(); + return ret; +} diff --git a/Source/Kernel/VTManager/VirtualTerminal.class.cpp b/Source/Kernel/VTManager/VirtualTerminal.class.cpp index 41c3e8d..7864afd 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.class.cpp +++ b/Source/Kernel/VTManager/VirtualTerminal.class.cpp @@ -4,7 +4,7 @@ #define BUFCHR(l, c) m_buff[((l) * m_cols) + (c)] -VirtualTerminal::VirtualTerminal(u32int rows, u32int cols, u8int fgcolor, u8int bgcolor) { +VirtualTerminal::VirtualTerminal(u32int rows, u32int cols, u8int fgcolor, u8int bgcolor) : m_kbdMutex(false) { m_buff = new chr[rows * cols]; m_rows = rows; m_cols = cols; @@ -104,10 +104,10 @@ void VirtualTerminal::setCursorCol(u32int col) { // Display functionn void VirtualTerminal::put(wchar c, bool updatecsr) { - if (c.value == 0x08) { //Ascii backspace + if (c.value == '\b') { if (m_csrcol > 0) m_csrcol--; putChar(m_csrlin, m_csrcol, ' '); - } else if (c.value == 0x09) { //Ascii tab + } else if (c.value == '\t') { m_csrcol = (m_csrcol + 8) &~(8 - 1); } else if (c.value == '\r') { m_csrcol = 0; diff --git a/Source/Kernel/VTManager/VirtualTerminal.class.h b/Source/Kernel/VTManager/VirtualTerminal.class.h index 6d081ee..6a14080 100644 --- a/Source/Kernel/VTManager/VirtualTerminal.class.h +++ b/Source/Kernel/VTManager/VirtualTerminal.class.h @@ -3,6 +3,9 @@ #include <Core/common.wtf.h> #include <Library/String.class.h> +#include <TaskManager/Mutex.class.h> +#include <DeviceManager/Kbd.ns.h> +#include <Library/Vector.class.h> struct chr { u8int color; @@ -20,6 +23,9 @@ class VirtualTerminal { u32int m_csrlin, m_csrcol; + Mutex m_kbdMutex; + Vector<Kbd::keypress_t> m_kbdbuff; //Key press events buffer + public: VirtualTerminal(u32int rows, u32int cols, u8int fgcolor = 7, u8int bgcolor = 0); ~VirtualTerminal(); @@ -48,6 +54,11 @@ class VirtualTerminal { //inline VirtualTerminal& operator<<(wchar c) { put(c); return *this; } inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; } inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; } + + //Keyboard functions + void keyPress(Kbd::keypress_t kp); //Called by Kbd:: when a key is pressed + Kbd::keypress_t getKeypress(bool show = true, bool block = true); //Block : must we wait for a key to be pressed ? + String readLine(bool show = true); }; #endif |