Implement sequence to change the window name.

This commit is contained in:
DarwinNE 2020-01-14 22:46:05 +01:00
parent f4b2001325
commit d40eacf12e
5 changed files with 84 additions and 7 deletions

View File

@ -9,7 +9,8 @@ namespace retro
int main() int main()
{ {
retro::InitConsole(); 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()); retro::Console::currentInstance->write(out.data(), out.size());
std::string in; std::string in;

View File

@ -265,15 +265,80 @@ void Console::ScrollUp(short n)
dirtyRect.bottom = dirtyRect.bottom > 0 ? dirtyRect.bottom - 1 : 0; dirtyRect.bottom = dirtyRect.bottom > 0 ? dirtyRect.bottom - 1 : 0;
} }
void Console::ProcessEscSequence(char c) void Console::ProcessOSCseq(char c)
{ {
switch(sequenceStep) switch(sequenceStep)
{ {
case 0: case 1:
if(c=='[') if(c!='0') // The only recognized sequence is OSC 0;
++sequenceStep; {
else 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; 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; break;
case 1: case 1:
++sequenceStep; ++sequenceStep;
@ -305,6 +370,7 @@ void Console::ProcessEscSequence(char c)
break; break;
default: default:
sequenceStep=0; sequenceStep=0;
isProcessingEscSequence=false;
} }
} }

View File

@ -27,6 +27,9 @@
#include <vector> #include <vector>
#include <string> #include <string>
#define BEL 7
#define MAX_LEN 250
namespace retro namespace retro
{ {
class Attributes class Attributes
@ -86,6 +89,10 @@ namespace retro
void Idle(); void Idle();
bool IsEOF() const { return eof; } bool IsEOF() const { return eof; }
protected:
std::string windowName;
WindowPtr win;
private: private:
GrafPtr consolePort = nullptr; GrafPtr consolePort = nullptr;
Rect bounds; Rect bounds;
@ -94,6 +101,7 @@ namespace retro
std::vector<AttributedChar> chars, onscreen; std::vector<AttributedChar> chars, onscreen;
bool isProcessingEscSequence; bool isProcessingEscSequence;
int sequenceStep; int sequenceStep;
bool OSCseq;
short cellSizeX; short cellSizeX;
short cellSizeY; short cellSizeY;
@ -118,6 +126,7 @@ namespace retro
void DrawCells(short x1, short x2, short y, bool erase = true); void DrawCells(short x1, short x2, short y, bool erase = true);
void ScrollUp(short n = 1); void ScrollUp(short n = 1);
void ProcessEscSequence(char c); void ProcessEscSequence(char c);
void ProcessOSCseq(char c);
void SetAttributes(Attributes aa); void SetAttributes(Attributes aa);
void InvalidateCursor(); void InvalidateCursor();

View File

@ -36,6 +36,7 @@ ConsoleWindow::ConsoleWindow(Rect r, ConstStr255Param title)
{ {
GrafPtr port; GrafPtr port;
//Retro68 Improved Console //Retro68 Improved Console
windowName="Retro68 Console";
win = NewWindow(NULL, &r, "\pRetro68 Console", true, 0, (WindowPtr)-1, true, 0); win = NewWindow(NULL, &r, "\pRetro68 Console", true, 0, (WindowPtr)-1, true, 0);
#if !TARGET_API_MAC_CARBON #if !TARGET_API_MAC_CARBON

View File

@ -35,7 +35,7 @@ namespace retro
ConsoleWindow(Rect r, ConstStr255Param title); ConsoleWindow(Rect r, ConstStr255Param title);
~ConsoleWindow(); ~ConsoleWindow();
private: private:
WindowPtr win; //WindowPtr win;
virtual char WaitNextChar(); virtual char WaitNextChar();
}; };