From 0c9a1a56c22de9a34d678898168a30aeda86b1a3 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 25 Mar 2012 03:00:38 -0700 Subject: [PATCH] Lots of work on web config Change to make fish immediately show color changes --- env.cpp | 12 +- input_common.cpp | 29 ++- input_common.h | 3 + reader.cpp | 47 ++-- reader.h | 6 + screen.cpp | 6 +- screen.h | 10 +- web_config/index.html | 494 +++++++++++++++++++++++++++++++++------- web_config/webconfig.py | 98 ++++++-- 9 files changed, 576 insertions(+), 129 deletions(-) diff --git a/env.cpp b/env.cpp index 205562a14..645dca02e 100644 --- a/env.cpp +++ b/env.cpp @@ -341,7 +341,9 @@ static void react_to_variable_change(const wcstring &key) { handle_locale(); } else if (key == L"fish_term256") { update_fish_term256(); - reader_repaint_needed(); + reader_react_to_color_change(); + } else if (string_prefixes_string(L"fish_color_", key)) { + reader_react_to_color_change(); } } @@ -355,11 +357,6 @@ static void universal_callback( int type, { const wchar_t *str=0; - if( var_is_locale( name ) ) - { - handle_locale(); - } - switch( type ) { case SET: @@ -388,6 +385,9 @@ static void universal_callback( int type, event_fire( &ev ); ev.arguments.reset(NULL); } + + if (name) + react_to_variable_change(name); } /** diff --git a/input_common.cpp b/input_common.cpp index 0e1fb40b9..d048211d0 100644 --- a/input_common.cpp +++ b/input_common.cpp @@ -44,16 +44,23 @@ static wint_t lookahead_arr[1024]; */ static int lookahead_count = 0; -/** - Callback function for handling interrupts on reading -*/ +/** Callback function for handling interrupts on reading */ static int (*interrupt_handler)(); +/** Callback function to be invoked before reading each byte */ +static void (*poll_handler)(); + + void input_common_init( int (*ih)() ) { interrupt_handler = ih; } +void input_common_set_poll_callback(void (*handler)(void)) +{ + poll_handler = handler; +} + void input_common_destroy() { @@ -66,10 +73,14 @@ void input_common_destroy() static wint_t readb() { unsigned char arr[1]; - int do_loop = 0; + bool do_loop = false; do { + /* Invoke any poll handler */ + if (poll_handler) + poll_handler(); + fd_set fdset; int fd_max=0; int ioport = iothread_port(); @@ -88,7 +99,7 @@ static wint_t readb() } - do_loop = 0; + do_loop = false; res = select( fd_max + 1, &fdset, 0, 0, 0 ); if( res==-1 ) @@ -113,7 +124,7 @@ static wint_t readb() } - do_loop = 1; + do_loop = true; break; } default: @@ -133,7 +144,7 @@ static wint_t readb() { debug( 3, L"Wake up on universal variable event" ); env_universal_read_all(); - do_loop = 1; + do_loop = true; if( lookahead_count ) { @@ -148,7 +159,7 @@ static wint_t readb() { iothread_service_completion(); } - do_loop = 1; + do_loop = true; } if( FD_ISSET( 0, &fdset ) ) @@ -160,7 +171,7 @@ static wint_t readb() */ return R_EOF; } - do_loop = 0; + do_loop = false; } } } diff --git a/input_common.h b/input_common.h index a2b361f79..759bc9cec 100644 --- a/input_common.h +++ b/input_common.h @@ -30,6 +30,9 @@ enum */ void input_common_init( int (*ih)() ); +/* Sets a callback to be invoked every time a byte is read */ +void input_common_set_poll_callback(void (*handler)(void)); + /** Free memory used by the library */ diff --git a/reader.cpp b/reader.cpp index eaa7d3e04..b645c2b07 100644 --- a/reader.cpp +++ b/reader.cpp @@ -302,7 +302,10 @@ class reader_data_t Keep track of whether any internal code has done something which is known to require a repaint. */ - int repaint_needed; + bool repaint_needed; + + /** Whether the a screen reset is needed after a repaint. */ + bool screen_reset_needed; }; /** @@ -446,7 +449,7 @@ static void reader_repaint() &indents[0], data->buff_pos ); #endif - data->repaint_needed = 0; + data->repaint_needed = false; } /** @@ -678,6 +681,9 @@ void reader_init() shell_modes.c_lflag &= ~ECHO; /* turn off echo mode */ shell_modes.c_cc[VMIN]=1; shell_modes.c_cc[VTIME]=0; + + /* Repaint if necessary before each byte is read. This lets us react immediately to universal variable color changes. */ + input_common_set_poll_callback(reader_repaint_if_needed); } @@ -699,12 +705,29 @@ void reader_exit( int do_exit, int forced ) void reader_repaint_needed() { - if( data ) - { - data->repaint_needed = 1; + if (data) { + data->repaint_needed = true; } } +void reader_repaint_if_needed() { + if (data && data->screen_reset_needed) { + s_reset( &data->screen, false); + data->screen_reset_needed = false; + } + + if (data && data->repaint_needed) { + reader_repaint(); + /* reader_repaint clears repaint_needed */ + } +} + +void reader_react_to_color_change() { + if (data) { + data->repaint_needed = true; + data->screen_reset_needed = true; + } +} /** @@ -1651,7 +1674,7 @@ static int handle_completions( std::vector &comp ) } free( prefix ); - s_reset( &data->screen, 1 ); + s_reset( &data->screen, true); reader_repaint(); } @@ -2325,7 +2348,7 @@ void reader_pop() { end_loop = 0; //history_set_mode( data->app_name.c_str() ); - s_reset( &data->screen, 1 ); + s_reset( &data->screen, true); } } @@ -2678,7 +2701,7 @@ const wchar_t *reader_readline() exec_prompt(); reader_super_highlight_me_plenty( data->buff_pos ); - s_reset( &data->screen, 1 ); + s_reset( &data->screen, true); reader_repaint(); /* @@ -2804,9 +2827,7 @@ const wchar_t *reader_readline() case R_NULL: { - if( data->repaint_needed ) - reader_repaint(); - + reader_repaint_if_needed(); break; } @@ -2814,7 +2835,7 @@ const wchar_t *reader_readline() { exec_prompt(); write_loop( 1, "\r", 1 ); - s_reset( &data->screen, 0 ); + s_reset( &data->screen, false); reader_repaint(); break; } @@ -3084,7 +3105,7 @@ const wchar_t *reader_readline() */ default: { - s_reset( &data->screen, 1 ); + s_reset( &data->screen, true); reader_repaint(); break; } diff --git a/reader.h b/reader.h index af66e6310..eda4b3529 100644 --- a/reader.h +++ b/reader.h @@ -75,6 +75,12 @@ void reader_write_title(); */ void reader_repaint_needed(); +/** Call this function to tell the reader that some color has changed. */ +void reader_react_to_color_change(); + +/* Repaint immediately if needed. */ +void reader_repaint_if_needed(); + /** Run the specified command with the correct terminal modes, and while taking care to perform job notification, set the title, etc. diff --git a/screen.cpp b/screen.cpp index f5496bbac..3bd1b57c9 100644 --- a/screen.cpp +++ b/screen.cpp @@ -344,7 +344,7 @@ static void s_check_status( screen_t *s) int prev_line = s->actual.cursor[1]; write_loop( 1, "\r", 1 ); - s_reset( s, 0 ); + s_reset( s, false ); s->actual.cursor[1] = prev_line; } } @@ -606,7 +606,7 @@ static void s_update( screen_t *scr, const wchar_t *prompt ) need_clear = 1; s_move( scr, &output, 0, 0 ); scr->actual_width = screen_width; - s_reset( scr, 0 ); + s_reset( scr, false ); } if( wcscmp( prompt, scr->actual_prompt.c_str() ) ) @@ -855,7 +855,7 @@ void s_write( screen_t *s, s_save_status( s ); } -void s_reset( screen_t *s, int reset_cursor ) +void s_reset( screen_t *s, bool reset_cursor ) { CHECK( s, ); diff --git a/screen.h b/screen.h index 0fe08eec3..0f930a178 100644 --- a/screen.h +++ b/screen.h @@ -85,10 +85,11 @@ class screen_data_t }; /** - The struct representing the current and desired screen contents. + The class representing the current and desired screen contents. */ -typedef struct +class screen_t { + public: /** The internal representation of the desired screen contents. */ @@ -123,8 +124,7 @@ typedef struct other than from fish's main loop, in which case we need to redraw. */ struct stat prev_buff_1, prev_buff_2, post_buff_1, post_buff_2; -} - screen_t; +}; /** This is the main function for the screen putput library. It is used @@ -155,6 +155,6 @@ void s_write( screen_t *s, resizing, there will be one line of garbage for every repaint, which will quicly fill the screen. */ -void s_reset( screen_t *s, int reset_cursor ); +void s_reset( screen_t *s, bool reset_cursor ); #endif diff --git a/web_config/index.html b/web_config/index.html index f355078b8..f4abf4d2a 100644 --- a/web_config/index.html +++ b/web_config/index.html @@ -56,34 +56,56 @@ body { height: 30px; } -#master_detail_box { - overflow: hidden; +#master_detail_table { + display: table; + margin-top: 10px; } #master { - float: left; + display: table-cell; text-align: right; min-width: 200px; font-size: 16pt; padding-left: 12px; + padding-bottom: 0px; margin-top: -7px; } +#detail { + display: table-cell; + border: 1px solid #555; + background-color: #181818; + padding-top: 30px; + padding-bottom: 20px; + padding-left: 30px; + padding-right: 30px; +} + +#detail_function { + white-space: pre; + overflow: auto; + width: 100%; +} + .master_element { - padding-top: 7px; - padding-bottom: 12px; + padding-top: 6px; + padding-bottom: 11px; padding-left: 5px; padding-right: 32px; font-size: 12pt; + /* Make our border overlap the detail, even if we're unselected (so it doesn't jump when selected) */ + position: relative; + left: 1px; } .selected_master_elem { border: 1px solid #555; border-right: none; - /* Make our border overlap the box */ - position: relative; - left: 1px; - background-color: black; + background-color: #181818; + + /* Pad one less than .master_element, to accomodate our border. */ + padding-top: 5px; + padding-bottom: 10px; } .master_element_text { @@ -93,8 +115,33 @@ body { } #colorpicker_term256 { - padding: 30px; - border: 1px solid #555; + border: solid #444 1px; +} + +.colorpicker_modifiers { + margin-top: 10px; + display:inline-block; + margin-left: auto; + margin-right: auto; + color: #AAA; + font-size: smaller; +} + +.colorpicker_modifier_cell { + cursor: pointer; + display:inline-block; + text-align: center; + border: solid #333 2px; + padding: 5px; + margin-top: 5px; + margin-left: auto; + margin-right: auto; +} + +.modifier_cell_selected { + color: #CCC; + border-color: #AAA; + background-color: #444; } #data_table { @@ -120,16 +167,46 @@ body { white-space: nowrap; } +.colorpicker_ground { + position: relative; + bottom: 50px; + margin: 0px; + height: 50px; + margin-bottom: -50px; +} + +.colorpicker_ground_tab { + cursor: pointer; + color: #AAA; + border: solid 2px #555; + padding-top: 5px; + padding-bottom: 5px; + padding-left: 7px; + padding-right: 7px; + display: inline-block; + background-color: black; + margin-right: -2px; + min-width: 110px; + text-align: center; +} + +.colorpicker_ground_selected { + background-color: #777; + color: white; +} + .colorpicker_term256_row { } .colorpicker_term256_cell { - width: 24; - height: 24; + width: 27; + height: 27; } .colorpicker_cell_selected { - border: solid white 3px; + border: dashed white 3px; + width: 21; + height: 21; } .error_msg { @@ -145,6 +222,10 @@ body {