|
|
@ -423,13 +423,13 @@ namespace DFHack
|
|
|
|
int count;
|
|
|
|
int count;
|
|
|
|
if (enable_raw() == -1) return 0;
|
|
|
|
if (enable_raw() == -1) return 0;
|
|
|
|
if(state == con_lineedit)
|
|
|
|
if(state == con_lineedit)
|
|
|
|
return -1;
|
|
|
|
return Console::FAILURE;
|
|
|
|
state = con_lineedit;
|
|
|
|
state = con_lineedit;
|
|
|
|
count = prompt_loop(lock,ch);
|
|
|
|
count = prompt_loop(lock,ch);
|
|
|
|
state = con_unclaimed;
|
|
|
|
state = con_unclaimed;
|
|
|
|
disable_raw();
|
|
|
|
disable_raw();
|
|
|
|
print("\n");
|
|
|
|
print("\n");
|
|
|
|
if(count != -1)
|
|
|
|
if(count > Console::FAILURE)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
output = toLocaleMB(raw_buffer);
|
|
|
|
output = toLocaleMB(raw_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -441,9 +441,9 @@ namespace DFHack
|
|
|
|
struct termios raw;
|
|
|
|
struct termios raw;
|
|
|
|
|
|
|
|
|
|
|
|
if (!supported_terminal)
|
|
|
|
if (!supported_terminal)
|
|
|
|
return -1;
|
|
|
|
return Console::FAILURE;
|
|
|
|
if (tcgetattr(STDIN_FILENO,&orig_termios) == -1)
|
|
|
|
if (tcgetattr(STDIN_FILENO,&orig_termios) == -1)
|
|
|
|
return -1;
|
|
|
|
return Console::FAILURE;
|
|
|
|
|
|
|
|
|
|
|
|
raw = orig_termios; //modify the original mode
|
|
|
|
raw = orig_termios; //modify the original mode
|
|
|
|
// input modes: no break, no CR to NL, no parity check, no strip char,
|
|
|
|
// input modes: no break, no CR to NL, no parity check, no strip char,
|
|
|
@ -465,7 +465,7 @@ namespace DFHack
|
|
|
|
raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0;// 1 byte, no timer
|
|
|
|
raw.c_cc[VMIN] = 1; raw.c_cc[VTIME] = 0;// 1 byte, no timer
|
|
|
|
// put terminal in raw mode
|
|
|
|
// put terminal in raw mode
|
|
|
|
if (tcsetattr(STDIN_FILENO, TCSADRAIN, &raw) < 0)
|
|
|
|
if (tcsetattr(STDIN_FILENO, TCSADRAIN, &raw) < 0)
|
|
|
|
return -1;
|
|
|
|
return Console::FAILURE;
|
|
|
|
rawmode = 1;
|
|
|
|
rawmode = 1;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -518,7 +518,8 @@ namespace DFHack
|
|
|
|
* initially is just an empty string. */
|
|
|
|
* initially is just an empty string. */
|
|
|
|
const std::string empty;
|
|
|
|
const std::string empty;
|
|
|
|
history.add(empty);
|
|
|
|
history.add(empty);
|
|
|
|
if (::write(fd,prompt.c_str(),prompt.size()) == -1) return -1;
|
|
|
|
if (::write(fd,prompt.c_str(),prompt.size()) == -1)
|
|
|
|
|
|
|
|
return Console::FAILURE;
|
|
|
|
while(1)
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
unsigned char c;
|
|
|
|
unsigned char c;
|
|
|
@ -528,7 +529,7 @@ namespace DFHack
|
|
|
|
if(!read_char(c))
|
|
|
|
if(!read_char(c))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
return -2;
|
|
|
|
return Console::SHUTDOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
/* Only autocomplete when the callback is set. It returns < 0 when
|
|
|
|
/* Only autocomplete when the callback is set. It returns < 0 when
|
|
|
@ -561,8 +562,7 @@ namespace DFHack
|
|
|
|
history.remove();
|
|
|
|
history.remove();
|
|
|
|
return raw_buffer.size();
|
|
|
|
return raw_buffer.size();
|
|
|
|
case 3: // ctrl-c
|
|
|
|
case 3: // ctrl-c
|
|
|
|
errno = EAGAIN;
|
|
|
|
return Console::RETRY;
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
case 127: // backspace
|
|
|
|
case 127: // backspace
|
|
|
|
case 8: // ctrl-h
|
|
|
|
case 8: // ctrl-h
|
|
|
|
if (raw_cursor > 0 && raw_buffer.size() > 0)
|
|
|
|
if (raw_cursor > 0 && raw_buffer.size() > 0)
|
|
|
@ -577,7 +577,7 @@ namespace DFHack
|
|
|
|
if (!read_char(seq[0]))
|
|
|
|
if (!read_char(seq[0]))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
return -2;
|
|
|
|
return Console::SHUTDOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
if (seq[0] == 'b')
|
|
|
|
if (seq[0] == 'b')
|
|
|
@ -593,7 +593,7 @@ namespace DFHack
|
|
|
|
if (!read_char(seq[1]))
|
|
|
|
if (!read_char(seq[1]))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
return -2;
|
|
|
|
return Console::SHUTDOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seq[1] == 'D')
|
|
|
|
if (seq[1] == 'D')
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -658,7 +658,7 @@ namespace DFHack
|
|
|
|
if(!read_char(seq2))
|
|
|
|
if(!read_char(seq2))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
return -2;
|
|
|
|
return Console::SHUTDOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
if (seq[1] == '3' && seq2 == '~' )
|
|
|
|
if (seq[1] == '3' && seq2 == '~' )
|
|
|
@ -674,7 +674,7 @@ namespace DFHack
|
|
|
|
if (!read_char(seq3[0]) || !read_char(seq3[1]))
|
|
|
|
if (!read_char(seq3[0]) || !read_char(seq3[1]))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock->lock();
|
|
|
|
lock->lock();
|
|
|
|
return -2;
|
|
|
|
return Console::SHUTDOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (seq2 == ';')
|
|
|
|
if (seq2 == ';')
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -747,9 +747,9 @@ namespace DFHack
|
|
|
|
// character starting from the first bye already red
|
|
|
|
// character starting from the first bye already red
|
|
|
|
while ((sz = mbrtoc32(&c32,&mb[count-1],1, &state)) < 0) {
|
|
|
|
while ((sz = mbrtoc32(&c32,&mb[count-1],1, &state)) < 0) {
|
|
|
|
if (sz == -1 || sz == -3)
|
|
|
|
if (sz == -1 || sz == -3)
|
|
|
|
return -1; /* mbrtoc32 error (not valid utf-32 character */
|
|
|
|
return Console::FAILURE; /* mbrtoc32 error (not valid utf-32 character */
|
|
|
|
if(!read_char(c))
|
|
|
|
if(!read_char(c))
|
|
|
|
return -2;
|
|
|
|
return Console::SHUTDOWN;
|
|
|
|
mb[count++] = c;
|
|
|
|
mb[count++] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (raw_buffer.size() == size_t(raw_cursor))
|
|
|
|
if (raw_buffer.size() == size_t(raw_cursor))
|
|
|
@ -760,7 +760,8 @@ namespace DFHack
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* Avoid a full update of the line in the
|
|
|
|
/* Avoid a full update of the line in the
|
|
|
|
* trivial case. */
|
|
|
|
* trivial case. */
|
|
|
|
if (::write(fd,mb,count) == -1) return -1;
|
|
|
|
if (::write(fd,mb,count) == -1)
|
|
|
|
|
|
|
|
return Console::FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -888,7 +889,7 @@ void Console::add_text(color_value color, const std::string &text)
|
|
|
|
int Console::get_columns(void)
|
|
|
|
int Console::get_columns(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock_guard <recursive_mutex> g(*wlock);
|
|
|
|
lock_guard <recursive_mutex> g(*wlock);
|
|
|
|
int ret = -1;
|
|
|
|
int ret = Console::FAILURE;
|
|
|
|
if(inited)
|
|
|
|
if(inited)
|
|
|
|
ret = d->get_columns();
|
|
|
|
ret = d->get_columns();
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
@ -897,7 +898,7 @@ int Console::get_columns(void)
|
|
|
|
int Console::get_rows(void)
|
|
|
|
int Console::get_rows(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock_guard <recursive_mutex> g(*wlock);
|
|
|
|
lock_guard <recursive_mutex> g(*wlock);
|
|
|
|
int ret = -1;
|
|
|
|
int ret = Console::FAILURE;
|
|
|
|
if(inited)
|
|
|
|
if(inited)
|
|
|
|
ret = d->get_rows();
|
|
|
|
ret = d->get_rows();
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
@ -927,10 +928,10 @@ void Console::cursor(bool enable)
|
|
|
|
int Console::lineedit(const std::string & prompt, std::string & output, CommandHistory & ch)
|
|
|
|
int Console::lineedit(const std::string & prompt, std::string & output, CommandHistory & ch)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lock_guard <recursive_mutex> g(*wlock);
|
|
|
|
lock_guard <recursive_mutex> g(*wlock);
|
|
|
|
int ret = -2;
|
|
|
|
int ret = Console::SHUTDOWN;
|
|
|
|
if(inited) {
|
|
|
|
if(inited) {
|
|
|
|
ret = d->lineedit(prompt,output,wlock,ch);
|
|
|
|
ret = d->lineedit(prompt,output,wlock,ch);
|
|
|
|
if (ret == -2) {
|
|
|
|
if (ret == Console::SHUTDOWN) {
|
|
|
|
// kill the thing
|
|
|
|
// kill the thing
|
|
|
|
if(d->rawmode)
|
|
|
|
if(d->rawmode)
|
|
|
|
d->disable_raw();
|
|
|
|
d->disable_raw();
|
|
|
|