mirror of
https://github.com/autc04/Retro68.git
synced 2025-02-18 18:31:07 +00:00
readline!
This commit is contained in:
parent
04fcc13550
commit
f370137c88
@ -1,5 +1,9 @@
|
|||||||
set(CMAKE_CXX_FLAGS "-std=c++11")
|
set(CMAKE_CXX_FLAGS "-std=c++11")
|
||||||
add_executable(Test test.cc Console.cc)
|
add_executable(Test
|
||||||
|
test.cc
|
||||||
|
Console.cc
|
||||||
|
Console.h
|
||||||
|
MacUtils.h)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT Test.dsk
|
OUTPUT Test.dsk
|
||||||
COMMAND ${MAKE_APPL} -c Test
|
COMMAND ${MAKE_APPL} -c Test
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
|
#include "MacUtils.h"
|
||||||
|
#include "Events.h"
|
||||||
|
|
||||||
Console *Console::currentInstance = NULL;
|
Console *Console::currentInstance = NULL;
|
||||||
|
|
||||||
Console::Console(GrafPtr port)
|
Console::Console(GrafPtr port)
|
||||||
|
: consolePort(port)
|
||||||
{
|
{
|
||||||
|
PortSetter setport(consolePort);
|
||||||
|
|
||||||
Rect r = {2,2,340,510};
|
Rect r = {2,2,340,510};
|
||||||
bounds = r;
|
bounds = r;
|
||||||
SetPort(port);
|
|
||||||
consolePort = port;
|
|
||||||
TextFont(9);
|
TextFont(9);
|
||||||
TextSize(9);
|
TextSize(9);
|
||||||
MoveTo(10,10);
|
|
||||||
|
|
||||||
cellSizeY = 10;
|
cellSizeY = 10;
|
||||||
cellSizeX = CharWidth('M');
|
cellSizeX = CharWidth('M');
|
||||||
@ -39,6 +41,7 @@ void Console::DrawCell(short x, short y)
|
|||||||
|
|
||||||
void Console::Draw()
|
void Console::Draw()
|
||||||
{
|
{
|
||||||
|
PortSetter setport(consolePort);
|
||||||
//PashortRect(&r);
|
//PashortRect(&r);
|
||||||
|
|
||||||
for(short row = 0; row < rows; ++row)
|
for(short row = 0; row < rows; ++row)
|
||||||
@ -63,6 +66,8 @@ void Console::ScrollUp(short n)
|
|||||||
|
|
||||||
void Console::putch(char c)
|
void Console::putch(char c)
|
||||||
{
|
{
|
||||||
|
PortSetter setport(consolePort);
|
||||||
|
|
||||||
//Debugger();
|
//Debugger();
|
||||||
switch(c)
|
switch(c)
|
||||||
{
|
{
|
||||||
@ -84,3 +89,44 @@ void Console::putch(char c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Console::ReadLine()
|
||||||
|
{
|
||||||
|
std::string buffer;
|
||||||
|
EventRecord event;
|
||||||
|
char c;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
while(!GetOSEvent(everyEvent, &event))
|
||||||
|
;
|
||||||
|
} while(event.what != keyDown && event.what != autoKey);
|
||||||
|
|
||||||
|
c = event.message & charCodeMask;
|
||||||
|
|
||||||
|
if(c == '\r')
|
||||||
|
c = '\n';
|
||||||
|
|
||||||
|
if(c == '\b')
|
||||||
|
{
|
||||||
|
cursorX--;
|
||||||
|
putch(' ');
|
||||||
|
cursorX--;
|
||||||
|
|
||||||
|
buffer.substr(0,buffer.size()-1);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
//c = 'X';
|
||||||
|
}
|
||||||
|
if(c == 127)
|
||||||
|
{
|
||||||
|
c = 'Y';
|
||||||
|
}
|
||||||
|
|
||||||
|
putch(c);
|
||||||
|
buffer += std::string(1,c);
|
||||||
|
} while(c != '\n');
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <Quickdraw.h>
|
#include <Quickdraw.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class Console
|
class Console
|
||||||
{
|
{
|
||||||
@ -7,6 +8,7 @@ public:
|
|||||||
Console(GrafPtr port);
|
Console(GrafPtr port);
|
||||||
void Draw();
|
void Draw();
|
||||||
void putch(char c);
|
void putch(char c);
|
||||||
|
std::string ReadLine();
|
||||||
|
|
||||||
static Console *currentInstance;
|
static Console *currentInstance;
|
||||||
private:
|
private:
|
||||||
|
19
App2/MacUtils.h
Normal file
19
App2/MacUtils.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <Quickdraw.h>
|
||||||
|
|
||||||
|
class PortSetter
|
||||||
|
{
|
||||||
|
GrafPtr save;
|
||||||
|
public:
|
||||||
|
PortSetter(GrafPtr port)
|
||||||
|
{
|
||||||
|
::GetPort(&save);
|
||||||
|
::SetPort(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
~PortSetter()
|
||||||
|
{
|
||||||
|
::SetPort(save);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -127,6 +127,9 @@ int main(int argc, char** argv)
|
|||||||
std::cout << "Hello, world: " << i << std::endl;
|
std::cout << "Hello, world: " << i << std::endl;
|
||||||
std::cout << std::flush;
|
std::cout << std::flush;
|
||||||
|
|
||||||
|
std::cout << "Say something: " << std::flush;
|
||||||
|
console.ReadLine();
|
||||||
|
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
std::cout << "Exception speed test: " << std::flush;
|
std::cout << "Exception speed test: " << std::flush;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user