Searching yarn

Twts matching #coding
Sort by: Newest, Oldest, Most Relevant
In-reply-to » @lyse Is it this one? https://github.com/rivo/tview It’s almost 10 years old but hasn’t seen a 1.0.0 release yet? šŸ¤”

@movq@www.uninformativ.de Yes. The author tries hard not to break existing code, but apparently he did this time. In his defense, it’s not an official release, I just updated to master. Which is exactly what I always did in the past as there are no real versions (I even think that in one ticket he wrote years ago that master is always stable). That has finally changed a year ago, though: https://github.com/rivo/tview/releases/tag/v0.42.0

⤋ Read More
In-reply-to » Every now and then, I think that I have carefully proof-read my message enough times and hit the "Add message" button in tt. But then, in the message tree, I spot another missed typo. My process is then to go to my twtxt.txt and fix it by hand. However, I still have to clean up tt's cache. This is rather tidious:

Fuck me! I tried to upgrade tview and the first thing I notice is a shitload of added dependency versions:

go.mod | 18 ++++-----
go.sum | 97 ++++++++++++++++++++++++++++++++++++++-----------

My code does not compile anymore as the view.FormItem interface was extended. Get/SetDisabled(…) are quickly implemented, no worries.

But the tview.Primitive (what makes a widget) interface has now a bunch of PRIVATE methods. For focus handling. Would you believe that!? Thanks, I cannot satisfy this interface in my very custom widgets anymore. Okay then, I just embed *tview.Box. tt now successfully compiles, but does not react anymore on key presses and the message tree is not focused either.

I’m not in the mood to debug this shit. :-( Lunch time.

⤋ Read More
In-reply-to » Every now and then, I think that I have carefully proof-read my message enough times and hit the "Add message" button in tt. But then, in the message tree, I spot another missed typo. My process is then to go to my twtxt.txt and fix it by hand. However, I still have to clean up tt's cache. This is rather tidious:

Getting the vim key bindings to work for focus switching in this modal dialog took me forever. Only cursors and (Shift+)Tab are supported out of the box. I absolutely understand that, it’s fine. I installed an input handler on the dialog, but the focus always stayed the same.

After two wasted hours, I was in despair to copy the tview.Modal into my own code base. Of course, I had to fix all the private tview field accesses first. But even installing the input handler directly on the buttons themselves did not work. Even though, the handler was definitely executed, the focus did not shift. Forcing redraws as a last resort also did not work.

Looking through all the messy chained input handling, I eventually stumbled across another place in the tview.Form, which is internally used by tview.Modal. This messed around with app focus receptions and input handlers. This gave me the idea to make the tview.Application refocus my modal dialog after I told the modal dialog which button to select. And would you look at that, this did the trick! I haven’t completely figured out what is going on exactly, but I could get rid of my Modal clone again.

I always go through hell with focus handling in tview. Each and every time. It just does not feel natural to me. Complete brainfuck to wrap my head around. The Urwid API felt sooo much more refined, it never was an issue. It just works. In fact, I cannot think of any other TUI library that has remotely the same pain level when it comes to focusing widgets as tview.

Now I’m curious how movwin deals with that. ;-)

⤋ Read More
In-reply-to » Oh boy, I absolutely hate this stupid trend of not writing changelogs anymore! Why the fuck would one seriously consider it to be a viable option to just let some shitty bot spew all merge requests on a goddamn GitHub release?! First of all, these merge request titles suck balls. The order of the changes in this "changelog" is completely random (well, probably merge time, which is as useless as the dick on the Pope). They are not grouped by anything at all. Additions, changes, removals, deprecations, etc. randomly mixed up in one giant list. And then "Add feature X", seventeen kilometers further down "Revert 'Add feature X'". Fuck you! Don't include this shit in the first place!

@lyse@lyse.isobeef.org Thanks!

On the AI changelog part, though, I’d rather recommend to just not have a changelog at all.

I’m afraid that ship has sailed. You can rest assured that someone who uses AI/LLMs for their code (which is almost everybody at this point) will most certainly also use it for changelogs.

I actually considered not mentioning AI output at all, because this just opens a huge can of worms … šŸ˜ž

While going through these terrible GitHub release pages, I also found these ā€œNew Project Contributorsā€ sections

Yeah, they play on a nerd’s pride.

Now, it’s just the same auto shitshow with MR titles in a rolling date-versioned release scheme. It’s just our team who has to deal with that, though. I think I’m the only one who is not a fan of it.

I’ve found that this whole situation is much worse at work than it is in the Free Software world. At work, it’s literally work and hardly anybody actually cares. We still don’t have all people convinced that writing good commit messages or using good branch names is worth the time. It’s … oh god, no, I’m going to stop here, this is bad for my mental health. šŸ˜…

Suffice it to say, all release notes at work are now AI-generated. Nobody gives a fuck.

⤋ Read More
In-reply-to » First draft of a file selection popup / widget:

@movq@www.uninformativ.de That is really cool! Maybe it would look nicer if the selected entry highlighted the whole row, not just the individual cells in that row without the column spacers. :-? But maybe I’m wrong. Everyone has their own taste.

And no, it’s not pointless at all. I find this really interesting. The videos and photos are perfect for me. Even if I had the source code, I would not use that toolkit, as I’m not a fan of movable windows in TUIs. I want all my own programs to be fullscreen all the time. 8-) Having said that, it’s still an absolutely brilliant source of inspriation that will come in handy one day. So, keep posting. :-)

⤋ Read More
In-reply-to » @lyse Two emails. šŸ˜… One person asking for the source code, and the author of wcwidth (the library I’m using) contacted me to provide some input. šŸ‘Œ

@movq@www.uninformativ.de Great to be asked for feedback! I just noticed that the first wcwidth version was derived from Markus Kuhn’s C code. I came across him in my ISO 8601 and RFC 3339 endeavors the other day. https://www.cl.cam.ac.uk/~mgk25/iso-time.html What a surprise. :-)

⤋ Read More
In-reply-to » (This settled at about 25k hits on the HTML page now. But only about 11k hits in total on favicon.ico and only around 7.5k hits on the image thumbnails. So I guess that, in reality, it might have gotten around 7k hits. The rest … is probably bots.)

@lyse@lyse.isobeef.org Two emails. šŸ˜… One person asking for the source code, and the author of wcwidth (the library I’m using) contacted me to provide some input. šŸ‘Œ

⤋ Read More
In-reply-to » @movq Related reading (if you're interested): Let's Talk about LLMs by James Bennett

@itsericwoodward@itsericwoodward.com That DORA quote is 🤯 — and it perfectly explains why AI coding tools terrify me in certain contexts. Dropping Copilot into a codebase full of technical debt isn’t gonna fix the debt, it’s just gonna write more of it faster 🤣 Fred Brooks would be nodding his head right now šŸ™

⤋ Read More
In-reply-to » @movq Related reading (if you're interested): Let's Talk about LLMs by James Bennett

(#xbh2sbq) @itsericwoodward@itsericwoodward.com That DORA quote is 🤯 — and it perfectly explains why AI coding tools terrify me in certain contexts. Dropping Copilot into a codebase full of technical debt isn’t gonna fix the debt, it’s just gonna write more of it faster 🤣 Fred Brooks would be nodding his head right now šŸ™

⤋ Read More
In-reply-to » Okay. I have lost the ā€œbattleā€ against ā€œAIā€ at work and I will no longer try to ā€œfightā€ any of it.

@movq@www.uninformativ.de Wow, I’m sorry to hear about that. Permanent emergency mode sucks, I’ve been there, and it always felt like drowning.

Fortunately, at my current job, we’ve been given time to keep our technical debt from overtaking the project. Unfortunately, we’ve been forced to use AI (mostly in the form of GitHub Copilot). Of course, now that the tokens cost more than a developer’s salary, they’ve been rethinking that position somewhat. 😁

In my experience, you are 100% correct - even in the best case, AI is a force multiplier. If the code is clean, it can speed you up. But if the code is a mess, it’ll just multiply the mess.

⤋ Read More
In-reply-to » Now that is an interesting move:

@prologic@twtxt.net As have I. šŸ¤” I mean, since I left GitHub, I got basically 0 pull requests anyway.

Even during my time using GitHub, I noticed that ā€œdrive-by PRsā€ are rarely a good idea. People don’t really know/understand the code or the design principles/goals, so I often turned down PRs. Or I accepted them and was grumpy afterwards. šŸ˜…

What does work is having a team of maintainers/devs. The only question is: How do you build such a team if you don’t accept PRs? That’s going to be the interesting part.

⤋ Read More
In-reply-to » @lyse By the way, which site generator are you using? I kind of miss having code blocks with syntax highlighting and that generic yellow highlighting thing is pretty cool, too.

@lyse@lyse.isobeef.org Ah, I almost thought so (that you wrote it by hand), but then I looked at the source code and saw the TOC and I was like: ā€œNaah, probably not. I would be way too lazy to do that manually.ā€ šŸ˜… And indeed … ha.

Oh god, yeah, that’s a lot of <span>. šŸ¤” Can’t really avoid that, I guess, especially if you want to do syntax highlighting of code blocks.

You wrote your own site generator, didn’t you?

In parts. I write everything in Markdown (it’s online, even: https://movq.de/blog/postings/2026-05-29/0/POSTING-en.md), plus a few Vim shortcuts (to generate thumbnails, for example), and then python-markdown renders it: https://pypi.org/project/Markdown/ This process is wrapped in a shell script, like ā€œre-render every page if the .md file is newer than the .html fileā€ and that’s mostly it. And the Atom feed generator is completely custom. šŸ¤”

⤋ Read More
In-reply-to » @movq It's the "Lyse types the entire HTML by hand" generator. Yes, no kidding. I write articles so rarely, that I can do that once in a while. It's fun to some degree, but also not.

Years ago, I used Kate, no, not somebody’s wife, but the KDE Advanced Text Editor, to export source code files and fragments into HTML with syntax highlighting. I think that’s where I got the initial <b> idea from. There were also bucketloads of <span style='color:#644a9b;'> all over the place, even inside <b>. No CSS classes defined upfront, all colors inlined. The final rendering in the browser looked great, but the source code ugly as hell in my opinion. However, I’m thankful for hinting me at <b>. I think this kicked off everything. :-)

⤋ Read More
In-reply-to » @lyse By the way, which site generator are you using? I kind of miss having code blocks with syntax highlighting and that generic yellow highlighting thing is pretty cool, too.

@movq@www.uninformativ.de It’s the ā€œLyse types the entire HTML by handā€ generator. Yes, no kidding. I write articles so rarely, that I can do that once in a while. It’s fun to some degree, but also not.

After some time, I finally recorded some Vim macros to insert <b>…</b>, <var>…</var>, <span class=s>…</span> etc. around the tokens. This helped a little bit. But I was still questioning my mental state doing it like that. I also had to fix a bunch of the end tags by hand, because the word movement wasn’t enough or the end movement went too far. Quite the annoying process for sure.

But I think the HTML looks a wee bit nicer and is maybe even semantically a little bit better than having only <span>s everywhere. I find the <span class="whatever"> just soo awfully long. Of course, I never look at the code again, but knowing, that e.g. there is a <b> and it saves so many bytes in comparison, makes me happy. It is a more elegant solution in my opinion. Not by much, but better nonetheless. It’s a matter of simplicity. Admittedly, even I can’t avoid the <span>s alltogether. Oh well. On the other hand, I’m sure that this does not make any difference whatsoever. I bet, nobody and nothing, like a screenreader, analyzes the HTML for that, where this would be truly useful.

Oh! Maybe text browsers, though. It just occurred to me while composing this reply. :-) Haha, I lost my bet quickly. w3m picks up at least the <b> for keywords and builtin types, <u> for filenames and <i> for comments. Yey. No different styles for <var> and <mark>, unfortunately. elinks only renders the bold. It’s cool that I had the right intuition right from the beginning, despite being unable to pinpoint it. :-)

All the <span> hell with common syntax highlighters is a downer for me that keeps me from looking more into them. If I wrote more articles, I might rig something up with Pygments. At least that’s somehow positively connotated in my brain. Not sure if it actually deserves it, but I dealt with that in some loose form (can’t even remember) years and years ago. Apparently, it wasn’t too terrible.

To prepare the table of contents, I used grep and sed with some manual intervention in the end. The entire process can be improved. Absolutely.

You wrote your own site generator, didn’t you?

⤋ Read More
In-reply-to » @movq Thanks. I noticed the <updated> of the feed, too. But for some reason, some articles were suddenly marked as new.

@lyse@lyse.isobeef.org Oh, nice. That was quite the ride. :-) And all that because of locales. 😳

But, did I understand that correctly? All Atom feeds were broken, right? Because they all use that same code path with that strftime/strptime dance in it?

⤋ Read More
In-reply-to » @movq I'm very curious...

It’s one of the reasons in fact I’ve been working on bob so I have a very concrete and strong foundation for how these things work, how they behave and how bad or good they can be. I am on-purpose building bob to be not only a decent coding tool and general task completion tool, but with serious security boundaries, sanitation, auditing and compliance. If I’m going to succeed at building autoonmous agents that can cope with a wider array of varying inputs (mostly natural language, some structural language) then it needs to be both a) Safe and b) Robust

⤋ Read More
In-reply-to » @movq I'm very curious...

And every time I ask it to do the same thing, it produces basically the same result. It will sometimes not produce a go.mod, but that’s probably because doing so isn’t as statically high as writing the code to sum numbers from stdin.

⤋ Read More
In-reply-to » @movq I'm very curious...

Which it does so in seconds, faster than I can type. The code is correct, it compiles and does exactly what I wanted. And the code looks pretty reasonable. It handles flotas, has error handling and handles space or line separated numbers on stdin.

⤋ Read More
In-reply-to » @movq I'm very curious...

@movq@www.uninformativ.de I think your points are pretty clear to me, that’s fine. I’m just seeing if you can perhaps see things a different way maybe?šŸ¤” I would challenge the assertion that you cannot understand how Claude Code generated an output; which I can demonstrate easily with a fairly trivial example by the input:

Write a program in Go that sums a list of numbers from stdin and prints the result.

⤋ Read More
In-reply-to » @movq I'm very curious...

@prologic@twtxt.net Yeah, it’s hard to get my point across here. I tried to address that a few paragraphs down.

Yes, I can tinker with AI techniques on a general level. That’s cool but not really my area of interest.

What I certainly can’t do is learn how specific AI products work. I can’t possibly find out why Claude Code produced that particular line of code. Claude is just a magic box that does something and I have to trust it.

⤋ Read More
In-reply-to » @lyse Thanks! There are a few points in there that I’ll add to my list.

@bender@twtxt.net Now that’s an interesting philosophical viewpoint right there. But this assumes that the ā€œAIā€ we seemingly have available to us today is actually telligent, understands and has cognitive reasoning. It does not. All of these LLM models from big-tech companies like Anthropic, OpenAI, Google, Microsoft, Meta and Alibaba are all just very powerful, very large multidimensional neural networks with attention that are very good at statistical probabilities of ā€˜what comes nextā€. I think we get really upset over the wrong things sometimes. We need to continue to be upset that these 🤬 companies have basically destroyed any meaningful value of the concept of Copyright and Intellectual Property and Works of art. The so-called ā€œAIā€ we have today is just a tool. Can you say for certain that the typewriter and the computer ruined our ability to write? Perhaps yes, but we still learn how to do so, likewise, I still think that learning to write code, research, read and write are all valuable skills to learn. Later on once you have the basics, you can defer some of the ā€œtediousā€ work to these models, because frankly, they’re far better at inferencing and pattern matching than you or i will ever be, not because they’re better at pattern-matching per se, but because they have been trained on a very large corpus and they are much much faster at doing the same basic things we are far superior at.

⤋ Read More
In-reply-to » @lyse Thanks! There are a few points in there that I’ll add to my list.

Is it the fact that ā€œbig techā€ companies have basically stolen all of human knowledge to their benefit to build these AI(s) that’s the problem? Or is it that these AI(s) can write code better than you can (some of the time)? Or is it that because of all of the above, there’s no joy left in writing code anymore? šŸ¤”

⤋ Read More
In-reply-to » I’ve started collecting reasons against AI usage here, so I don’t have to repeat myself all the time:

@lyse@lyse.isobeef.org Thanks! There are a few points in there that I’ll add to my list.

Your very first point is obviously crucial. ā€œWriting codeā€ is just the means to an end for many people and they don’t really care about it or like it, so they love AI. I had this in another draft (it refers to the other list I posted):

https://movq.de/v/614f14c3ef/ramble.txt

And this right here is so important:

simplicity is the real art and much harder to achieve.

Finding an elegant, simple solution is waaaaaaaaaaaaaaaaaay harder than anything else. And here’s the thing: I don’t get why nerds/techies don’t get ā€œnerd-snipedā€ by this. A lot of people love building big stuff and then brag about being clever/competent because they were able to build that big thing – but once you realize that this approach is the lazy one, shouldn’t you make finding the elegant solution your goal? Doesn’t that give you more bragging rights?

(Am I being clear? Do you understand what I mean? šŸ˜…)

⤋ Read More
In-reply-to » @lyse Uhhh, yes, I have one single script to build the website and I ran that while writing that noai.html page. Apart from the global updated field in my feeds (that one got changed), everything else should be stable, though.

@movq@www.uninformativ.de Thanks. I noticed the <updated> of the feed, too. But for some reason, some articles were suddenly marked as new.

On some YouTube feed <entry>s, I noticed updated <updated> fields showing today’s timestamps. But unless there is no <published>, the <updated> is not even considered. I verified that in the source code. Yet, all the affected articles in Newsboat show today’s timestamp, not the years old publication timestamp. I generate the YouTube feeds from the original feeds myself once a day, so I doubt that this is cause by some YouTube shenanigans.

Very weird, it doesn’t make any sense at all. What is going on here? O_o It doesn’t appear that I have duplicates in the database either.

⤋ Read More
In-reply-to » I just realized that this book, which I’m still using as a reference every now and then, is from 2005.

@tftp@tilde.town Ah, I see. I have a feeling that a lot of stuff is going on under the hood all the time and it’s mostly the userland-visible things that stay the same? šŸ¤” But yeah, some stuff is really, really old, like the TCP code I’ve recently (tried to) read.

⤋ Read More
In-reply-to » So apparently this is the default when making a new Matrix account, which makes me wonder why we’re even doing this whole crypto dance in the first place … ?

@lyse@lyse.isobeef.org

So, it’s plenty good enough for them.

Yeah, but on the other hand, you can’t even log in normally to a Matrix/Element account. I mean using username + password. It’s not expected that you ever log out or lose your browser session. If you do, you must use a one-time backup code (that you must create and save beforehand) to log in again.

To be fair, I can’t say that I fully understand what Matrix is doing in the first place. The text that I quoted reads like they have your keys. But they also claim that they only store this stuff encryped: https://element.io/en/help#encryption5 So … encrypted with what? Only option here is my password, isn’t it? (But if my password was good enough to reclaim an account … why do all the other stuff …)

Matrix takes end-to-end encryption seriously. When I ran a Matrix server for the family, the family members would regularly lose their keys, because they didn’t pay attention to something. That’s on purpose! Or rather, that was on purpose. Maybe it’s different these days?

No clue.

⤋ Read More

I’m not always on the same page as Rob Pike, but this hit close to home:

Although trained in physics, I worked in the computing industry with pride and purpose for over 40 years. And now I can do nothing but sit back and watch it destroy itself for no valid reason beyond hubris (if I’m being charitable).

Ineffable sadness watching something I once loved deliberately lose its soul.

I spent my time trying to make it better. Not just write code, but find better or at least different ways to do so. Simpler, cleaner, more general, more comprehensible.

What’s happening today is a complete repudiation of everything I was trying to achieve.

ā€œSimpler, cleaner, more general, more comprehensibleā€, that’s what I’ve been trying to establish in our teams as well. Obviously not to the same degree, but you get the idea.

And it all goes out the window now. We’re doing the complete opposite – and with full force.

⤋ Read More

I’m still having some fundamental design issues with my TUI widget system, so I’m still not comfortable making this code public.

But after a day of work (and discussing AI ad nauseam at work), I just don’t have any energy left. šŸ˜‘

⤋ Read More
In-reply-to » @lyse Yes, and that’s why I’m 100% convinced that we’ll see a massive brain drain in a couple of years. This will affect young people even more, because they don’t have all the ā€œoldā€ knowledge to fall back on.

@movq@www.uninformativ.de I couldn’t agree more! I also have the feeling that it causes more people to just accept ā€œit’s a software problem, there’s nothing that can be done about itā€. Which is very frightning to me.

Up until now, I was successful in refusing to actively use that crap. I had to do one mandatory AI training, but even our hippest AI enthusiasts found it absolutely terrible. Probably also nailed together by the same rubbish they want us to now use everyday as much as possible.

Code reviews are the part that I have to deal with most. And I believe that the code quality is degrading.

Let’s hope the bubble bursts sooner than later. It will definitely burst at some point. That’s for sure.

⤋ Read More
In-reply-to » @lyse Oops, I guess the new text is a bit obscure. If you follow the link, the text is a bit more explicit, but you still need to know what a lexical scope is. Anyway, this is part of Perl moving very carefully toward being UTF-8 by default while also not breaking code written in the 90s. If you name a recent version like "use v5.42;" then Perl stops letting you use non-ASCII characters unless you also say "use utf8;". The "lexically" part basically means that strictness continues until the next "}", or the end of the program. That lets you fix up old code one block at a time, if you aren't ready to apply the new strictness to a whole file at once.

@falsifian@www.falsifian.org Thanks for clarification. I already thought something along those lines. Wow, so, you can really mix different encodings in a single file, crazy. My Perl experience is limited to maybe 10, 20 or at the very most 30 written lines of code over the decades.

⤋ Read More
In-reply-to » My first pull request to Perl has been merged! https://github.com/Perl/perl5/commit/2aea97bf3f5c2ea62cf5e701858694b7378ed58c

@lyse@lyse.isobeef.org Oops, I guess the new text is a bit obscure. If you follow the link, the text is a bit more explicit, but you still need to know what a lexical scope is. Anyway, this is part of Perl moving very carefully toward being UTF-8 by default while also not breaking code written in the 90s. If you name a recent version like ā€œuse v5.42;ā€ then Perl stops letting you use non-ASCII characters unless you also say ā€œuse utf8;ā€. The ā€œlexicallyā€ part basically means that strictness continues until the next ā€œ}ā€, or the end of the program. That lets you fix up old code one block at a time, if you aren’t ready to apply the new strictness to a whole file at once.

⤋ Read More
In-reply-to » New library alert => Last night, I published twtxt-lib, a new isomorphic TypeScript library for parsing and interacting with twtxt.txt files. Check out the demo at https://twtxt-lib.itsericwoodward.com/!

@prologic@twtxt.net so…

An isomorphic TypeScript library is a codebase, written in TypeScript, that can run in multiple JavaScript environments, most commonly both the web browser (client-side) and a server (like Node.js). The core idea is to share the exact same code across the frontend and backend, avoiding duplication and improving efficiency.

⤋ Read More

Hmmm, that’s a pity. I never realized that before. The following Go code

var b bool
…
b |= otherBool

results in a compilation error:

invalid operation: operator | not defined on b (variable of type bool)

I cannot use || for assignments as in ||= according to https://go.dev/ref/spec#Assignment_statements. Instead, I have to write b = b || otherBool like a barbarian. Oh well, probably doesn’t happen all that often, given that I only now run into this after all those many years.

⤋ Read More

yes, yes that’s right. Mu (µ) now has a built-in LSP server for fans of VS Code / VSCodium šŸ˜… You just go install ./cmd/mu-lsp/... and install the VS extension and hey presto 🄳 You get outlines of any Mu source, Find References and Go to Definition!

⤋ Read More
In-reply-to » Btw @movq you've inspired me to try and have a good 'ol crack at writing a bootloader, stage1 and customer microkernel (µKernel) that will eventually load up a Mu (µ) program and run it! 🤣 I will teach Mu (µ) to have a ./bin/mu -B -o ... -p muos/amd64 ... target.

@prologic@twtxt.net I’d love to take a look at the code. šŸ˜…

I’m kind of curious to know how much Assembly I need vs. How much of a microkernel can I build purely in Mu (µ)? šŸ¤”

Can’t really answer that, because I only made a working kernel for 16-bit real mode yet. That is 99% C, though, only syscall entry points are Assembly. (The OpenWatcom compiler provides C wrappers for triggering software interrupts, which makes things easier.)

But in long mode? No idea yet. šŸ˜… At least changing the page tables will require a tiny little bit of Assembly.

⤋ Read More

Took me nearly all week (in my spare time), but Mu (µ) finally officially support linux/amd64 🄳 I completely refactored the native code backend and borrowed a lot of the structure from another project called wazero (the zero dependency Go WASM runtime/compiler). This is amazing stuff because now Mu (µ) runs in more places natively, as well as running everywhere Go runs via the bytecode VM interpreter šŸ¤ž

⤋ Read More

I’m trying to implement configurable key bindings in tt. Boy, is parsing the key names into tcell.EventKeys a horrible thing. This type consists of three information:

  1. maybe a predefined compound key sequence, like Ctrl+A
  2. maybe some modifiers, such as Shift, Ctrl, etc.
  3. maybe a rune if neither modifiers are present nor a predefined compound key exists

It’s hardcoded usage results in code like this:

func (t *TreeView[T]) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
    return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p tview.Primitive)) {
        switch event.Key() {
        case tcell.KeyUp:
            t.moveUp()
        case tcell.KeyDown:
            t.moveDown()
        case tcell.KeyHome:
            t.moveTop()
        case tcell.KeyEnd:
            t.moveBottom()
        case tcell.KeyCtrlE:
            t.moveScrollOffsetDown()
        case tcell.KeyCtrlY:
            t.moveScrollOffsetUp()
        case tcell.KeyTab, tcell.KeyBacktab:
            if t.finished != nil {
                t.finished(event.Key())
            }
        case tcell.KeyRune:
            if event.Modifiers() == tcell.ModNone {
                switch event.Rune() {
                case 'k':
                    t.moveUp()
                case 'j':
                    t.moveDown()
                case 'g':
                    t.moveTop()
                case 'G':
                    t.moveBottom()
                }
            }
        }
    })
}

This data structure is just awful to handle and especially initialize in my opinion. Some compound tcell.Keys are mapped to human-readable names in tcell.KeyNames. However, these names always use - to join modifiers, e.g. resulting in Ctrl-A, whereas tcell.EventKey.Name() produces +-delimited strings, e.g. Ctrl+A. Gnaarf, why this asymmetry!? O_o

I just checked k9s and they’re extending tcell.KeyNames with their own tcell.Key definitions like crazy: https://github.com/derailed/k9s/blob/master/internal/ui/key.go Then, they convert an original tcell.EventKey to tcell.Key: https://github.com/derailed/k9s/blob/b53f3091ca2d9ab963913b0d5e59376aea3f3e51/internal/ui/app.go#L287 This must be used when actually handling keyboard input: https://github.com/derailed/k9s/blob/e55083ba271eed6fc4014674890f70c5ed6c70e0/internal/ui/tree.go#L101

This seems to be much nicer to use. However, I fear this will break eventually. And it’s more fragile in general, because it’s rather easy to forget the conversion or one can get confused whether a certain key at hand is now an original tcell.Key coming from the library or an ā€œextendedā€ one.

I will see if I can find some other programs that provide configurable tcell key bindings.

⤋ Read More

Since I used so much Rust during the holidays, I got totally used to rustfmt. I now use similar tools for Python (black and isort).

What have I been doing all these years?! I never want to format code manually again. šŸ¤£šŸ˜…

⤋ Read More