#ifndef INPUTLINE_H
#define INPUTLINE_H

#ifndef INPUTLINE_LENGTH
#define INPUTLINE_LENGTH 80
#endif

#ifndef ANSI_back
#define ANSI_back "\b \b"	// back, overwrite with Space, back
#endif

#include "stdint.h"

/*
 * InputLine line;
 * void loop() {
 * 	line.Update();
 * 	if (line.isReady()) {
 * 		while (char c=line.nextChar()) {
 * 			Serial.print(c);
 * 		};
 * 	};
 * };
 * // 
 */

class InputLine {
	public:
		InputLine();		// constructor
		void Update();		// call often (read Serial)
					// when isReady return true, starts new line
		bool isReady();		// after enter (or full buffer)
					// if true, next Update reset line
		char nextChar();	// return next unreaded char or \0 at EOL, move forward
		char peekChar();	// return next unreaded char or \0 at EOL, no move
		void drop();		// drops line, start new one
		
		bool get_uint8_t(uint8_t &val);	// read uint8_t, success if at least 1 number and no number left
		bool echo;		// should echo typed chars? default=true
					// 
//	private:
		int charsReady;		// how much is collected so far
		char buff[INPUTLINE_LENGTH+1]; 	// buffer for chars+\0
		int atChar;		// nextChar = buff[atChar]; atChar++;
	private:
		bool dropLine;	// for Update
		bool ready;	// \r\n or overflow detected
};

/*
 * Alternative (peek before Enter pressed)
 * if (line.charsReady > 0) {
 * 	for (int i=0; i < line.charsReady; ++i) {
 * 		Serial.print(line.buff[i]);
 * 	};
 * 	line.drop();
 * };
 *
 * or even
 * if (line.charsReady > 0) {
 * 	Serial.print(line.buff);
 * 	line.drop();
 * };
 */
#endif
