Text Editor E01 - How to use ANSI Escape Codes & Call Native APIs with Java

Поділитися
Вставка
  • Опубліковано 14 січ 2025

КОМЕНТАРІ • 66

  • @fmueller
    @fmueller 2 роки тому +16

    Please continue with that series! It's great.

    • @MarcoCodes
      @MarcoCodes  2 роки тому +4

      Second video is already in production, an frankly, it's going to be awesome ;)

  • @amirshelli
    @amirshelli 6 місяців тому +1

    It's actually so useful that you instruct on how could the viewer find things themselves! Thank you for the series!

    • @amirshelli
      @amirshelli 6 місяців тому

      @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?

  • @tmsngr
    @tmsngr 2 роки тому +2

    What I really like about this video (I don't yet know your others) is your dense presentation of information.

  • @aixo81
    @aixo81 Рік тому +1

    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.

  • @KolosBros
    @KolosBros 2 роки тому +5

    oh my god, this is awesome! This is an awesome way to actually learn a whole bunch of new stuff

  • @ShivaniSingh-sf3mv
    @ShivaniSingh-sf3mv Рік тому

    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

    • @MarcoCodes
      @MarcoCodes  Рік тому

      Thank you for the nice words! Will do!

  • @ayuobmousa6589
    @ayuobmousa6589 2 роки тому +1

    oh my this came in the perfect time.

  • @JanWillemKeizer
    @JanWillemKeizer 2 роки тому

    Thank you for the shout-out!
    Cheers from an enterprise programmer ;-)

  • @sixpooltube
    @sixpooltube Рік тому

    Incredible tutorial. Subscribed.

  • @tiziano6311
    @tiziano6311 2 роки тому

    Great video, thank you for the content!

  • @jeffreymiller4090
    @jeffreymiller4090 2 роки тому +1

    Hi Marco, great tutorial! Just curious how your 'java' command is compiling and running Viewer.java?

    • @MarcoCodes
      @MarcoCodes  2 роки тому +1

      Hey Jeffrey,
      since Java 11 (I think), the 'java' command does this automatically for you.

  • @warnerjanveldhuis341
    @warnerjanveldhuis341 2 роки тому

    Casually has a book called Shit! in the background :) Nice video, good explanation. Subscribed!

    • @MarcoCodes
      @MarcoCodes  2 роки тому

      Hadn't even noticed that myself, haha :)

    • @marin1419
      @marin1419 9 місяців тому

      is that a language?

  • @udhayasankar113
    @udhayasankar113 2 роки тому +1

    Pls make a video on complete spring batch

    • @MarcoCodes
      @MarcoCodes  2 роки тому

      Unfortunately no time for that atm.

  • @alitekin7568
    @alitekin7568 2 роки тому

    great content. thanks a lot.

  • @mmatteii
    @mmatteii 2 роки тому

    Great stuff man.
    Can we call ncurse lib with jna? or is it a different thing from termios?

  • @Mr-domenic
    @Mr-domenic Рік тому +2

    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

    • @MarcoCodes
      @MarcoCodes  Рік тому

      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.

    • @Mr-domenic
      @Mr-domenic Рік тому

      ​@@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
      @MarcoCodes  Рік тому

      Interesting! Which Linux are you on btw?

    • @Mr-domenic
      @Mr-domenic Рік тому

      ​​@@MarcoCodesI'm using WSL2, running Ubuntu 20.04 on windows.
      OpenJDK version 11

    • @Mr-domenic
      @Mr-domenic Рік тому

      @@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 🤣

  • @iliachakarov7285
    @iliachakarov7285 Рік тому

    MARCO U A G!!!

  • @SLTRM
    @SLTRM 2 роки тому

    Thanks. Very informative video. Is posible compile this project using graalvm/native-image and still work?

    • @MarcoCodes
      @MarcoCodes  2 роки тому

      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.

  • @hue.huehuehue
    @hue.huehuehue Рік тому

    There was a problem calling tcgetattr is printed and i get return value as -1, how do i go about debugging it?

    • @MarcoCodes
      @MarcoCodes  Рік тому +1

      Which operating system are you on? Have you checked out any of he other comments regarding tcgetattr?

    • @hue.huehuehue
      @hue.huehuehue Рік тому

      @@MarcoCodes hey thanks for the reply, i later found through comments you instructed someone to run directly from terminal, not IDE and that worked. :)

    • @hue.huehuehue
      @hue.huehuehue Рік тому

      @@MarcoCodes I am using ubuntu 22 for reference .

  • @TomasZubrietovsky
    @TomasZubrietovsky Рік тому

    Hi, is there some way how to run it on windows?

    • @MarcoCodes
      @MarcoCodes  Рік тому +1

      Yes! Windows & macOS support was added in the third episode here:
      ua-cam.com/video/72Dt_U9DQh4/v-deo.html

  • @Tom_van_Gorkom
    @Tom_van_Gorkom Рік тому

    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?

    • @MarcoCodes
      @MarcoCodes  Рік тому

      Hi Tom, what exception/error Codes are you getting?

    • @MarcoCodes
      @MarcoCodes  Рік тому +1

      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.

    • @Tom_van_Gorkom
      @Tom_van_Gorkom Рік тому

      @@MarcoCodes error code 255

  • @ASHWINNAMBIARM
    @ASHWINNAMBIARM 2 роки тому

    Native.load() returned value 255. Can you tell me why?

    • @MarcoCodes
      @MarcoCodes  2 роки тому

      Hey, what operating system are you on?

    • @ASHWINNAMBIARM
      @ASHWINNAMBIARM 9 місяців тому

      @@MarcoCodes sorry for the delay, it was Ubuntu OS

  • @cdhagen
    @cdhagen Рік тому

    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. 🙈

    • @MarcoCodes
      @MarcoCodes  Рік тому

      What error Code do you get from the syscall?

  • @mkhadka123
    @mkhadka123 Рік тому

    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.

  • @marcobehler1395
    @marcobehler1395 2 роки тому +2

    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 .

  • @hue.huehuehue
    @hue.huehuehue Рік тому

    The github repository has no source code to copy from...

    • @MarcoCodes
      @MarcoCodes  Рік тому +1

      Check out the branches of that repository.

    • @hue.huehuehue
      @hue.huehuehue Рік тому

      @@MarcoCodes Got it, thanks :)

  • @outscope23
    @outscope23 2 роки тому

    I get return code 255 when calling LibC.INSTANCE.tcgetattr(0, termios). Any idea what causes this problem on MacOS?

    • @ashajjar
      @ashajjar 2 роки тому +1

      me too .. on linux Manjaro, I get this error. I thought because I am trying it in Kotlin

    • @ashajjar
      @ashajjar 2 роки тому +1

      wait ... it turned out that IntilliJ does not like the code ... if I run in the terminal directly it works :D

    • @MarcoCodes
      @MarcoCodes  2 роки тому +1

      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.

    • @MarcoCodes
      @MarcoCodes  2 роки тому +1

      Yay, glad you figured it out! Yes, you have to go through a real terminal.

    • @ashajjar
      @ashajjar 2 роки тому

      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 😅