From 6a8afbe5a0033c6e0e48ab7a928858925514891e Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 14 May 2012 18:30:02 +0300 Subject: [PATCH] SDL: Add command to enter command line with specified text --- include/platform/sdl/platform.hpp | 6 ++++++ manual.lyx | 8 ++++++++ manual.txt | 5 +++++ src/platform/sdl/commandline.cpp | 29 +++++++++++++++++++++++++++++ src/platform/sdl/graphicsfn.cpp | 20 +++++++++++++++++--- 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/include/platform/sdl/platform.hpp b/include/platform/sdl/platform.hpp index 93facaa0..c2647e06 100644 --- a/include/platform/sdl/platform.hpp +++ b/include/platform/sdl/platform.hpp @@ -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. * diff --git a/manual.lyx b/manual.lyx index 9e1a3319..16fbf418 100644 --- a/manual.lyx +++ b/manual.lyx @@ -1565,6 +1565,14 @@ scroll-down Scroll messages window forward one screenful. \end_layout +\begin_layout Subsubsection +prompt-command +\end_layout + +\begin_layout Standard +Enter command prompt, with prompt prepopulated with specified command. +\end_layout + \begin_layout Section Settings \end_layout diff --git a/manual.txt b/manual.txt index 3eda44f6..37c69742 100644 --- a/manual.txt +++ b/manual.txt @@ -765,6 +765,11 @@ Scroll messages window back one screenful. Scroll messages window forward one screenful. +6.12.7 prompt-command + +Enter command prompt, with prompt prepopulated with specified +command. + 7 Settings 7.1 Core settings diff --git a/src/platform/sdl/commandline.cpp b/src/platform/sdl/commandline.cpp index 81e46f70..4f254670 100644 --- a/src/platform/sdl/commandline.cpp +++ b/src/platform/sdl/commandline.cpp @@ -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) diff --git a/src/platform/sdl/graphicsfn.cpp b/src/platform/sdl/graphicsfn.cpp index 3320db8f..b1e8de6c 100644 --- a/src/platform/sdl/graphicsfn.cpp +++ b/src/platform/sdl/graphicsfn.cpp @@ -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 exec_command_prefix("prompt-command", + "Prompt for command", "Syntax: prompt-command \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);