How do I make multiple concurrent progress bars in the terminal? (tutorial in C)

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 72

  • @kyleherrity8443
    @kyleherrity8443 3 года назад +18

    I used to program exclusively in C. Now I program primarily in C++. Your videos make me wax nostalgic about my past. I miss the purity and simplicity of C! Great videos.

    • @kayakMike1000
      @kayakMike1000 3 года назад

      C seems pure because it is so much more simple, I am sure your C++ code is pure also.

  • @marcosfons
    @marcosfons 3 года назад +34

    I was always in doubt about how it was done, but I had never really researched it. What a nice video to watch, thank you

  • @fburton8
    @fburton8 3 года назад +7

    Back in the day (late 1970s) I knew most of the VT52 and VT100 escape codes off by heart when I wrote a 'visual' text editor for use on our PDP-11 terminals. Better than using TECO and later EDT for writing code anyway.

  • @kayakMike1000
    @kayakMike1000 3 года назад +2

    Damn dude, you're a fantastic software engineer.

  • @nomadic-insomniac
    @nomadic-insomniac 3 года назад +4

    Awesome , I've been coding in C for a couple of years now and I still learn something new whenever I visit your channel.
    Keep up the good work.
    Stay safe.

    • @JacobSorber
      @JacobSorber  3 года назад

      Thanks! Hopefully, we'll keep learning new things together.

  • @massimilianogilli1164
    @massimilianogilli1164 3 года назад +21

    mind doing a video on event-driven model?

    • @joseortiz_io
      @joseortiz_io 3 года назад +1

      I would love to see this as well!

    • @JacobSorber
      @JacobSorber  3 года назад +17

      Yeah, it's been on my list for a while. For some reason, some ideas take more fiddling than others. It'll show up one of these weeks.

    • @joseortiz_io
      @joseortiz_io 3 года назад

      @@JacobSorber Yeah I'd definitely love to see this. I've been working on a microservice architecture and one issue I'm dealing with is implementing CQRS for updating views. And that requires an event-driven model. I thought about using gRPC for that but I'd like to know all other options

  • @butchdean
    @butchdean 3 года назад +2

    This was one of your most excellent videos ever! Progress bars have been making me feel lacking for years! haha. Thank you!

  • @vitacell1
    @vitacell1 3 года назад +4

    I love C, and your videos about it.

    • @JacobSorber
      @JacobSorber  3 года назад +3

      Thanks. Glad you're enjoying them.

  • @redcrafterlppa303
    @redcrafterlppa303 3 года назад

    I was recently making some terminal related lerning libraries and moving the cursor using ansi was something I was overcomplicating. This video really helped me understanding ansi better.

  • @Arnau_0_0
    @Arnau_0_0 3 года назад

    I had a lot of problems understanding ESC characters but you made it all clear to me. Thanks!!

  • @stackoverflow2155
    @stackoverflow2155 3 года назад

    I really like your tutorials. They cover C, and how people can use it well.

  • @oblivionronin
    @oblivionronin Год назад

    I started to research this after i saw the output of docker build, tought it was so cool, like how do i get this into my program ?! I knew it wasnt curses, glad to see its fairly simple. Great video, thanks !

  • @zedespook
    @zedespook 3 года назад +5

    Can you do a video about #pragma once vs. header guards?

  • @edenr1988
    @edenr1988 3 года назад

    Thanks a lot! couldn't find a better explanation anywhere else than in your video! 👍

    • @JacobSorber
      @JacobSorber  3 года назад

      You're welcome! Glad it helped.

  • @gaganb
    @gaganb 3 года назад

    A video about namespaces would be great to see!

  • @praenubilus1980
    @praenubilus1980 3 года назад

    Please make more videos like this one

  • @TheKelor
    @TheKelor 3 года назад

    This was *exactly* what I was searching for :o really ty :D

    • @JacobSorber
      @JacobSorber  3 года назад +2

      Welcome. Glad I could help.

  • @mah4i
    @mah4i 3 года назад

    While i was watching this video ,i noticed that most of icons in RUclips page changed from almost 1 minute ago.
    well, that's weird.
    Also love your videos man , i like people who respect C :D

    • @JacobSorber
      @JacobSorber  3 года назад

      Thanks. Not sure what was happening with the icons, but I'm glad you're enjoying the videos.

  • @benjaminshinar9509
    @benjaminshinar9509 3 года назад +1

    really cool!
    how does the format know you meant \033 and not null terminator ('\0') followed by 33 without spaces?
    great video as usual, I'm always learnning new things.

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Thanks. Octal escape sequences have 1-3 digits (octits), and the sequence ends when you either run into a non digit or you finish with 3 digits. So, "\0003" would be NULL character followed by '3' and \03 would be the character with value 3.

    • @Scotty-vs4lf
      @Scotty-vs4lf Год назад

      @@JacobSorber what if u used hex instead of octal

  • @ahmadj1064
    @ahmadj1064 3 года назад

    Hey jacob, really really love your stuff. Can you make a video on strings in general in c? I have a hard time with strings and would really like a video on string manipulation

    • @JacobSorber
      @JacobSorber  3 года назад

      Yeah, probably. Are there specific things about strings that are messing you up?

  • @therealchonk
    @therealchonk 3 года назад +4

    Can't you just use '\b' for backspace?

    • @JacobSorber
      @JacobSorber  3 года назад +2

      Good point. Yes, you can. I was just looking through the CSI docs and so I ended up using that one.

    • @edgarbonet1
      @edgarbonet1 2 года назад

      Indeed. For the record, when you hit the backspace key on a terminal operating in canonical mode, the terminal driver echoes "\b \b", meaning: move back one cell, overwrite with a space, move back again.

  • @storkmobile7432
    @storkmobile7432 3 года назад

    Jacob,
    Nice videos to watch and to learn c from a profession. May I ask for a reqest. Maybe one step behind mulity threading, MPI (message pasing interface, executing parallel programs on different computers. I'm interested in how to use it in practice. Thanks Ben

    • @JacobSorber
      @JacobSorber  3 года назад

      An MPI tutorial could be fun. I'll see what I can do. Thanks.

  • @agustinranieri
    @agustinranieri 3 года назад

    Love your videos! How about making a selection menu?

    • @JacobSorber
      @JacobSorber  3 года назад

      Yeah, we could do that. I'll add it to the list.

  • @udhayakumar8259
    @udhayakumar8259 3 года назад +1

    Hi ,jacob can you explain fcntl- (fille control in unix ) record locking features in Unix

    • @JacobSorber
      @JacobSorber  3 года назад +1

      I'll add it to the list, and see what I can do in a future video. Thanks.

    • @udhayakumar8259
      @udhayakumar8259 3 года назад

      @@JacobSorber thank you jacob awesome.

  • @guifes10
    @guifes10 3 года назад

    Is this supposed to work on a windows terminal as well? or just unix?

  • @airbus5717
    @airbus5717 3 года назад

    can u make a video recommending other Yt channels that produce C content

  • @pro-nav
    @pro-nav 3 года назад

    So you are saying I can make ASCII games for a terminal without using windows.h? Excellent, right when I needed it.

  • @Cwmwd24
    @Cwmwd24 3 года назад

    Why not use "\e" for the ESC character?

  • @b4ttlemast0r
    @b4ttlemast0r 2 года назад

    the arrowhead overwrites the initial [ too

  • @EpiKaoZ
    @EpiKaoZ 2 года назад

    Why you didnt need to use mutexes? isnt It unsafe to access progress from diferent threads?

    • @thebigmacd
      @thebigmacd Год назад

      None of the threads are writing to the same memory location, so there is no conflict.

  • @oj0024
    @oj0024 3 года назад +1

    Can you link some ANSI control sequence documentation? Whenever I need to use them, I end up using some random site that has like three to four escape sequences, which is really annoying. Is there a reference with an exhaustive list of all the standard ones?

    • @JacobSorber
      @JacobSorber  3 года назад +1

      I typically use the wikipedia page (en.wikipedia.org/wiki/ANSI_escape_code). It also has links to more official docs down at the bottom.

    • @ukaszdrukaa8326
      @ukaszdrukaa8326 3 года назад +2

      The xterm documentation is one of the de facto standards for terminal escape sequences; you can search for "xterm sequences" and you'll find it, granted it's lengthy and technical.
      It's also worth mentioning that not all terminals support all sequences, and that's why the terminfo library (that ncurses uses) exists. You can use it to see if the terminal supports a sequence and if not, then you can avoid using it. (terminals can really get upset when they receive broken or unknown escape sequences)
      Aaand I'll also allow myself to shill Notcurses. It's an awesome terminal graphics library, more powerful and modern than ncurses is.

  • @abdus-salam
    @abdus-salam 3 года назад

    can you help to understand by example of old fashion terminal dashboard with dynamically updating values?. i.e gpsd do

  • @winter0912
    @winter0912 3 года назад +1

    Just wanna point out that in real world you have to use some synchronization mechanism (mutexes / atomic variables) while updating and reading progress, otherwise it's data race, so undefined behaviour

    • @winter0912
      @winter0912 3 года назад

      Well, it of cource depends on the architecture, for example not synchronizing it on x86 is *probably* ok, you won't see half-updated int. But you should always pay attention to this kind of details.

  • @XenoTravis
    @XenoTravis 3 года назад +1

    Why do people say avoid using sleep functions? I can't ever seem to find a good answer or alternative. I imagine it isn't that big of a deal with modern computing

    • @JacobSorber
      @JacobSorber  3 года назад +4

      First off, you always want to be careful with this sort of advice. Such a broad recommendation is bound to be wrong at least some of the time. That said, there are a bunch of different reasons someone might say that. In embedded systems, we avoid *some* sleep functions (like __delay_cycles on the MSP430s) because they can keep the CPU active and may not properly utilize low power modes. Others do, and...so, no worries. Depending on what you're trying to do, sleep functions are often a bit clunky. They are often uninterpretable. They aren't guaranteed to wait for the amount of time you asked them to. So, you often have more efficient and responsive ways to wait for things - like condition variables, mutexes, timers, events, etc. For the example in this video, I didn't really care about any of that. I just didn't want to be constantly burning CPU cycles.

    • @XenoTravis
      @XenoTravis 3 года назад

      @@JacobSorber well now I got some investigation to do! Thanks for the info!

    • @Victor_Marius
      @Victor_Marius 2 года назад

      @@JacobSorber i think on arduino, using the delay functions it doesn't work well with some timing libs (for alarms, timeouts and intervals) and maybe another thing is that you can not use it on interrupts.

  • @JohnHollowell
    @JohnHollowell 3 года назад +1

    Now I know what all the cryptic stuff in my shell prompt variable (PS1) means and why they give me different colors and text formats, thanks!

  • @kodref
    @kodref 3 года назад

    ESC CSI NUMTHREADS PREVIOUSLINE

  • @Victor_Marius
    @Victor_Marius 2 года назад

    Does it work in windows? I tried these escape sequences in CMD (but in python) and \033[5F doesn't appear to work. I used \033[5A
    instead.

    • @Starwort
      @Starwort 2 года назад

      cmd and powershell do not support ANSI natively afaik, but Windows Terminal does, or you can use the colorama library to polyfill it (colorama.init() sets up your terminal to use ANSI, and the library also contains some shortcuts)

    • @Victor_Marius
      @Victor_Marius 2 года назад

      @@Starwort I'm pretty sure I used colorama.init in CMD and there are some escape sequences that don't work even though they are on the Microsoft developer website

    • @Starwort
      @Starwort 2 года назад

      @@Victor_Marius weird; were you using the colorama tools or ANSI escapes directly? If the latter, you may have messed up the parameters to init?

  • @v3spirit
    @v3spirit 3 года назад

    multiple progress in the bars terminal?

  • @sonymusicproducer8711
    @sonymusicproducer8711 8 месяцев назад

    😘

  • @lifesoftserv
    @lifesoftserv 3 года назад

    Really like your channel. Would like to see your thoughts on a build system, if you are interested in looking it is called "qo" and it is on github from andlabs/qo . Thanks and keep up the good work :)

    • @JacobSorber
      @JacobSorber  3 года назад +1

      Thanks, Joe. I'll take a look.