Open PropGit opened 8 years ago
I have some candidate code for this, but since I'm here, there is an opportunity to address #41 and possibly #42 here as well (which I have not done in the code below)
safe_gets.c:
/*
* Small modifications for using text_t interface by Steve Denson.
* Super-simple text I/O for PropGCC, stripped of all stdio overhead.
* Copyright (c) 2012, Ted Stefanik. Concept inspired by:
*
* very simple printf, adapted from one written by me [Eric Smith]
* for the MiNT OS long ago
* placed in the public domain
* - Eric Smith
* Propeller specific adaptations
* Copyright (c) 2011 Parallax, Inc.
* Written by Eric R. Smith, Total Spectrum Software Inc.
*
* MIT licensed (see terms at end of file)
*/
#include <ctype.h>
#include "simpletext.h"
static volatile char _textScanTerminalCharEchoing = 1;
void scanEchoDisable()
{
_textScanTerminalCharEchoing = 0;
}
void scanEchoEnable()
{
_textScanTerminalCharEchoing = 1;
}
char* _safe_gets(text_t *text, char* origBuf, int count)
{
char* buf = origBuf;
while (count-- > 0)
{
int ch = text->rxChar(text);
if (ch == 8 || ch == 127)
{
if (buf > origBuf)
{
if(_textScanTerminalCharEchoing)
{
text->txChar(text, '\010');
text->txChar(text, ' ');
text->txChar(text, '\010');
}
count += 1;
buf--;
}
count += 1;
continue;
}
if(_textScanTerminalCharEchoing)
{
text->txChar(text, ch);
if (ch == '\r')
text->txChar(text, '\n');
}
if (ch == '\r' || ch == '\n')
break;
*(buf++) = ch;
}
*buf = 0;
return (origBuf);
}
Regarding echoed characters as indicated by BlocklyProp's Issue #690, (Look for posts describing "An underlying function inside of getStr() is generating an echo"), we need to evaluate and fix this in Simple Libraries.