set_input_error_handler(3)
π set_input_error_handler π
okay bestie, so this one lives in the gstream manual, section 3 (library calls, obviously), and it's all about what happens when your inputter catches someone being a menace. sit down, grab a strawberry π, let's go.
β¨ NAME β¨
set_input_error_handler β the little function that decides who gets yelled at when the user does something goofy π
β¨ SYNOPSIS β¨
#include <gstream.h>
void set_input_error_handler(int error);
β¨ DESCRIPTION β¨
okay so here's the vibe: this sets an error handler that gets called whenever the inputter encounters any unusual, erratic behaviour. like, the user trying to move the cursor off the string, or pressing invalid keys. that kind of chaos. π
and the handler gets passed a constant, which currently can be one of these:
IE_UNRECOGNIZED_KEYβ the key that got inputted couldn't be used for anything. like, it wasn't one of the recognized control keys (thinkKEY_LEFT, but notKEY_PGDN) and the input approver didn't accept it as a valid char either. so it's just... nothing. a void key. πIE_CURSOR_EXCEEDING_LIMITSβ the user tried to move the cursor off the input string. e.g. cursor is at the beginning of the string and they pressKEY_LEFTorKEY_HOME. also, heads up: pressingKEY_UPandKEY_DOWNcurrently returnsIE_CURSOR_EXCEEDING_LIMITSno matter where the cursor is. yes, no matter where. that's just how it is, periodt.IE_NO_ROOM_FOR_CHARβ there was no room for the inputted char. this one shows up a lot when the length of the input string has been limited to a certain maximum withset_max_input_length, but it can also happen if the buffer that the inputter puts the data in is full. lowkey that second one is not likely to happen unless you, for instance, force the gstream to use your own buffer, because the standard buffer is rather large. it's chunky. it's fine. π«Ά
note that these constants are defined in'gbuf', so you have to putgbuf::in front of them. no skipping, bestie.
and here's what that looks like in real life:
int stupid_mistakes = 0;
void ieh_for_my_number_inputter(int e)
{
switch (e) {
case gbuf::IE_UNRECOGNIZED_KEY: // note: gbuf::
if (stupid_mistakes > MUST_BE_BRAIN_DEAD) {
say_to_user("Sorry, you can only input numbers!");
user_characteristics = FOOL;
stupid_mistakes = 0;
}
else
++stupid_mistakes;
break;
case gbuf::IE_NO_ROOM_FOR_CHAR:
play_quiet_beep();
break;
} // in all other situations: do nothing
}
now, super important thing to understand: the inputter automatically takes care of any problems encountered and solves them with much elegance. often simply by ignoring the user if the result of the action would be illegal. so your error handler doesn't really deal with the problem or handle the situation β it is merely a way for you to warn or tell the user that he is doing something wrong. you're not the fixer, you're the notifier. main character energy in a supporting role, iykyk. π
πΈ some advice about style πΈ
this part is advice, and no cap, you don't have to follow it. you are free to have your own opinion, and these are general, so they might not fit your particular situation. but please at least read them through before you begin designing your own error handler. like, at least skim. for me. π₯Ί
- often the best thing to do is not to do anything. for example, simply ignoring that the user is pressing an unrecognized key is often better than complaining, unless you have a specific reason for warning him β in the example above, the user should be aware that he was supposed to enter a number.
- if you decide to do something, remember the KISS principle: keep it simple. if you as a user have made a mistake, you're probably already irritated because of that, and then it doesn't help the situation that you have to watch the screen go beserk (or hear an entire symphony) before you can continue. π
- if you play a sound, such as a beep, make it a short, quiet one. personally I can't stand a hysterical
"BEEEEEEEEEP"if I accidentally hit the wrong key. - generally don't use large special effects. if you have invented a new kind of plasma generator, you're probably better off releasing a demo that shows it, instead of making your users annoyed by forcing them to look at it everytime they make the slightest fault. let the plasma generator be its own moment. β¨
- if you display a message, consider implementing a system like in the example above where the user is given a few tries before the message is displayed, to ensure it is only (or mostly) sent to newbies. if the example should be perfect, it would even reset the mistake counter now and then. we love a forgiving queen. π
- at last, a practical advice: keep in mind that future versions of gstream may have more error codes added, so design the function in a way that it won't break as soon as that happens (e.g. don't count on that if you test for the first constants, then the remaining has to be the last). future-proofing is self-care. π
π¦ the typedef π¦
there is a typedef, 'input_error_handler', in 'gbuf' for the type of a pointer to a handler function:
gbuf::input_error_handler tmp_ieh;
//...
tmp_ieh = gs1.get_input_error_handler();
gs1.set_input_error_handler(gs2.get_input_error_handler());
gs2.set_input_error_handler(tmp_ieh);
look at that little swap dance. iconic. π
the default input error handler is 'ieh_never_complain'.
β¨ SEE ALSO β¨
gstream-get_input_error_handler(3)gstream-set_input_approver(3)gstream-set_max_input_length(3)gstream-ieh_never_complain(3)
and that's the whole page, bestie π«Ά this was the gstream manual, version 1.6, dated set_input_error_handler(3) β go forth and handle your errors with grace and a quiet beep. slay. ππβ
π¦ where this page comes from
- fedora 43: gstream-devel 1.6-35.fc43 Β· Giftware
- fedora 43: gstream-devel 1.6-35.fc43 Β· Giftware
- fedora 44: gstream-devel 1.6-36.fc44 Β· Giftware
- fedora 44: gstream-devel 1.6-36.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms