diff --git a/Console/ConsoleTest.cc b/Console/ConsoleTest.cc index b32da0ea83..82faadf9bd 100644 --- a/Console/ConsoleTest.cc +++ b/Console/ConsoleTest.cc @@ -9,7 +9,8 @@ namespace retro int main() { retro::InitConsole(); - std::string out = "Hello, \033[1mexternal world of \033[0m\033[3mtrue beauty and \033[4mgreatness\033[0m.\nEnter \"exit\" to quit.\n"; + std::string out = "\033]0;Hello world win\007Hello, \033[1mexternal world of \033[0m\033[3mtrue beauty and \033[4mgreatness\033[0m.\nEnter \"exit\" to quit.\n"; + //std::string out = "Hello, \033[1mexternal world of \033[0m\033[3mtrue beauty and \033[4mgreatness\033[0m.\nEnter \"exit\" to quit.\n"; retro::Console::currentInstance->write(out.data(), out.size()); std::string in; diff --git a/Console/retro/Console.cc b/Console/retro/Console.cc index 6024a8bcc0..db7ca63be8 100644 --- a/Console/retro/Console.cc +++ b/Console/retro/Console.cc @@ -265,15 +265,80 @@ void Console::ScrollUp(short n) dirtyRect.bottom = dirtyRect.bottom > 0 ? dirtyRect.bottom - 1 : 0; } -void Console::ProcessEscSequence(char c) +void Console::ProcessOSCseq(char c) { switch(sequenceStep) { - case 0: - if(c=='[') - ++sequenceStep; - else + case 1: + if(c!='0') // The only recognized sequence is OSC 0; + { + OSCseq=false; + sequenceStep=0; + return; + } + ++sequenceStep; + break; + case 2: + if(c!=';') // The only recognized sequence is OSC 0; + { + OSCseq=false; + sequenceStep=0; + return; + } + ++sequenceStep; + windowName=" "; + break; + default: + if(c==BEL) // The BEL character ends the sequence. + { + windowName[0]=windowName.length(); + SetWTitle(win, (ConstStringPtr)windowName.c_str()); + OSCseq=false; isProcessingEscSequence=false; + sequenceStep=0; + } + else + { + windowName+=c; + ++sequenceStep; + } + } +} + +void Console::ProcessEscSequence(char c) +{ + if(sequenceStep>0 && OSCseq) + { + ProcessOSCseq(c); + //sequenceStep=0; + //isProcessingEscSequence=false; + return; + } + if(sequenceStep>MAX_LEN) + { + // Sequence is too long! + sequenceStep=0; + isProcessingEscSequence=false; + return; + } + + switch(sequenceStep) + { + case 0: + if(c=='[') // Control Sequence Introducer + { + OSCseq=false; + ++sequenceStep; + } + else if(c==']') // Operating System Command + { + OSCseq=true; + ++sequenceStep; + } + else + { + isProcessingEscSequence=false; + } break; case 1: ++sequenceStep; @@ -305,6 +370,7 @@ void Console::ProcessEscSequence(char c) break; default: sequenceStep=0; + isProcessingEscSequence=false; } } diff --git a/Console/retro/Console.h b/Console/retro/Console.h index cc5df88403..6c08d6abd5 100644 --- a/Console/retro/Console.h +++ b/Console/retro/Console.h @@ -27,6 +27,9 @@ #include #include +#define BEL 7 +#define MAX_LEN 250 + namespace retro { class Attributes @@ -86,6 +89,10 @@ namespace retro void Idle(); bool IsEOF() const { return eof; } + protected: + std::string windowName; + WindowPtr win; + private: GrafPtr consolePort = nullptr; Rect bounds; @@ -94,6 +101,7 @@ namespace retro std::vector chars, onscreen; bool isProcessingEscSequence; int sequenceStep; + bool OSCseq; short cellSizeX; short cellSizeY; @@ -118,6 +126,7 @@ namespace retro void DrawCells(short x1, short x2, short y, bool erase = true); void ScrollUp(short n = 1); void ProcessEscSequence(char c); + void ProcessOSCseq(char c); void SetAttributes(Attributes aa); void InvalidateCursor(); diff --git a/Console/retro/ConsoleWindow.cc b/Console/retro/ConsoleWindow.cc index 5740ede97f..db71f55258 100644 --- a/Console/retro/ConsoleWindow.cc +++ b/Console/retro/ConsoleWindow.cc @@ -36,6 +36,7 @@ ConsoleWindow::ConsoleWindow(Rect r, ConstStr255Param title) { GrafPtr port; //Retro68 Improved Console + windowName="Retro68 Console"; win = NewWindow(NULL, &r, "\pRetro68 Console", true, 0, (WindowPtr)-1, true, 0); #if !TARGET_API_MAC_CARBON diff --git a/Console/retro/ConsoleWindow.h b/Console/retro/ConsoleWindow.h index e3d71c33bd..1b787dc769 100644 --- a/Console/retro/ConsoleWindow.h +++ b/Console/retro/ConsoleWindow.h @@ -35,7 +35,7 @@ namespace retro ConsoleWindow(Rect r, ConstStr255Param title); ~ConsoleWindow(); private: - WindowPtr win; + //WindowPtr win; virtual char WaitNextChar(); };