Skip to content

Commit

Permalink
Fix #230: add input echo / editing / correction
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Nov 13, 2019
1 parent 54c3c05 commit 3585c16
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/CatenaBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Copyright notice:
#define CATENA_ARDUINO_PLATFORM_VERSION_CALC(major, minor, patch, local) \
(((major) << 24u) | ((minor) << 16u) | ((patch) << 8u) | (local))

#define CATENA_ARDUINO_PLATFORM_VERSION CATENA_ARDUINO_PLATFORM_VERSION_CALC(0, 17, 0, 30) /* v0.17.0.30 */
#define CATENA_ARDUINO_PLATFORM_VERSION CATENA_ARDUINO_PLATFORM_VERSION_CALC(0, 17, 0, 40) /* v0.17.0.40 */

#define CATENA_ARDUINO_PLATFORM_VERSION_GET_MAJOR(v) \
(((v) >> 24u) & 0xFFu)
Expand Down
94 changes: 79 additions & 15 deletions src/Catena_StreamLineCollector.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
/* Catena_StreamLineCollector.h Sat Mar 18 2017 15:15:53 tmm */

/*
Module: Catena_StreamLineCollector.h
Function:
McciCatena::cStreamLineCollector
Version:
V0.5.0 Sat Mar 18 2017 15:15:53 tmm Edit level 1
Copyright notice:
This file copyright (C) 2017 by
This file copyright (C) 2017, 2019 by
MCCI Corporation
3520 Krums Corners Road
Ithaca, NY 14850
An unpublished work. All rights reserved.
This file is proprietary information, and may not be disclosed or
copied without the prior permission of MCCI Corporation.
See accompanying license file.
Author:
Terry Moore, MCCI Corporation March 2017
Revision history:
0.5.0 Sat Mar 18 2017 15:15:53 tmm
Module created.
*/

#ifndef _CATENA_STREAMLINECOLLECTOR_H_ /* prevent multiple includes */
Expand All @@ -46,6 +36,7 @@ Revision history:
#endif

#include <cstdarg>
#include <Catena_limits.h>

// now, back to reality
#include "Stream.h"
Expand All @@ -60,6 +51,57 @@ namespace McciCatena {

class cStreamLineCollector : public cPollableObject
{
public:
using ColumnNumber_t = std::uint8_t;
static constexpr ColumnNumber_t kColumnMax = cNumericLimits<ColumnNumber_t>::numeric_limits_max();

protected:
class Columnator
{
private:
enum class EncodingState : std::uint8_t
{
Normal,
Esc1,
EscOsc,
CSI1,
CSI2,
UTF8,
Transparent,
};

public:
Columnator()
: m_column(0)
, m_state(EncodingState::Normal)
{}

ColumnNumber_t adjust(const char *pString);
void adjustColumn(std::uint8_t c, bool fEchoMode);
void reset(ColumnNumber_t col = 0)
{
this->m_column = col;
this->m_state = EncodingState::Normal;
}
ColumnNumber_t getColumn() const
{ return this->m_column; }
void setTransarent(bool fTransparent)
{
if (fTransparent)
{
this->m_state = EncodingState::Transparent;
}
else
{
this->reset();
}
}

private:
ColumnNumber_t m_column;
EncodingState m_state;
};

public:
cStreamLineCollector() {};
virtual ~cStreamLineCollector() {};
Expand All @@ -70,13 +112,22 @@ class cStreamLineCollector : public cPollableObject
cStreamLineCollector(const cStreamLineCollector&&) = delete;
cStreamLineCollector& operator=(const cStreamLineCollector&&) = delete;

enum : uint8_t
enum EditChars: std::uint8_t
{
kEol = '\n',
kCr = '\r'
kCr = '\r',
kLf = '\n',
kRetype = 'R' & 0x1f, /* ^R: retype */
kTab = '\t',
kSp = ' ',
kBackspace = 'H' & 0x1f,
kDel = 0x7F,
kEsc = '\e',
kCancel = 'U' & 0x1f, /* ^U: cancel */
kCaret = '^',
};

enum ErrorCode : uint32_t
enum ErrorCode: std::uint32_t
{
kSuccess = 0,
kOverrun = 1,
Expand Down Expand Up @@ -121,8 +172,18 @@ class cStreamLineCollector : public cPollableObject
size_t nBuffer // the buffer size
);

void putc(std::uint8_t c);
void vprintf(const char *pFmt, std::va_list ap);

protected:
void inputEdit(std::uint8_t c);
void doEcho(std::uint8_t c);
void doInput(std::uint8_t c);
void doInputCancel();
void doInputDelete();
void doInputRetype();
void realign(Columnator &t);

private:
// the stream we're working with
Stream *m_pStream = nullptr;
Expand All @@ -147,8 +208,11 @@ class cStreamLineCollector : public cPollableObject
{
return this->m_pReadCompleteCbFn != nullptr;
}
Columnator m_inputColumn;
Columnator m_outputColumn;
};


}; // namespace McciCatena

/**** end of Catena_StreamLineCollector.h ****/
Expand Down
Loading

0 comments on commit 3585c16

Please sign in to comment.