|
|
@ -118,15 +118,17 @@ namespace DFHack
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Console::Console():std::ostream(0), std::ios(0)
|
|
|
|
Console::Console():std::ostream(0), std::ios(0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
d = new Private();
|
|
|
|
d = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Console::~Console()
|
|
|
|
Console::~Console()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if(d)
|
|
|
|
delete d;
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Console::init(void)
|
|
|
|
bool Console::init(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
d = new Private();
|
|
|
|
// make our own weird streams so our IO isn't redirected
|
|
|
|
// make our own weird streams so our IO isn't redirected
|
|
|
|
d->dfout_C = fopen("/dev/tty", "w");
|
|
|
|
d->dfout_C = fopen("/dev/tty", "w");
|
|
|
|
d->stream_o = new duthomhas::stdiobuf(d->dfout_C);
|
|
|
|
d->stream_o = new duthomhas::stdiobuf(d->dfout_C);
|
|
|
@ -139,7 +141,7 @@ bool Console::shutdown(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(d->rawmode)
|
|
|
|
if(d->rawmode)
|
|
|
|
disable_raw();
|
|
|
|
disable_raw();
|
|
|
|
*this << std::endl;
|
|
|
|
print("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Console::print( const char* format, ... )
|
|
|
|
int Console::print( const char* format, ... )
|
|
|
@ -174,16 +176,13 @@ void Console::clear()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*this << "\033c";
|
|
|
|
print("\033c\033[3J\033[H");
|
|
|
|
*this << "\033[3J\033[H";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Console::gotoxy(int x, int y)
|
|
|
|
void Console::gotoxy(int x, int y)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
print("\033[%d;%dH", y,x);
|
|
|
|
oss << "\033[" << y << ";" << x << "H";
|
|
|
|
|
|
|
|
*this << oss.str();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char * ANSI_CLS = "\033[2J";
|
|
|
|
const char * ANSI_CLS = "\033[2J";
|
|
|
@ -231,25 +230,20 @@ const char * getANSIColor(const int c)
|
|
|
|
|
|
|
|
|
|
|
|
void Console::color(int index)
|
|
|
|
void Console::color(int index)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*this << getANSIColor(index);
|
|
|
|
print(getANSIColor(index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Console::reset_color( void )
|
|
|
|
void Console::reset_color( void )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*this << RESETCOLOR;
|
|
|
|
print(RESETCOLOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Console::cursor(bool enable)
|
|
|
|
void Console::cursor(bool enable)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(enable)
|
|
|
|
if(enable)
|
|
|
|
{
|
|
|
|
print("\033[?25h");
|
|
|
|
*this <<"\033[?25h";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print("\033[?25l");
|
|
|
|
*this <<"\033[?25l";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Console::msleep (unsigned int msec)
|
|
|
|
void Console::msleep (unsigned int msec)
|
|
|
@ -339,8 +333,8 @@ int Console::prompt_loop(const std::string & prompt, std::string & buffer)
|
|
|
|
|
|
|
|
|
|
|
|
/* The latest history entry is always our current buffer, that
|
|
|
|
/* The latest history entry is always our current buffer, that
|
|
|
|
* initially is just an empty string. */
|
|
|
|
* initially is just an empty string. */
|
|
|
|
history_add("");
|
|
|
|
const std::string empty;
|
|
|
|
|
|
|
|
history_add(empty);
|
|
|
|
if (::write(fd,prompt.c_str(),plen) == -1) return -1;
|
|
|
|
if (::write(fd,prompt.c_str(),plen) == -1) return -1;
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -374,7 +368,8 @@ int Console::prompt_loop(const std::string & prompt, std::string & buffer)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
switch(c)
|
|
|
|
|
|
|
|
{
|
|
|
|
case 13: /* enter */
|
|
|
|
case 13: /* enter */
|
|
|
|
d->history.pop_front();
|
|
|
|
d->history.pop_front();
|
|
|
|
return buffer.size();
|
|
|
|
return buffer.size();
|
|
|
@ -516,7 +511,7 @@ int Console::prompt_loop(const std::string & prompt, std::string & buffer)
|
|
|
|
// push to front, remove from back if we are above maximum. ignore immediate duplicates
|
|
|
|
// push to front, remove from back if we are above maximum. ignore immediate duplicates
|
|
|
|
void Console::history_add(const std::string & command)
|
|
|
|
void Console::history_add(const std::string & command)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(d->history.front() == command)
|
|
|
|
if(!d->history.empty() && d->history.front() == command)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
d->history.push_front(command);
|
|
|
|
d->history.push_front(command);
|
|
|
|
if(d->history.size() > 100)
|
|
|
|
if(d->history.size() > 100)
|
|
|
@ -527,11 +522,10 @@ int Console::lineedit(const std::string & prompt, std::string & output)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
output.clear();
|
|
|
|
output.clear();
|
|
|
|
int count;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
|
|
if (d->isUnsupportedTerm() || !isatty(STDIN_FILENO))
|
|
|
|
if (d->isUnsupportedTerm() || !isatty(STDIN_FILENO))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
*this << prompt;
|
|
|
|
print(prompt.c_str());
|
|
|
|
flush();
|
|
|
|
fflush(d->dfout_C);
|
|
|
|
std::getline(std::cin, output);
|
|
|
|
std::getline(std::cin, output);
|
|
|
|
return output.size();
|
|
|
|
return output.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -540,7 +534,7 @@ int Console::lineedit(const std::string & prompt, std::string & output)
|
|
|
|
if (enable_raw() == -1) return 0;
|
|
|
|
if (enable_raw() == -1) return 0;
|
|
|
|
count = prompt_loop(prompt, output);
|
|
|
|
count = prompt_loop(prompt, output);
|
|
|
|
disable_raw();
|
|
|
|
disable_raw();
|
|
|
|
*this << std::endl;
|
|
|
|
print("\n");
|
|
|
|
return output.size();
|
|
|
|
return output.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|