git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Usermode/libreadline - Fix backspace
[tpg/acess2.git]
/
Usermode
/
Libraries
/
libreadline.so_src
/
main.c
diff --git
a/Usermode/Libraries/libreadline.so_src/main.c
b/Usermode/Libraries/libreadline.so_src/main.c
index
719667d
..
5937c6b
100644
(file)
--- a/
Usermode/Libraries/libreadline.so_src/main.c
+++ b/
Usermode/Libraries/libreadline.so_src/main.c
@@
-6,9
+6,11
@@
*/
#include <readline.h>
#include <acess/sys.h>
*/
#include <readline.h>
#include <acess/sys.h>
+#include <acess/devices/pty.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#define STDIN_FD 0
#define STDOUT_FD 1
#define STDIN_FD 0
#define STDOUT_FD 1
@@
-80,7
+82,7
@@
char *Readline_NonBlock(tReadline *Info)
int len, i;
// Read as much as possible (appending to remaining data)
int len, i;
// Read as much as possible (appending to remaining data)
- len =
r
ead(STDIN_FD, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen);
+ len =
_SysR
ead(STDIN_FD, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen);
if( len <= 0 ) return NULL;
Info->ReadBuffer[Info->ReadBufferLen + len] = '\0';
if( len <= 0 ) return NULL;
Info->ReadBuffer[Info->ReadBufferLen + len] = '\0';
@@
-104,15
+106,24
@@
char *Readline_NonBlock(tReadline *Info)
}
// Return NULL when command is still being edited
}
// Return NULL when command is still being edited
+ errno = EAGAIN;
return NULL;
}
char *Readline(tReadline *Info)
{
char *ret;
return NULL;
}
char *Readline(tReadline *Info)
{
char *ret;
+
+ // stty -echo,canon
+ struct ptymode mode = {.InputMode = 0, .OutputMode = 0};
+ _SysIOCtl(STDIN_FD, PTY_IOCTL_SETMODE, &mode);
- while( NULL == (ret = Readline_NonBlock(Info)) );
-
+ while( NULL == (ret = Readline_NonBlock(Info)) && errno == EAGAIN );
+
+ // stty +echo,canon
+ mode.InputMode = PTYIMODE_CANON|PTYIMODE_ECHO;
+ _SysIOCtl(STDIN_FD, PTY_IOCTL_SETMODE, &mode);
+
return ret;
}
return ret;
}
@@
-204,21
+215,21
@@
int Readline_int_ParseCharacter(tReadline *Info, char *Input)
// Move to the beginning of the line
pos = oldLen;
// Move to the beginning of the line
pos = oldLen;
- while(pos--)
w
rite(STDOUT_FD, "\x1B[D", 3);
+ while(pos--)
_SysW
rite(STDOUT_FD, "\x1B[D", 3);
// Update state
Info->CurBuffer = Info->History[--Info->HistoryPos];
Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
// Update state
Info->CurBuffer = Info->History[--Info->HistoryPos];
Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
-
w
rite(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
+
_SysW
rite(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
Info->BufferWritePos = Info->BufferUsed;
// Clear old characters (if needed)
if( oldLen > Info->BufferWritePos ) {
pos = oldLen - Info->BufferWritePos;
Info->BufferWritePos = Info->BufferUsed;
// Clear old characters (if needed)
if( oldLen > Info->BufferWritePos ) {
pos = oldLen - Info->BufferWritePos;
- while(pos--)
w
rite(STDOUT_FD, " ", 1);
+ while(pos--)
_SysW
rite(STDOUT_FD, " ", 1);
pos = oldLen - Info->BufferWritePos;
pos = oldLen - Info->BufferWritePos;
- while(pos--)
w
rite(STDOUT_FD, "\x1B[D", 3);
+ while(pos--)
_SysW
rite(STDOUT_FD, "\x1B[D", 3);
}
}
break;
}
}
break;
@@
-230,34
+241,34
@@
int Readline_int_ParseCharacter(tReadline *Info, char *Input)
// Move to the beginning of the line
pos = oldLen;
// Move to the beginning of the line
pos = oldLen;
- while(pos--)
w
rite(STDOUT_FD, "\x1B[D", 3);
+ while(pos--)
_SysW
rite(STDOUT_FD, "\x1B[D", 3);
// Update state
Info->CurBuffer = Info->History[Info->HistoryPos++];
Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
// Write new line
// Update state
Info->CurBuffer = Info->History[Info->HistoryPos++];
Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
// Write new line
-
w
rite(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
+
_SysW
rite(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
Info->BufferWritePos = Info->BufferUsed;
// Clear old characters (if needed)
if( oldLen > Info->BufferWritePos ) {
pos = oldLen - Info->BufferWritePos;
Info->BufferWritePos = Info->BufferUsed;
// Clear old characters (if needed)
if( oldLen > Info->BufferWritePos ) {
pos = oldLen - Info->BufferWritePos;
- while(pos--)
w
rite(STDOUT_FD, " ", 1);
+ while(pos--)
_SysW
rite(STDOUT_FD, " ", 1);
pos = oldLen - Info->BufferWritePos;
pos = oldLen - Info->BufferWritePos;
- while(pos--)
w
rite(STDOUT_FD, "\x1B[D", 3);
+ while(pos--)
_SysW
rite(STDOUT_FD, "\x1B[D", 3);
}
}
break;
case 'D': // Left
if(Info->BufferWritePos == 0) break;
Info->BufferWritePos --;
}
}
break;
case 'D': // Left
if(Info->BufferWritePos == 0) break;
Info->BufferWritePos --;
-
w
rite(STDOUT_FD, "\x1B[D", 3);
+
_SysW
rite(STDOUT_FD, "\x1B[D", 3);
break;
case 'C': // Right
if(Info->BufferWritePos == Info->BufferUsed) break;
Info->BufferWritePos ++;
break;
case 'C': // Right
if(Info->BufferWritePos == Info->BufferUsed) break;
Info->BufferWritePos ++;
-
w
rite(STDOUT_FD, "\x1B[C", 3);
+
_SysW
rite(STDOUT_FD, "\x1B[C", 3);
break;
}
break;
break;
}
break;
@@
-271,7
+282,7
@@
int Readline_int_ParseCharacter(tReadline *Info, char *Input)
case '\b':
if(Info->BufferWritePos <= 0) break; // Protect against underflows
// Write the backsapce
case '\b':
if(Info->BufferWritePos <= 0) break; // Protect against underflows
// Write the backsapce
-
write(STDOUT_FD, &ch, 1
);
+
_SysWrite(STDOUT_FD, "\b \b", 3
);
if(Info->BufferWritePos == Info->BufferUsed) // Simple case: End of string
{
Info->BufferUsed --;
if(Info->BufferWritePos == Info->BufferUsed) // Simple case: End of string
{
Info->BufferUsed --;
@@
-286,12
+297,12
@@
int Readline_int_ParseCharacter(tReadline *Info, char *Input)
buf[3] += (delta/10) % 10;
buf[4] += (delta) % 10;
// Write everything save for the deleted character
buf[3] += (delta/10) % 10;
buf[4] += (delta) % 10;
// Write everything save for the deleted character
-
w
rite(STDOUT_FD,
+
_SysW
rite(STDOUT_FD,
&Info->CurBuffer[Info->BufferWritePos],
Info->BufferUsed - Info->BufferWritePos
);
&Info->CurBuffer[Info->BufferWritePos],
Info->BufferUsed - Info->BufferWritePos
);
- ch = ' ';
write(STDOUT_FD, &ch, 1);
ch = '\b'; // Clear old last character
-
write(STDOUT_FD, buf, 7);
// Update Cursor
+ ch = ' ';
_SysWrite(STDOUT_FD, &ch, 1);
ch = '\b'; // Clear old last character
+
_SysWrite(STDOUT_FD, buf, 7);
// Update Cursor
// Alter Buffer
memmove(&Info->CurBuffer[Info->BufferWritePos-1],
&Info->CurBuffer[Info->BufferWritePos],
// Alter Buffer
memmove(&Info->CurBuffer[Info->BufferWritePos-1],
&Info->CurBuffer[Info->BufferWritePos],
@@
-325,12
+336,12
@@
int Readline_int_ParseCharacter(tReadline *Info, char *Input)
buf[2] += (delta/100) % 10;
buf[3] += (delta/10) % 10;
buf[4] += (delta) % 10;
buf[2] += (delta/100) % 10;
buf[3] += (delta/10) % 10;
buf[4] += (delta) % 10;
-
write(STDOUT_FD, &ch, 1);
// Print new character
-
w
rite(STDOUT_FD,
+
_SysWrite(STDOUT_FD, &ch, 1);
// Print new character
+
_SysW
rite(STDOUT_FD,
&Info->CurBuffer[Info->BufferWritePos],
Info->BufferUsed - Info->BufferWritePos
);
&Info->CurBuffer[Info->BufferWritePos],
Info->BufferUsed - Info->BufferWritePos
);
-
write(STDOUT_FD, buf, 7);
// Update Cursor
+
_SysWrite(STDOUT_FD, buf, 7);
// Update Cursor
// Move buffer right
memmove(
&Info->CurBuffer[Info->BufferWritePos+1],
// Move buffer right
memmove(
&Info->CurBuffer[Info->BufferWritePos+1],
@@
-340,7
+351,7
@@
int Readline_int_ParseCharacter(tReadline *Info, char *Input)
}
// Simple append
else {
}
// Simple append
else {
-
w
rite(STDOUT_FD, &ch, 1);
+
_SysW
rite(STDOUT_FD, &ch, 1);
}
Info->CurBuffer[ Info->BufferWritePos ++ ] = ch;
Info->BufferUsed ++;
}
Info->CurBuffer[ Info->BufferWritePos ++ ] = ch;
Info->BufferUsed ++;
UCC
git Repository :: git.ucc.asn.au