@MarcoCodes although I found out I'm having an issue entering raw mode. I'm on macOS v14.5 (M1)... I noticed I get different numbers initially, even after changing the flag type to long. Here is what I get Termios: Termios{c_iflag=27138, c_oflag=2, c_cflag=19200, c_lflag=536872392, c_cc=[4, -1, -1, 127, 23, 21, 18, -1, 3, 28, 26, 25, 17, 19, 22, 15, 1, 0, 20]} Raw Mode Enabled Termios: Termios{c_iflag=26626, c_oflag=2, c_cflag=19200, c_lflag=536871232, c_cc=[4, -1, -1, 127, 23, 21, 18, -1, 3, 28, 26, 25, 17, 19, 22, 15, 1, 0, 20]} -> in this case when I write something I only see the keys after pressing ctrl+j If I put the numbers you had for the flags manually, it does enter raw mode... Is there a way I could fix this?
Thank you so much!!! I wanted to code something like an editor and I didn't know where to start from. Your code guided me until the first half of your second video and now I got enough to continue with my development. I'm making a kind of REST call maker (like postman) in console and I wanted this to be user interactive. I'm glad to have met you.
Hey Marco Huge fan, Please make more of these tutorial video. Really helps to break mundane task from work. Thank you so much. You are awesome programmer
Record a problem I encountered in case others will too: cc_t c_cc[NCCS] The length of c_cc is different in different operating system! The length is 20 in MacOS and 32 in Linux If someone encounter `free(): invalid pointer` when executing, change the length of c_cc can fix
Thanks for posting it! Yes, I fixed the array length in Episode 3 for macOS (and a couple other things to make it work flawlessly), but thinking back now, it maybe should have been here in the first episode already.
@@MarcoCodes Thanks for your reply! However, I have watched episode 3 and added Windows/MacOS/Unix support in my code I tested on windows11 and wsl, and found that there's still a problem in Unix support First, I encounter: free(): invalid pointer I changed the length of c_cc to 32 Then, execute successfully! But I can't anymore after the first execution with error message: munmap_chunk(): invalid pointer I can't find solutions on line, do you have some ideas?
@@MarcoCodes I test the code on CentOS 7 running on VMWare Still can't work Error message: *** Error in `java': malloc(): memory corruption (fast): 0x00007fcda85153e0 *** In my opinion, it may caused by some specific parameter value that is different between different Linux distributions. We have to gone through the boring documents and find out the value Now I know how painful it is to adapt software to different OSs 🤣
Unfortunately not. That's because of JNA not working nicely together with graalvm/native-image. Using JNI as an alternative might work, but I haven't explored that yet.
@@MarcoCodes hey thanks for the reply, i later found through comments you instructed someone to run directly from terminal, not IDE and that worked. :)
Ah, Tom btw, I completely forgot. In episode 3 we actually make the thing work on MacOS, it is a matter of replacing a couple of constants. You might want to check out that episode.
Did anyone get this to work with MacOS (Intel, not M1)? I have watched the addendum in Part 03, but it still does not work. No error message, but the terminal just won't go into "raw" mode. It's a shame, seems like an interesting project, but this bit-fiddling is not for me. 🙈
After executing the command the first @15:20, I do not get the values as you are, instead I get something like "free(): invalid pointer Aborted" ---> I have the exact same code as you until that point, what is going on there? A little help please :) **edit It works now. I updated my jdk (OpenJDk 11 to 18) after seeing comment of @Carlos below.
For anyone having issues following along with macOS: There are two tiny changes you need to make to the Viewer class to make it work under macOS, which I cover in the 3rd part of this series: ua-cam.com/video/72Dt_U9DQh4/v-deo.html .
If you are getting the error with tcgetattr(), it might very likely be that you are trying to run the code directly from the IDE, which will not wor,k. Could you try through the terminal? If you are getting the error with the ioctl() call, it's because of the wrong constant value for macOS, see the pinned comment.
It would have been great though to be able to run it in IDE because you could use debugging features .. luckily i didn’t need it so far but I am sure i will and then it will be the time when i will look for how to make “intillij run” act like a real terminal 😅
Please continue with that series! It's great.
Second video is already in production, an frankly, it's going to be awesome ;)
It's actually so useful that you instruct on how could the viewer find things themselves! Thank you for the series!
@MarcoCodes although I found out I'm having an issue entering raw mode. I'm on macOS v14.5 (M1)...
I noticed I get different numbers initially, even after changing the flag type to long.
Here is what I get
Termios: Termios{c_iflag=27138, c_oflag=2, c_cflag=19200, c_lflag=536872392, c_cc=[4, -1, -1, 127, 23, 21, 18, -1, 3, 28, 26, 25, 17, 19, 22, 15, 1, 0, 20]}
Raw Mode Enabled
Termios: Termios{c_iflag=26626, c_oflag=2, c_cflag=19200, c_lflag=536871232, c_cc=[4, -1, -1, 127, 23, 21, 18, -1, 3, 28, 26, 25, 17, 19, 22, 15, 1, 0, 20]}
-> in this case when I write something I only see the keys after pressing ctrl+j
If I put the numbers you had for the flags manually, it does enter raw mode... Is there a way I could fix this?
What I really like about this video (I don't yet know your others) is your dense presentation of information.
Thank you so much!!!
I wanted to code something like an editor and I didn't know where to start from.
Your code guided me until the first half of your second video and now I got enough to continue with my development.
I'm making a kind of REST call maker (like postman) in console and I wanted this to be user interactive.
I'm glad to have met you.
Cool idea! Good luck with it!
oh my god, this is awesome! This is an awesome way to actually learn a whole bunch of new stuff
Glad you like it!
Hey Marco Huge fan, Please make more of these tutorial video. Really helps to break mundane task from work. Thank you so much. You are awesome programmer
Thank you for the nice words! Will do!
oh my this came in the perfect time.
Thank you for the shout-out!
Cheers from an enterprise programmer ;-)
Cheers!
Incredible tutorial. Subscribed.
Great video, thank you for the content!
Hi Marco, great tutorial! Just curious how your 'java' command is compiling and running Viewer.java?
Hey Jeffrey,
since Java 11 (I think), the 'java' command does this automatically for you.
Casually has a book called Shit! in the background :) Nice video, good explanation. Subscribed!
Hadn't even noticed that myself, haha :)
is that a language?
Pls make a video on complete spring batch
Unfortunately no time for that atm.
great content. thanks a lot.
Great stuff man.
Can we call ncurse lib with jna? or is it a different thing from termios?
Sure, that'll work!
Record a problem I encountered in case others will too:
cc_t c_cc[NCCS]
The length of c_cc is different in different operating system!
The length is 20 in MacOS and 32 in Linux
If someone encounter `free(): invalid pointer` when executing, change the length of c_cc can fix
Thanks for posting it! Yes, I fixed the array length in Episode 3 for macOS (and a couple other things to make it work flawlessly), but thinking back now, it maybe should have been here in the first episode already.
@@MarcoCodes Thanks for your reply!
However,
I have watched episode 3 and added Windows/MacOS/Unix support in my code
I tested on windows11 and wsl, and found that there's still a problem in Unix support
First, I encounter: free(): invalid pointer
I changed the length of c_cc to 32
Then, execute successfully!
But I can't anymore after the first execution with error message: munmap_chunk(): invalid pointer
I can't find solutions on line, do you have some ideas?
Interesting! Which Linux are you on btw?
@@MarcoCodesI'm using WSL2, running Ubuntu 20.04 on windows.
OpenJDK version 11
@@MarcoCodes I test the code on CentOS 7 running on VMWare
Still can't work
Error message:
*** Error in `java': malloc(): memory corruption (fast): 0x00007fcda85153e0 ***
In my opinion, it may caused by some specific parameter value that is different between different Linux distributions.
We have to gone through the boring documents and find out the value
Now I know how painful it is to adapt software to different OSs 🤣
MARCO U A G!!!
Thanks. Very informative video. Is posible compile this project using graalvm/native-image and still work?
Unfortunately not. That's because of JNA not working nicely together with graalvm/native-image. Using JNI as an alternative might work, but I haven't explored that yet.
There was a problem calling tcgetattr is printed and i get return value as -1, how do i go about debugging it?
Which operating system are you on? Have you checked out any of he other comments regarding tcgetattr?
@@MarcoCodes hey thanks for the reply, i later found through comments you instructed someone to run directly from terminal, not IDE and that worked. :)
@@MarcoCodes I am using ubuntu 22 for reference .
Hi, is there some way how to run it on windows?
Yes! Windows & macOS support was added in the third episode here:
ua-cam.com/video/72Dt_U9DQh4/v-deo.html
I am working on a macbook pro with M1 processor. I cannot get the jna to work. Does somebody know how to get it to work?
Hi Tom, what exception/error Codes are you getting?
Ah, Tom btw, I completely forgot. In episode 3 we actually make the thing work on MacOS, it is a matter of replacing a couple of constants. You might want to check out that episode.
@@MarcoCodes error code 255
Native.load() returned value 255. Can you tell me why?
Hey, what operating system are you on?
@@MarcoCodes sorry for the delay, it was Ubuntu OS
Did anyone get this to work with MacOS (Intel, not M1)? I have watched the addendum in Part 03, but it still does not work. No error message, but the terminal just won't go into "raw" mode. It's a shame, seems like an interesting project, but this bit-fiddling is not for me. 🙈
What error Code do you get from the syscall?
After executing the command the first @15:20, I do not get the values as you are, instead I get something like "free(): invalid pointer
Aborted" ---> I have the exact same code as you until that point, what is going on there? A little help please :)
**edit
It works now. I updated my jdk (OpenJDk 11 to 18) after seeing comment of @Carlos below.
For anyone having issues following along with macOS: There are two tiny changes you need to make to the Viewer class to make it work under macOS, which I cover in the 3rd part of this series: ua-cam.com/video/72Dt_U9DQh4/v-deo.html .
The github repository has no source code to copy from...
Check out the branches of that repository.
@@MarcoCodes Got it, thanks :)
I get return code 255 when calling LibC.INSTANCE.tcgetattr(0, termios). Any idea what causes this problem on MacOS?
me too .. on linux Manjaro, I get this error. I thought because I am trying it in Kotlin
wait ... it turned out that IntilliJ does not like the code ... if I run in the terminal directly it works :D
If you are getting the error with tcgetattr(), it might very likely be that you are trying to run the code directly from the IDE, which will not wor,k. Could you try through the terminal? If you are getting the error with the ioctl() call, it's because of the wrong constant value for macOS, see the pinned comment.
Yay, glad you figured it out! Yes, you have to go through a real terminal.
It would have been great though to be able to run it in IDE because you could use debugging features .. luckily i didn’t need it so far but I am sure i will and then it will be the time when i will look for how to make “intillij run” act like a real terminal 😅