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()
{
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;

View File

@ -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;
}
}

View File

@ -27,6 +27,9 @@
#include <vector>
#include <string>
#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<AttributedChar> 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();

View File

@ -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

View File

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