Skip to content

Commit

Permalink
Restore cursor and clean screen below cursor after command
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 9, 2018
1 parent a3aa53b commit 4270b20
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions Blink/Repl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

- (void)sigwinch;
- (void)loopWithCallback:(BOOL(^)(NSString *cmd)) callback;
- (void)clearToEnd;

- (int)clear_main:(int)argc argv:(char **)argv;
- (int)history_main:(int)argc argv:(char **)argv;
Expand Down
12 changes: 11 additions & 1 deletion Blink/Repl.m
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,13 @@ - (void)loopWithCallback:(BOOL(^)(NSString *cmd)) callback
if (!callback(cmdline)) {
break;
}


dispatch_sync(dispatch_get_main_queue(), ^{
[_device.view restore];
});

replxx_clear_screen_to_end(_replxx);

printf("\033]0;blink\007");
[_device setRawMode:NO];
}
Expand All @@ -543,6 +549,10 @@ - (void)loopWithCallback:(BOOL(^)(NSString *cmd)) callback
// _replxx = nil;
}

- (void)clearToEnd {

}

- (NSString *)_input:(char *)prompt
{
if (_replxx == nil || _stream.in == NULL) {
Expand Down
4 changes: 4 additions & 0 deletions Blink/TermJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,9 @@ NSString *term_setAutoCarriageReturn(BOOL state)
return [NSString stringWithFormat:@"term_setAutoCarriageReturn(%@);", state ? @"true" : @"false"];
}

NSString *term_restore() {
return @"term_restore()";
}


#endif /* TermJS_h */
1 change: 1 addition & 0 deletions Blink/TermView.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
- (void)pasteSelection:(id _Nullable)sender;
- (void)terminate;
- (void)reset;
- (void)restore;

- (void)blur;
- (void)focus;
Expand Down
5 changes: 5 additions & 0 deletions Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ - (void)reset
[_webView evaluateJavaScript:term_reset() completionHandler:nil];
}

- (void)restore
{
[self _evalJSScript:term_restore()];
}

- (void)increaseFontSize
{
[_webView evaluateJavaScript:term_increaseFontSize() completionHandler:nil];
Expand Down
1 change: 1 addition & 0 deletions Blink/replxx/include/replxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ char const* replxx_history_line( Replxx*, int index );
int replxx_history_save( Replxx*, const char* filename );
int replxx_history_load( Replxx*, const char* filename );
void replxx_clear_screen( Replxx* );
void replxx_clear_screen_to_end( Replxx* );
void replxx_debug_dump_print_codes(void);
/* the following is extension to the original linenoise API */
int replxx_install_window_change_handler( Replxx* );
Expand Down
10 changes: 10 additions & 0 deletions Blink/replxx/src/replxx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ char const* Replxx::ReplxxImpl::input( std::string const& prompt ) {
void Replxx::ReplxxImpl::clear_screen( void ) {
replxx::clear_screen( CLEAR_SCREEN::WHOLE );
}

void Replxx::ReplxxImpl::clear_screen_to_end( void ) {
replxx::clear_screen( CLEAR_SCREEN::TO_END );
}


int Replxx::ReplxxImpl::install_window_change_handler( void ) {
#ifndef _WIN32
Expand Down Expand Up @@ -607,6 +612,11 @@ void replxx_clear_screen( ::Replxx* replxx_ ) {
return ( replxx->clear_screen() );
}

void replxx_clear_screen_to_end( ::Replxx* replxx_ ) {
replxx::Replxx::ReplxxImpl* replxx( reinterpret_cast<replxx::Replxx::ReplxxImpl*>( replxx_ ) );
return ( replxx->clear_screen_to_end() );
}

/**
* replxx_set_preload_buffer provides text to be inserted into the command buffer
*
Expand Down
1 change: 1 addition & 0 deletions Blink/replxx/src/replxx_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public:
void set_no_color( bool val );
void set_max_history_size( int len );
void clear_screen( void );
void clear_screen_to_end(void);
int install_window_change_handler( void );
int window_changed( void );
completions_t call_completer( std::string const& input, int breakPos ) const;
Expand Down
6 changes: 6 additions & 0 deletions Resources/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,3 +426,9 @@ function term_applySexyTheme(theme) {
function term_setAutoCarriageReturn(state) {
t.setAutoCarriageReturn(state);
}

function term_restore() {
t.primaryScreen_.textAttributes.reset();
t.setVTScrollRegion(null, null);
t.setCursorVisible(true);
}

0 comments on commit 4270b20

Please sign in to comment.