I made a console formatting (color, cursor position) object

Started by
11 comments, last by silverphyre673 19 years, 1 month ago
Yeah... for those of you (and I know there is a lot of you) who want to be able to use color, position the cursor, or get user input without displaying what the user typed (or overwrite it with '*' like a password), and are using Windows (for now), I made this file. You can get it from the coding download section of my site at home.comcast.net/~silverphyre673/index.html Please let me know what you think. You can use it for anything you like, and, as the tutorial says, it is only version 0.5 (write and read functions need a bit of work). Please read the tutorial before asking questions, but ANY improvements will be really welcome. Thanks for trying it out - let me know what you think! Hey Drew! :D Yay Composer. Quick fix. Anyways, I've been overloading the read/write function, but left SetWrite and MoveWrite templated so they now just call Write on whatever is passed to them, which I think should work. So... question: If Read() takes a char* that is supposed to be read into (it doesn't return the read value, it puts it into readObj), do I just use Read(char* buffer) or Read(char* &buffer) <-- Seems ugly to me! Thanks, guys! [Edited by - silverphyre673 on March 14, 2005 11:07:26 PM]
my siteGenius is 1% inspiration and 99% perspiration
Advertisement
To make your links clickable, use <a href="url goes here">link text goes here</a>
(you've also gotta make sure that there's an http:// in there or the link will end up pointing somewhere on these forums)
e.g. Your website

p.s. please don't [repost] the same thing in multiple forum sections.
Accident. I thought it didn't post, and my browser started freezing, so I closed it, then accidentaly posted on the other forum. yeah. But please try it out.
my siteGenius is 1% inspiration and 99% perspiration
Looks interesting. I'm not sure why you have templated many of the functions though, especially when you are using strlen() on that template object in one part of your code.
So you think I should just overload the Write function for char*, char and std::string, or what?
my siteGenius is 1% inspiration and 99% perspiration
Haven't look at your code yet, but I do appreciate the web page change. That last one got me kind of depressed when I looked at the game of life [lol]
Actually, and I guess I should update the readme about this, but I could use some help with the Read functions...

In case you didn't see (I modified the original post, so you might have missed it)

Hey Drew! :D Yay Composer. Quick fix. Anyways, I've been overloading the read/write function, but left SetWrite and MoveWrite templated so they now just call Write on whatever is passed to them, which I think should work. So... question: If Read() takes a char* that is supposed to be read into (it doesn't return the read value, it puts it into readObj), do I just use

Read(char* buffer)

or

Read(char* &buffer) <-- Seems ugly to me!

Thanks, guys!

Also, the Read(std::string, unsigned length) function is being crappy and appends random characters to the end of my strings. Could someone show me why, maybe? Thanks!
my siteGenius is 1% inspiration and 99% perspiration
You should use Read(char *buffer) since you arent changing where the pointer points to.

Also, I do not believe that ReadConsole() will add the null terminator to your string. You should use the return value to put the null terminator into your buffer.
Quote:
Also, I do not believe that ReadConsole() will add the null terminator to your string. You should use the return value to put the null terminator into your buffer.


How would this look? Here is the function now:

bool Console::Read( char * readObj, unsigned length ){    DWORD read=0;    if ( !ReadConsole(input_handle, readObj, length, &read, NULL) )        return false;    readObj[strlen(readObj)+1]='\0';    return true;}


But this doesn't seem to work.
my siteGenius is 1% inspiration and 99% perspiration
I've never used ReadConsole before, but doesn't strlen() just return the position of the first null terminator? So you're going to need another way of determining the length.

EDIT: Just noticed...that'd be the variable "read" :)

This topic is closed to new replies.

Advertisement