Skip to content

Commit

Permalink
Fix encoding issue. Add showkey command
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed May 11, 2018
1 parent 4518fa8 commit 58c5038
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 130 deletions.
4 changes: 2 additions & 2 deletions Blink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1012,26 +1012,26 @@
D23970E720A07B9100881637 /* escape.hxx */,
D23970E820A07B9100881637 /* prompt.cxx */,
D23970E920A07B9100881637 /* replxx_impl.hxx */,
D23970EA20A07B9100881637 /* util.hxx */,
D23970EB20A07B9100881637 /* windows.hxx */,
D23970EC20A07B9100881637 /* conversion.cxx */,
D23970ED20A07B9100881637 /* replxx.cxx */,
D23970EE20A07B9100881637 /* keycodes.hxx */,
D23970F620A07B9100881637 /* ConvertUTF.h */,
D23970EF20A07B9100881637 /* ConvertUTF.cpp */,
D23970F020A07B9100881637 /* history.hxx */,
D23970F120A07B9100881637 /* io.cxx */,
D23970F220A07B9100881637 /* inputbuffer.cxx */,
D23970F320A07B9100881637 /* history.cxx */,
D23970F420A07B9100881637 /* io.hxx */,
D23970F520A07B9100881637 /* inputbuffer.hxx */,
D23970F620A07B9100881637 /* ConvertUTF.h */,
D23970F720A07B9100881637 /* killring.hxx */,
D23970F820A07B9100881637 /* escape.cxx */,
D23970F920A07B9100881637 /* prompt.hxx */,
D23970FA20A07B9100881637 /* util.cxx */,
D23970FB20A07B9100881637 /* windows.cxx */,
D23970FC20A07B9100881637 /* utfstring.hxx */,
D23970FD20A07B9100881637 /* conversion.hxx */,
D23970EA20A07B9100881637 /* util.hxx */,
D23970FE20A07B9100881637 /* wcwidth.cpp */,
);
path = src;
Expand Down
7 changes: 4 additions & 3 deletions Blink/TermDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ - (void)attachView:(TermView *)termView

- (void)setRawMode:(BOOL)rawMode
{
_rawMode = rawMode;
_input.raw = rawMode;
dispatch_sync(dispatch_get_main_queue(), ^{
_rawMode = rawMode;
[_view setAutoCarriageReturn:!rawMode];
});
}

- (void)setSecureTextEntry:(BOOL)secureTextEntry
Expand Down Expand Up @@ -228,7 +230,6 @@ - (void)attachInput:(TermInput *)termInput
[_input reset];
}

_input.raw = _rawMode;
_input.device = self;
if (_secureTextEntry != _input.secureTextEntry) {
_input.secureTextEntry = _secureTextEntry;
Expand Down
2 changes: 1 addition & 1 deletion Blink/TermInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@end

@interface TermInput : UITextView
@property BOOL raw;

@property BOOL softwareKB;

@property TermDevice *device;
Expand Down
21 changes: 13 additions & 8 deletions Blink/TermInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ + (NSString *)KEY:(NSString *)c MOD:(NSInteger)m RAW:(BOOL)raw
} else if (c == UIKeyInputEscape) {
return @"\x1B";
} else if ([c isEqual:@"\n"]) {
return @"\r";
// See raw mode: http://man7.org/linux/man-pages/man3/termios.3.html
if (raw) {
// INLCR Translate NL to CR on input
return @"\r";
}
return c;
}

if (m) {
Expand Down Expand Up @@ -430,7 +435,7 @@ - (void)_insertText:(NSString *)text
NSString *value = [text substringFromIndex:(range.length)];
[_device write:[CC FKEY:[value integerValue]]];
} else {
[_device write:[CC KEY:text MOD:0 RAW:_raw]];
[_device write:[CC KEY:text MOD:0 RAW:_device.rawMode]];
}
} else {
NSUInteger modifiers = [[_smartKeys view] modifiers];
Expand All @@ -441,7 +446,7 @@ - (void)_insertText:(NSString *)text
} else if (modifiers == (KbdCtrlModifier | KbdAltModifier)) {
[self _escCtrlSeqWithInput: text];
} else {
[_device write:[CC KEY:text MOD:0 RAW:_raw]];
[_device write:[CC KEY:text MOD:0 RAW:_device.rawMode]];
}
}
}
Expand Down Expand Up @@ -549,7 +554,7 @@ - (void)arrowSeq:(UIKeyCommand *)cmd
if (_device.view.hasSelection) {
[self _changeSelection:cmd];
} else {
[_device write:[CC KEY:cmd.input MOD:cmd.modifierFlags RAW:_raw]];
[_device write:[CC KEY:cmd.input MOD:cmd.modifierFlags RAW:_device.rawMode]];
}
}

Expand Down Expand Up @@ -603,13 +608,13 @@ - (void)cursorSeq:(UIKeyCommand *)cmd
}

if (cmd.input == UIKeyInputUpArrow) {
[_device write:[CC KEY:SpecialCursorKeyPgUp MOD:0 RAW:_raw]];
[_device write:[CC KEY:SpecialCursorKeyPgUp MOD:0 RAW:_device.rawMode]];
} else if (cmd.input == UIKeyInputDownArrow) {
[_device write:[CC KEY:SpecialCursorKeyPgDown MOD:0 RAW:_raw]];
[_device write:[CC KEY:SpecialCursorKeyPgDown MOD:0 RAW:_device.rawMode]];
} else if (cmd.input == UIKeyInputLeftArrow) {
[_device write:[CC KEY:SpecialCursorKeyHome MOD:0 RAW:_raw]];
[_device write:[CC KEY:SpecialCursorKeyHome MOD:0 RAW:_device.rawMode]];
} else if (cmd.input == UIKeyInputRightArrow) {
[_device write:[CC KEY:SpecialCursorKeyEnd MOD:0 RAW:_raw]];
[_device write:[CC KEY:SpecialCursorKeyEnd MOD:0 RAW:_device.rawMode]];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Blink/replxx/src/conversion.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void to_lower( std::string& s_ ) {
}

bool is_8bit_encoding( void ) {
return true;
return false;
// bool is8BitEncoding( false );
// string origLC( setlocale( LC_CTYPE, nullptr ) );
// string lc( origLC );
Expand Down
6 changes: 3 additions & 3 deletions Blink/replxx/src/io.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ char32_t read_char(void) {
// drop out of this loop on ctrl-C
if (keys[0] == ctrlChar('C')) {
printf("Leaving keyboard debugging mode (on ctrl-C)\n");
fflush(stdout);
fflush(__thread_stdout);
return -2;
}
}
Expand Down Expand Up @@ -506,10 +506,10 @@ void clear_screen( CLEAR_SCREEN clearScreen_ ) {
#else
if ( clearScreen_ == CLEAR_SCREEN::WHOLE ) {
char const clearCode[] = "\033c\033[H\033[2J\033[0m";
static_cast<void>( write(1, clearCode, sizeof ( clearCode ) - 1) >= 0 );
static_cast<void>( fwrite(clearCode, 1, sizeof ( clearCode ) - 1, __thread_stdout) >= 0);
} else {
char const clearCode[] = "\033[J";
static_cast<void>( write(1, clearCode, sizeof ( clearCode ) - 1) >= 0 );
static_cast<void>( fwrite(clearCode, 1, sizeof ( clearCode ) - 1, __thread_stdout) >= 0 );
}
#endif
}
Expand Down
55 changes: 28 additions & 27 deletions Blink/replxx/src/replxx.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -795,33 +795,34 @@ int replxx_history_size( ::Replxx* replxx_ ) {
* on screen for debugging / development purposes. It is implemented
* by the replxx-c-api-example program using the --keycodes option. */
void replxx_debug_dump_print_codes(void) {
// char quit[4];
//
// printf(
// "replxx key codes debugging mode.\n"
// "Press keys to see scan codes. Type 'quit' at any time to exit.\n");
// if (enableRawMode() == -1) return;
// memset(quit, ' ', 4);
// while (1) {
// char c;
// int nread;
//
//#if _WIN32
// nread = _read(STDIN_FILENO, &c, 1);
//#else
// nread = read(STDIN_FILENO, &c, 1);
//#endif
// if (nread <= 0) continue;
// memmove(quit, quit + 1, sizeof(quit) - 1); /* shift string to left. */
// quit[sizeof(quit) - 1] = c; /* Insert current char on the right. */
// if (memcmp(quit, "quit", sizeof(quit)) == 0) break;
//
// printf("'%c' %02x (%d) (type quit to exit)\n", isprint(c) ? c : '?', (int)c,
// (int)c);
// printf("\r"); /* Go left edge manually, we are in raw mode. */
// fflush(stdout);
// }
// disableRawMode();
char quit[4];

fprintf(thread_stdout,
"Press keys to see scan codes. Type 'quit' at any time to exit.\r\n");
if (enableRawMode() == -1) return;
memset(quit, ' ', 4);
while (1) {
char c;
int nread;

#if _WIN32
nread = _read(STDIN_FILENO, &c, 1);
#else
nread = read(fileno(thread_stdin), &c, 1);
#endif
if (nread <= 0) continue;
memmove(quit, quit + 1, sizeof(quit) - 1); /* shift string to left. */
quit[sizeof(quit) - 1] = c; /* Insert current char on the right. */
if (memcmp(quit, "quit", sizeof(quit)) == 0) break;



fprintf(thread_stdout, "'%c'\t%3d 0%03o 0x%02x (type quit to exit)\n", isprint(c) ? c : '?', (int)c,
(int)c, (int)c);
fprintf(thread_stdout, "\r"); /* Go left edge manually, we are in raw mode. */
fflush(thread_stdout);
}
disableRawMode();
}

int replxx_install_window_change_handler( ::Replxx* replxx_ ) {
Expand Down
Loading

0 comments on commit 58c5038

Please sign in to comment.