Rewrite DBCS character handling of Backspace key in command history

This commit is contained in:
maron2000 2025-03-28 23:49:15 +09:00
parent fc3dcc496f
commit 49f77509a2

View File

@ -979,88 +979,64 @@ void DOS_Shell::InputCommand(char * line) {
if(str_index) { if(str_index) {
size += DeleteBackspace(false, line, str_index, str_len); size += DeleteBackspace(false, line, str_index, str_len);
} }
} else { }
int k=1; else {
if(str_index == 0)break; if(str_index == 0)break;
if (isDBCSCP()
#if defined(USE_TTF)
&&dbcs_sbcs
#endif
&&str_index>1&&(line[str_index-1]<0||((dos.loaded_codepage==932||(dos.loaded_codepage==936&&gbk)||dos.loaded_codepage==950||dos.loaded_codepage==951)&&line[str_index-1]>=0x40))&&line[str_index-2]<0)
k=2;
page = real_readb(BIOSMEM_SEG, BIOSMEM_CURRENT_PAGE); page = real_readb(BIOSMEM_SEG, BIOSMEM_CURRENT_PAGE);
BIOS_NCOLS; BIOS_NROWS; BIOS_NCOLS; BIOS_NROWS;
col = CURSOR_POS_COL(page); uint8_t bytes = 1; // Previous character is DBCS or SBCS
row = CURSOR_POS_ROW(page); if(isDBCSCP()
if(str_index >= k) { #if defined(USE_TTF)
if(col == 0) { && dbcs_sbcs
if(k == 1) { #endif
WriteChar(ncols - 1, row - 1, page, ' ', 0, false); ) bytes = GetLastCount(line, str_index);
backone();
} if(str_index < str_len) {
else {
uint16_t get_char;
ReadCharAttr(ncols - 1, row - 1, page, &get_char);
WriteChar(ncols - 1, row - 1, page, ' ', 0, false);
WriteChar(ncols - 2, row - 1, page, ' ', 0, false);
backone(); backone();
if((uint8_t)(line[str_index - 1] & 0xFF) != (uint8_t)(get_char & 0xFF)) {
WriteChar(ncols - 3, row - 1, page, ' ', 0, false);
backone();
}
}
}
else {
WriteChar(col - 1, row, page, ' ', 0, false);
backone();
if(k == 2) {
assert(col >= k);
WriteChar(col - 2, row, page, ' ', 0, false);
backone();
}
}
if(str_index == str_len) {
if(k == 2)line[str_len - 2] = 0;
line[str_len - 1] = 0;
line[str_len] = 0;
str_len -= k;
str_index -= k;
size += k;
break;
}
col = CURSOR_POS_COL(page);
uint16_t a = str_len - str_index; uint16_t a = str_len - str_index;
uint8_t* text = reinterpret_cast<uint8_t*>(&line[str_index]); uint8_t* text = reinterpret_cast<uint8_t*>(&line[str_index]);
DOS_WriteFile(STDOUT, text, &a);//write buffer to screen DOS_WriteFile(STDOUT, text, &a);
uint16_t col2 = CURSOR_POS_COL(page); }
row = CURSOR_POS_ROW(page); backone();
if(k == 2) { if(bytes == 2 && str_len >= 2) backone();
outc(' '); outc(' '); backone(); backone(); outc(' ');
if(bytes == 2 && str_len >= 2) outc(' ');
backone();
if(bytes == 2 && str_len >= 2) backone();
if(str_index < str_len) {
for(uint16_t i = str_index - bytes; i < str_len - bytes; i++) {
line[i] = line[i + bytes]; // Shift buffer to left
} }
else { }
outc(' '); backone(); line[str_len - 1] = '\0';
} if(bytes == 2)line[str_len - 2] = '\0';
if(col2 >= ncols - (k == 2 ? 3 : 1) && row < nrows) { str_len -= bytes;
for(int i = 0; i <= k; i++) WriteChar(i, row + 1, page, ' ', 0, false); str_index -= bytes;
} size -= bytes;
col2 = CURSOR_POS_COL(page); if(str_index < str_len) {
if(col2 >= a) INT10_SetCursorPos(row, col2 - a, page); for(int i = str_len; i > 0; i--) backone();
else {
uint16_t lines_up = (a - col2 - 1) / ncols + 1; col = CURSOR_POS_COL(page);
if(col2 < ncols) for(int i = col2; i < ncols; i++) WriteChar(i, row, page, ' ', 0, false); while(col > prompt_col) {
if(row >= lines_up) INT10_SetCursorPos(row - lines_up, col, page); backone();
else INT10_SetCursorPos(0, 0, page); col = CURSOR_POS_COL(page);
} }
for(Bitu i = str_index; i <= str_len; i++) { uint16_t a = str_len;
line[i-k] = line[i]; uint8_t* text = reinterpret_cast<uint8_t*>(&line[0]);
DOS_WriteFile(STDOUT, text, &a); // Rewrite the command history
outc(' '); outc(' '); backone(); backone();
for(int i = str_len; i > 0; i--) backone();
col = CURSOR_POS_COL(page);
while(col > prompt_col) {
backone();
col = CURSOR_POS_COL(page);
} }
line[str_len - k] = 0;
line[str_len - k + 1] = 0; a = str_index;
line[str_len] = 0; text = reinterpret_cast<uint8_t*>(&line[0]);
str_index -= k; DOS_WriteFile(STDOUT, text, &a); // Move to the cursor position
str_len -= k;
size += k;
} }
} }
if (l_completion.size()) l_completion.clear(); if (l_completion.size()) l_completion.clear();