From 0f1717f829e95d7f3e1ac5b213d3f73f09b0da62 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 8 Feb 2018 17:56:31 +0100 Subject: [PATCH] [Script] Reset highlighting when reload view Issue: #767 --- Examples/test_script_mode.sh | 37 +++++++++++++++++++++++------------- source/dialogs/script.c | 17 ++++++++++++++++- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Examples/test_script_mode.sh b/Examples/test_script_mode.sh index 61e29141..a58ef83e 100755 --- a/Examples/test_script_mode.sh +++ b/Examples/test_script_mode.sh @@ -1,17 +1,28 @@ #!/usr/bin/env bash -echo -en "\x00prompt\x1ftesting\n" -echo -en "\0urgent\x1f0,2\n" -echo -en "\0active\x1f1\n" -echo -en "\0markup-rows\x1ftrue\n" -echo -en "\0message\x1fSpecial boldmessage\n" - -echo "aap" -echo "noot" -echo "mies" -echo "testing" -echo "Bold" -if [ -n "$@" ] +if [ x"$@" = x"quit" ] then - echo "$@" + exit 0 +fi + +if [ "$@" ] +then + for a in {1..10} + do + echo "$a" + done + echo "quit" +else + echo -en "\x00prompt\x1ftesting\n" + echo -en "\0urgent\x1f0,2\n" + echo -en "\0active\x1f1\n" + echo -en "\0markup-rows\x1ftrue\n" + echo -en "\0message\x1fSpecial boldmessage\n" + + echo "aap" + echo "noot" + echo "mies" + echo "testing" + echo "Bold" + echo "quit" fi diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 9daf1354..4f53ee3e 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -78,7 +78,7 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) char *value = line + length_key + 1; if ( strcasecmp ( line, "message" ) == 0 ) { g_free ( pd->message ); - pd->message = g_strdup ( value ); + pd->message = strlen(value)? g_strdup ( value ):NULL; } else if ( strcasecmp ( line, "prompt" ) == 0 ) { g_free ( pd->prompt ); @@ -187,6 +187,19 @@ static unsigned int script_mode_get_num_entries ( const Mode *sw ) return rmpd->cmd_list_length; } +static void script_mode_reset_highlight ( Mode *sw ) +{ + ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; + + rmpd->num_urgent_list = 0; + g_free ( rmpd->urgent_list ); + rmpd->urgent_list = NULL; + rmpd->num_active_list = 0; + g_free ( rmpd->active_list ); + rmpd->active_list = NULL; + +} + static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; @@ -204,9 +217,11 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { + script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, rmpd->cmd_list[selected_line], &new_length ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { + script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, *input, &new_length ); }