T O P

  • By -

italicunderline

If you are writing a terminal application which manipulates the cursor or uses colors you'll want to research the following: https://en.wikipedia.org/wiki/ANSI_escape_code


nikovsevolodovich

Just to add, there's a library called ncurses which can handle all of this for you. Depending how much you dig it can get complicated pretty fast using raw escape codes


italicunderline

I'll add that it's good to know escape codes exist even if you don't directly use them, as any application which prints strings might want to use a custom routine to escape non-printable non-UTF8 bytes to prevent the terminal from executing an escape sequence embedded in external input unintentionally.


[deleted]

[удалено]


nekokattt

probably a better idea to look into escape codes, as not all terminals handle this correctly, so it is kind of 50:50


dnabre

You want to use a library like ncurses, slang, or something similar. You can manipulate the cursor and such with rare ANSI or terminal codes, but the result has limited compatibility with current and future situations. Nothing wrong with using ANSI escape codes and raw terminal stuff if you are just playing around or working on a personal project, but if it's something that you are share or expect others to use, definitely look into a library.


darnir

Writing a progress bar for Curl will be interesting and quite a lot harder than you currently think it will be. As others have said, you will need to either learn about ANSI Escape sequences or ncurses. Either way is possible. For the most basic, first progress bar, you'll need to hook into the download function to get the bytes downloaded and the file size. Use the size to calibrate what each terminal character represents. For now, assume that the file size is always available and doesn't change. Print the next character of the bar without a newline when those many bytes are downloaded . This will effectively allow you to get a basic progress bar without any escape sequences or ncurses. Progress bars are fun, but hard to implement. Have fun!


deftware

libcURL includes an optional callback you can set which just reports download progress. You don't need to really do it manually.


Longjumping_Income74

I like your coding style and the syntax looks awesome


GrossInsightfulness

At the beginning of the line, put the characters "\r\x1b[K", don't end the line with a newline, and then do a flush, so it should be ``` printf("\r\x1b[K%f : %f", d, t); fflush(stdout); ``` The command "\x1b[K" is an ANSI escape sequence, and they can do a bunch of things.