#include "CommonFramework.h"

// Funkcja odczytujaca napis z konsoli
void GetString( CConsoleBase *console, RBuf &buf )
	{
	_LIT( KFormatChar, "%c" );
	_LIT( KNewLine, "\n" );
	while( 1 )
		{
		TKeyCode key = console->Getch();
		if (key == EKeyEnter)
			{
			console->Printf( KNewLine );
			break;
			}			
		
		TChar ch = key;
		console->Printf( KFormatChar, ch );
		buf.Append( ch );
		}
	}

// Funkcja odczytuje ciag liczb z konsoli jako napis
void GetStringNumber( CConsoleBase *console, RBuf &buf )
	{
	_LIT( KFormatChar, "%c" );
	_LIT( KNewLine, "\n" );
	while( 1 )
		{
		TKeyCode key = console->Getch();
		if (key == EKeyEnter)
			{
			console->Printf( KNewLine );
			break;
			}			
		
		TChar ch = key;
		if ( ch < '0' || ch > '9' ) continue;
		console->Printf( KFormatChar, ch );
		buf.Append( ch );
		}
	}

// Przyklad
LOCAL_C void doExampleL()
    {
	_LIT(KHelloWorldText,"Hello world!\n");
	
	console->Printf(KHelloWorldText);
	
	RBuf buf;
	buf.Create( 100 );

	GetString( console, buf );	
	console->Printf( buf );
	console->Printf( _L("\n") );
	
	GetStringNumber( console, buf );	
	console->Printf( buf );
	console->Printf( _L("\n") );
	
	buf.Close();
	
	}

