فهرست منبع

Allow keyboard long-presses

Ray 3 سال پیش
والد
کامیت
2411f4aee1
3فایلهای تغییر یافته به همراه13 افزوده شده و 9 حذف شده
  1. 2 2
      README.md
  2. 7 5
      cligui_main.c
  3. 4 2
      text_input.c

+ 2 - 2
README.md

@@ -13,12 +13,12 @@ git clone https://github.com/ranchordo/flipperzero-cli-bridge ./applications_use
 # If everything went well, the built .fap file can be found in ./dist/f7-D/apps/apps/Tools/cli_gui.fap
 ```
 # Usage
-On the flipperzero, you should be able to find a new application (CLI-GUI Bridge) under Applications->Tools. Opening it will result in a text prompt - the prompt for the command line. Enter a suitable command (quickly pressing the back button will input a space) such as `subghz chat [freq in hz, e.g. 310000000]`, etc, then navigate to and press the SAVE key. You should then see the command window. Use Up and Down to scroll, and use Left or Center to get back to the text input prompt. A quick tap of the back key while viewing the console output sends a Ctrl-C to the console.
+On the flipperzero, you should be able to find a new application (CLI-GUI Bridge) under Applications->Tools. Opening it will result in a text prompt - the prompt for the command line. Enter a suitable command (quickly pressing the back button or holding `_` on the keyboard will input a space) such as `subghz chat [freq in hz, e.g. 310000000]`, etc, then navigate to and press the SAVE key. You should then see the command window. Use Up and Down to scroll, and use Left or Center to get back to the text input prompt. A quick tap of the back key while viewing the console output sends a Ctrl-C to the console, and a long press of the left or right keys during text input will navigate back to the console output without executing.
 ## Exiting the app
 Holding and then releasing the back key for at least a second or so (long press) will exit the app normally, meaning that the inner terminal will send Ctrl-C and close. Any sessions will be disconnected.  
   
   
-Holding and then releasing the OK key for at least a second or so (long press) will exit the app while keeping the terminal open. Terminal output will be cleared the next time you launch the app, but whatever command or session was running previously will be resumed. This is especially handy with subghz chat - exiting the app while keeping the terminal open will not disconnect you from the chat, and the flipper will still vibrate briefly whenever a new message comes in (even if the app is closed).  
+Holding and then releasing the OK key while focusing on the console output for at least a second or so (long press) will exit the app while keeping the terminal open. Terminal output will be cleared the next time you launch the app, but whatever command or session was running previously will be resumed. This is especially handy with subghz chat - exiting the app while keeping the terminal open will not disconnect you from the chat, and the flipper will still vibrate briefly whenever a new message comes in (even if the app is closed).  
   
   
 NOTE: USB functionality (qFlipper, normal USB CLI) may not work after running the app (especially after exiting without closing the terminal), simply restart your flipper and all USB functionality will return to normal.

+ 7 - 5
cligui_main.c

@@ -24,14 +24,14 @@ static void cligui_tick_event_cb(void* context) {
             furi_string_push_back(app->text_box_store, c);
         }
     }
-    if (available > 0) {
+    if(available > 0) {
         text_box_set_text(app->text_box, furi_string_get_cstr(app->text_box_store));
     }
     // Set input header stuff
     size_t len = furi_string_size(app->text_box_store);
     size_t idx = len - 2;
-    while (idx > 0) {
-        if (furi_string_get_char(app->text_box_store, idx) == '\n') {
+    while(idx > 0) {
+        if(furi_string_get_char(app->text_box_store, idx) == '\n') {
             idx++;
             break;
         }
@@ -50,8 +50,10 @@ static void input_callback_wrapper(InputEvent* event, void* context) {
         view_dispatcher_stop(app->view_dispatcher);
     }
     if(event->type == InputTypeLong && event->key == InputKeyOk) {
-        persistent_exit = true;
-        view_dispatcher_stop(app->view_dispatcher);
+        if(app->data->state == ViewConsoleOutput) {
+            persistent_exit = true;
+            view_dispatcher_stop(app->view_dispatcher);
+        }
     }
     if(app->data->state == ViewTextInput) {
         text_input_input_handler(app, event);

+ 4 - 2
text_input.c

@@ -19,8 +19,6 @@ void text_input_result_callback(void* ctx) {
 }
 
 void text_input_input_handler(CliguiApp* app, InputEvent* event) {
-    UNUSED(app);
-    UNUSED(event);
     if(event->type == InputTypeShort && event->key == InputKeyBack) {
         // view_dispatcher_switch_to_view(app->view_dispatcher, ViewConsoleOutput);
         // app->data->state = ViewConsoleOutput;
@@ -28,4 +26,8 @@ void text_input_input_handler(CliguiApp* app, InputEvent* event) {
         app->text_input_store[len] = ' ';
         app->text_input_store[len + 1] = 0;
     }
+    if(event->type == InputTypeLong && (event->key == InputKeyLeft || event->key == InputKeyRight)) {
+        view_dispatcher_switch_to_view(app->view_dispatcher, ViewConsoleOutput);
+        app->data->state = ViewConsoleOutput;
+    }
 }