SDL: Add command to enter command line with specified text
This commit is contained in:
parent
1db083990b
commit
6a8afbe5a0
5 changed files with 65 additions and 3 deletions
|
@ -193,6 +193,12 @@ struct commandline_model
|
|||
* Enable command line.
|
||||
*/
|
||||
void enable() throw();
|
||||
/**
|
||||
* Enable command line with specific command.
|
||||
*
|
||||
* Parameter cmd: The command template.
|
||||
*/
|
||||
void enable(const std::string& cmd) throw();
|
||||
/**
|
||||
* Repaint to SDL surface.
|
||||
*
|
||||
|
|
|
@ -1565,6 +1565,14 @@ scroll-down
|
|||
Scroll messages window forward one screenful.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
prompt-command <command>
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Enter command prompt, with prompt prepopulated with specified command.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Section
|
||||
Settings
|
||||
\end_layout
|
||||
|
|
|
@ -765,6 +765,11 @@ Scroll messages window back one screenful.
|
|||
|
||||
Scroll messages window forward one screenful.
|
||||
|
||||
6.12.7 prompt-command <command>
|
||||
|
||||
Enter command prompt, with prompt prepopulated with specified
|
||||
command.
|
||||
|
||||
7 Settings
|
||||
|
||||
7.1 Core settings
|
||||
|
|
|
@ -145,6 +145,35 @@ bool commandline_model::overwriting() throw()
|
|||
return overwrite_mode;
|
||||
}
|
||||
|
||||
void commandline_model::enable(const std::string& cmd) throw()
|
||||
{
|
||||
enable();
|
||||
unsigned left = 0;
|
||||
unsigned tmp = 0;
|
||||
for(size_t itr = 0; itr < cmd.length(); itr++) {
|
||||
unsigned char ch = cmd[itr];
|
||||
if(ch < 128)
|
||||
codepoints.push_back(ch);
|
||||
else if(left) {
|
||||
left--;
|
||||
tmp = tmp * 64 + (ch & 0x3F);
|
||||
if(!left)
|
||||
codepoints.push_back(tmp);
|
||||
} else if(ch < 192) {
|
||||
} else if(ch < 224) {
|
||||
left = 1;
|
||||
tmp = ch & 0x1F;
|
||||
} else if(ch < 240) {
|
||||
left = 2;
|
||||
tmp = ch & 0x0F;
|
||||
} else if(ch < 248) {
|
||||
left = 3;
|
||||
tmp = ch & 0x07;
|
||||
}
|
||||
}
|
||||
cursor_pos = codepoints.size();
|
||||
}
|
||||
|
||||
void commandline_model::enable() throw()
|
||||
{
|
||||
if(enabled_flag)
|
||||
|
|
|
@ -68,6 +68,9 @@ namespace
|
|||
SDL_TimerID timer_id;
|
||||
//Timer IRQ counter. Used by identify key stuff.
|
||||
volatile unsigned timer_irq_counter;
|
||||
//Delayed command to start.
|
||||
bool delayed_cmd_active;
|
||||
std::string delayed_cmd;
|
||||
|
||||
void sigalrm_handler(int s)
|
||||
{
|
||||
|
@ -269,6 +272,13 @@ namespace
|
|||
platform::queue(emu_handle_identify, NULL, false);
|
||||
}
|
||||
|
||||
function_ptr_command<const std::string&> exec_command_prefix("prompt-command",
|
||||
"Prompt for command", "Syntax: prompt-command <prefix>\nPrompts command with specified text.\n",
|
||||
[](const std::string& line) throw(std::bad_alloc, std::runtime_error) {
|
||||
delayed_cmd = line;
|
||||
delayed_cmd_active = true;
|
||||
});
|
||||
|
||||
//Handle QUIT in normal state.
|
||||
void ui_handle_quit_signal()
|
||||
{
|
||||
|
@ -306,7 +316,7 @@ void ui_loop()
|
|||
{
|
||||
ui_mutex->lock();
|
||||
int r = SDL_PollEvent(&e);
|
||||
if(!repaint_in_flight && !timer_triggered && !r) {
|
||||
if(!repaint_in_flight && !timer_triggered && !delayed_cmd_active && !r) {
|
||||
ui_mutex->unlock();
|
||||
usleep(2000);
|
||||
continue;
|
||||
|
@ -385,9 +395,13 @@ void ui_loop()
|
|||
switch(special_mode) {
|
||||
case SPECIALMODE_NORMAL:
|
||||
//Enable command line if needed.
|
||||
if(iskbd && kbdkey == SDLK_ESCAPE) {
|
||||
if((iskbd && kbdkey == SDLK_ESCAPE) || delayed_cmd_active) {
|
||||
if(!cmdline.enabled() && !polarity) {
|
||||
cmdline.enable();
|
||||
if(delayed_cmd_active)
|
||||
cmdline.enable(delayed_cmd);
|
||||
else
|
||||
cmdline.enable();
|
||||
delayed_cmd_active = false;
|
||||
commandline_updated = true;
|
||||
special_mode = SPECIALMODE_COMMAND;
|
||||
platform::set_modal_pause(true);
|
||||
|
|
Loading…
Add table
Reference in a new issue