From c0b70dcdd2c2c78279aa9991b388a9d4f2b73631 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Tue, 9 Nov 2021 14:55:33 +0800 Subject: [PATCH] Always re-render prompt while navigating history --- src/replxx_impl.cxx | 12 +++++++++--- src/replxx_impl.hxx | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/replxx_impl.cxx b/src/replxx_impl.cxx index 6fcacff..af6c18e 100644 --- a/src/replxx_impl.cxx +++ b/src/replxx_impl.cxx @@ -949,7 +949,7 @@ int Replxx::ReplxxImpl::virtual_render( char32_t const* buffer_, int len_, int& * Refresh the user's input line: the prompt is already onscreen and is not * redrawn here screen position */ -void Replxx::ReplxxImpl::refresh_line( HINT_ACTION hintAction_ ) { +void Replxx::ReplxxImpl::refresh_line( HINT_ACTION hintAction_, bool refreshPrompt_ ) { int long long now( now_us() ); int long long duration( now - _lastRefreshTime ); if ( duration < RAPID_REFRESH_US ) { @@ -957,6 +957,12 @@ void Replxx::ReplxxImpl::refresh_line( HINT_ACTION hintAction_ ) { _refreshSkipped = true; return; } + if ( refreshPrompt_ ) + { + _terminal.jump_cursor( 0, 0 ); + _prompt.write(); + _prompt._cursorRowOffset = _prompt._extraLines; + } _refreshSkipped = false; render( hintAction_ ); handle_hints( hintAction_ ); @@ -1894,7 +1900,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::history_move( bool previous_ ) { } _data.assign( _history.current() ); _pos = _data.length(); - refresh_line(); + refresh_line( HINT_ACTION::REGENERATE, true /* refreshPrompt */ ); return ( Replxx::ACTION_RESULT::CONTINUE ); } @@ -1941,7 +1947,7 @@ Replxx::ACTION_RESULT Replxx::ReplxxImpl::history_jump( bool back_ ) { _history.jump( back_ ); _data.assign( _history.current() ); _pos = _data.length(); - refresh_line(); + refresh_line( HINT_ACTION::REGENERATE, true /* refreshPrompt */ ); } return ( Replxx::ACTION_RESULT::CONTINUE ); } diff --git a/src/replxx_impl.hxx b/src/replxx_impl.hxx index 8f6357b..b8ffcbf 100644 --- a/src/replxx_impl.hxx +++ b/src/replxx_impl.hxx @@ -266,7 +266,7 @@ private: void call_modify_callback( void ); completions_t call_completer( std::string const& input, int& ) const; hints_t call_hinter( std::string const& input, int&, Replxx::Color& color ) const; - void refresh_line( HINT_ACTION = HINT_ACTION::REGENERATE ); + void refresh_line( HINT_ACTION = HINT_ACTION::REGENERATE, bool refreshPrompt_ = false ); void move_cursor( void ); void indent( void ); int virtual_render( char32_t const*, int, int&, int&, Prompt const* = nullptr );