InnocentZero's Treasure Chest

HomeFeedAbout Me

25 Apr 2024

Calcurs update

Ok, let's roll.

Adding crossterm as a dependency was fairly straightforward. Now I need to enable raw mode, clear the screen, and then paint the screen and wait for a key command. Easy stuff. Now with this out of the way, I need to code up the calendar view.

Ok, so a couple of minutes later I figured out the aesthetics and stuff but I cannot for the love of god implement a pager in my application. So I'm gonna do what any sane person would think of doing. Use some existing pager library or something.

Ok so we have more problems. bat by itself does not have a pager as far as I can see, so we have to pipe it to something or do some other hacks.

I found a simple solution. I save the output of the calendar as lines and retrieve the final state on scrolling up and down. However, I'll probably lock this in a --view-only flag that won't allow others to open it in a terminal that is too small.

Actually screw it, no need to have the pager at all. Be like btop, bail out if the terminal is too small for your use. But since I changed stuff, I need to figure out how to set it back to the og thing.

For some reason the alignment of the entire table in raw mode is shifted to the left so I need to find the padding manually. Simple enough since I'm already printing the lines manually so I need to verify the width of the line once to make sure that the line fits, since every other line will follow. Ok rust format specifiers ftw!

Colors are creating a problem. Could be just crossterm colors, as they are not playing nicely with the format specifiers. It's weird, but it's not something that isn't handleable. Let me try owo_colors crate for now. If it works I'll open a bug report.

Figured out the problem. Rust does not recognise ansi escape quotes as a thing so I need to use unicode width to measure them. ansi_width to the rescue!

Bruh, this is insanely weird. The length works perfectly fine now but the padding does not. Wtf?? Ok the padding read was the length to the rightmost point of the string. Makes sense. With this calendar view as a static is done for now.

Tags: programming projects

Other posts
Creative Commons License
This website by Md Isfarul Haque is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.