When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
210 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
This code is all sorts of wrong, I don't even know where to begin.
what's wrong
begin which is the most important
yeah so the code just repeats itself the input given in release mode but when I debug it works fine, I've tried hours for it to show that case
but I am sure that the problem arises in this function
by what I have done unit now
by all that printing stuff onto the terminal
ofc its a loop its meant to repeat itself. Maybe you should aid us with some output visuals
nah man that's not what I meant
it
it's a loop to read input
Ok
First of all, where is NoOfCharType defined? The function certainly doesn't initialize it. Secondly, what's this ReadKey()? The name is descriptive but it's not standard C and I don't know why you're using anything other than standard C for this case. Third, that's not the range of visible characters, if you use a weird locale that might not apply. Why are your newlines terminated in an \r, are you redirecting your shell's output to a file you intend to read on Windows? Why are you using EXIT_FAILURE and EXIT_SUCCESS which are for the process error codes? Why do you have a random semicolon in the code? Why are you using braces for cases? Why are you using a switch statement at all since all you are doing is the equivalent of an if statement? Why are you printing error messages inside the input function? So many questions.
Why is a function called ReadInput printing stuff?
man shall I give you my entire git repo
this is not my whole code
But it's poorly written and I am telling you these are all problems.
ReadInput is printing stuff because it is in raw mode
to give it an illusion of it being in normal mode
so that I could do terminal stuff
It doesn't matter, ReadInput is printing a prompt and interpreting input. It's not reading input.
I am making a shell
I understand what you are making.
so what's the problem
what do you want, user typing on a blank canvas
And that is what ReadInput means? Why didn't you name it DrawCircles?
That's not what you are doing.
do you know how does a shell operates
Anyway, first of all, to actually read your prompt, you only need to fgets() into a string.
Yes I do.
then you should know what I am doing
ReadInput is a name that is not at all what you are doing. The name makes no sense.
you know what rawmode means atleast right?
do you?
you absolutely don't know shi!
it's a terminal
ofc
how does shell give you the history you typed in when you pressed the up arrow key
you need to enter the raw mode to do that
I have made one without a raw mode
That's a shell feature, not a terminal feature.
yup
how does it do that
that's my question
explain
how does shell know you pressed the arrow up key without pressing enter
Mr smart you are wrong
absolutely
you either don't understand what I am saying or you don't know your stuff right
I understand what you are saying, you just don't understand what you are saying is nonsense. And if you stop it with the attitude I could potentially explain it to you.
You have a bad mental image of how it works and there are many things wrong with how you structured the code as well.
So, shall I continue?
"I can debate to 50 scholars,
but to an ignorant, I admit defeat"
-Shafi
what I am saying is escape sequences doesn't give you the input
you cannot get that feature without entering the raw mode
What does this have to do with anything I've said?
what is this
this is exactly what I am replying to
Actually make that feature
without endering the raw mode
the feature to get your history inside a shell
by clicking the up arrow key
Yes. You press your little up arrow, the terminal (which takes in input from the keyboard) then passes an escape code down to your process (the shell) via stdin.
nope
You use the word shell and terminal interchangeably, why are you contradicting?
you are changing the topic
make it
and dm me
I would be available
I haven't
you probably have misunderstood
@ivory sentinel
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
Now, can I explain why your code is utter trash and looks like it was written by an idiot?
Because it is absolutely horrid in so many ways.
!f
You would get the up error doing something like this:
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
void enable_raw_mode(struct termios* orig_termios) {
tcgetattr(STDIN_FILENO, orig_termios);
struct termios raw = *orig_termios;
raw.c_lflag &= ~(ECHO | ICANON);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
}
void disable_raw_mode(struct termios* orig_termios) {
tcsetattr(STDIN_FILENO, TCSAFLUSH, orig_termios);
}
int main() {
struct termios orig_termios;
enable_raw_mode(&orig_termios);
puts("Press keys (press 'q' to quit)...");
while (true) {
char c;
if (read(STDIN_FILENO, &c, 1) == 1) {
if (c == '\x1b') {
char seq[2];
if (read(STDIN_FILENO, &seq[0], 1) == 1 &&
read(STDIN_FILENO, &seq[1], 1) == 1) {
if (seq[0] == '[' && seq[1] == 'A') {
printf("Up arrow detected!\n");
// Fetch previous command from history
}
}
} else if (c == 'q') {
break;
} else {
printf("You pressed: %c\n", c);
}
}
}
disable_raw_mode(&orig_termios);
return 0;
}
Actually you're too entitled and arrogant to deserve real help.
it doesn't give me an error but a runtime bug
you cannot solve my problem but just yaps around thinking he is god like a maniac
I was having a bad day today
you made it worse
thank you
Of course I can but I cannot communicate with you if all you do is argue about how you know everything when you're here asking trivial things but are unwilling to listen and instead piss on those who know better? If you knew better you wouldn't be asking for help.
You may think you know better but if you're not even willing to listen then what is my role here?
like if you say things that doens't make sense how can I
why are you not taking up the challenge
make it
once
Well if something doesn't make sense we can discuss it until it does make sense.
can't you
I did make what you asked, I'm not implementing a whole shell for you.
give me your repo
My repo of what?
My git repo of the shell you're working on? What are you on about?
you said you have made a shell right?
the git repository of that
I didn't say anything about anything I made.
what is this
then
I'm sorry but excuse me
Yes, the code above does what you asked, which was how to detect the damn key in raw mode. As for the shell itself...
that's not what I said
I have made a whole text editor
if you know
Am I supposed to clap?
did I say
I just said I know how to operate in raw
mode
Why are you telling me about a text editor?
I shown you an example that I could work in raw mode
You should probably use X/Curses as a standard API instead of duplicating standard functionality by getting escape code from the terminal. It handles windows and all sorts of things.
For the text editor, that is.
I don't need to but I did
used termios
and it is better to use termios as xcurses doesn't give that control by the mebers of this server
Termios is POSIX, I was talking about X/Curses, which is what somethim like Vim, maybe nano, Emacs, etc. would use.
Control?
Idk what you are talking about.
yeah I used that
BTW
can you just
make it
that feature to detect a up arrow
without endering the raw mode
make it
I am not telling you to make an entire shell
make it and then tag me dm me whatever
Backspace for what? Deleting characters?
sorry up arrow
without endering the raw mode
and pressing enter
You can't detect the up arrow accept after finishing input if you don't enter raw mode.
This has nothing to do with my complaint that ReadInput() wasn't doing what it claimed to do.
what the hell is this msg
then
That is the underlying mechanism. Since you asked me if I knew how it worked.
how do you implement this
you have to enter the raw mode to do that
otherwise prove to me
CAN YOU PROVE IT
yes or no
Did you read this line here? And did you see the code I provided?
So why the hell are you on about raw mode?
I have no idea why you even mentioned it.
this code enters the raw mode
that's the shit I said for this long time
you cannot make that feature without entering the raw mode
CAn you make it
But you said it with no context and later started demaning code that doesn't use raw mode for reasons that are beyond me.
Why are you trying to do it in canonical mode? You can't.
I said with the context
how do you implement that feature without entering the raw mode
Yes. And why did you ask that? What is wrong with raw mode?
Raw mode is what you should be using.
what is this and the messages I forward
You asking a question that you probably already knew the answer to and which had nothing to do with my complaints. So I don't even know why we're even talking about raw mode.
Or half-knew cause idk what you thought the interaction between terminals and shells was or whether they were the same.
I had asked you properly
how do you implement it
without entering the raw
mode
you didn't answer me
and assumed something else
that's not my problem
okay
And I said several times that you cannot. I repeatedly said it. I'll even quote all the lines.
so all of this was a misunderstanding
I was talking about something else and you were so great at listening you started shouting at me asking whether I knew about raw mode.
I have made it clear
I had made it clear and you were just too passionate on shouting on others
that's not my mistake
and btw
I was already having a bad day
now with this it's just
huh
whatever
I'm having a f*cking headache
I would look into this code when I am fresh tomorrow
bye
@ivory sentinel Has your question been resolved? If so, type !solved :)
nah bot
@ivory sentinel seems it got heated pretty quick for no apparent reason as far as i can tell. i'm unable to understand what the problem you're having (it seem you deleted some posts, which isn't a good thing to do if you expecting help). in any case - since there's a snippet up there, based on that one could do
/* --- snip --- */
int enable_raw_mode(struct termios *orig_termios) {
/* --- snip --- */
}
int disable_raw_mode(struct termios *orig_termios) {
/* --- snip --- */
}
void check_arrows(char *buf, size_t size) {
if (size != 3) { return; }
uint32_t val = 0;
for (size_t i = 0; i < size; i++) { val |= buf[i] << (size - i - 1) * 8; }
// 1B 5B the first 2 chars in an arrow sequence
if (val >> 8 != 0x1b5b) { return; }
switch (val & 0xff) {
case 'A':
...
break;
case 'B':
...
break;
case 'C':
...
break;
case 'D':
...
break;
default:
break;
}
}
void print_buf(char *buf, size_t size) {
printf(">>> ");
for (size_t i = 0; i < size; i++) { printf("%c ", buf[i]); }
printf("\n");
}
int main(void) {
struct termios orig_termios;
if (enable_raw_mode(&orig_termios) == -1) {
perror("raw");
return 1;
}
puts("Press keys (press 'q' to quit)...");
while (true) {
enum {
SIZE = 128,
};
char buf[SIZE];
ssize_t ret = read(STDIN_FILENO, buf, sizeof buf);
if (ret == -1) {
perror("read");
goto cleanup;
}
if (*buf == 'q') { break; }
check_arrows(buf, (size_t)ret);
print_buf(buf, (size_t)ret);
}
cleanup:
(void)disable_raw_mode(&orig_termios);
}```
reading anything other than arrows is then becoming trivial. one can simply append the read char/chars into an array up until some specific char (a `'\n'` for example)
Lol
I haven't deleted any done lol
I was having a bad day and it was getting late already so when the argument kinda stopped I just deleted the entire complaint (because I had poted it on cpp-help before accidently and I was having my problem solved there) to not have any more arguments lol
the problem I was having is in the original message, or it is also in the cpp-help (yeah I accidently put in inside cpp-help the first time)
!solved