luke.b//blog

Today I want to add line wrapping to nomad and maybe figure out why there are still erroneous empty lines somehow after certain vim operations.

Apart from that it would be great to work on my various stories that I haven’t made progress on in a long while.

Let’s do this.

Gah, I so want to stay up late and implement line wrapping in nomad but it’s way too late… or early?

Ah, phew. git log is working. Which makes a lot of sense because I think the default pager that it uses is less.

Woop :)

I FIXED IT. SCROLLING WORKS IN VIM, LESS, HTOP AND PROBABLY OTHER THINGS!!!

For some reason, all the developers at some point in history were like “well, ESC [ A is nice, and the standard says we should use it to mean “move the cursor up” but what about ESC O A, it’s different and we can call it “Application Keys”, yeah that sounds cool."

Apparently it’s something to do with keypads. Maybe one day I’ll dive deep into how this car crash happened, but for now I’m satisfied to know that it’s all documented here and length and in great detail.

Anyway, this small but significant detail (it’s always one character isn’t it) was causing some programs to fail to be scrolled because I was sending the non-“Application Key” of the arrow keys.

Wait. Now git log scrolling is broken noooooo.

Sending up/down arrow sequences to vim when scrolling works beautifully. But guess what, less isn’t having any of it. ffs.

I suspect that what actually happens in e.g. Terminal.app is that scrolling up or down literally sends the same sequences as pressing the up or down arrow keys.

Let’s try that.

I’ve got a bit of time before I go sleep so I might see if I can fix scrolling up in vim ._.

I really feel like I’m learning how to write good tests.

I’m starting to think that integration testing is actually very difficult to do well if the individual components and their APIs change frequently and it’s best to write tests of any kind where the inputs and outputs of the tests are abstracted one layer from the actual API.

I did this in my commit earlier and I think it will make the test cases a lot easier to test in future, even if the API of the function being tested changes:

https://github.com/lukebarnard1/nomad-term/commit/f10c70a9b30abd7b1b9638c0eefc6d6a379e728a

Each test case specifies an input which would be the “real” input and an output which is one layer abstracted from the actual return value of the function.

This allows inspection of certain aspects of the output of the function without giving direct access to the returned value. So if the returned object changes, only a small amount of code will need to change as opposed to every test case.

I’ll definitely use this technique in future. And it’s proved really popular in various UI testing frameworks, including Enzyme which allows you to select certain parts of the rendered component and assert things about it.

I also want to do a blog about testing in general and how we’ve gone about testing the app I’ve been working on at work.

One of the hardest things I’m finding is that our components change quite rapidly, and so do there APIs. Something that we’ve been doing more and more is separate side-effect logic into “collective hooks” where most if not all of the hooks for a given React component are kept. This pattern makes it trivial to test the “view” half of the component in isolation from it’s stateful, side-effect half.

Anyway, I’m still learning the ropes when it comes to testing, more updates later :)

I added a bunch of tests to nomad and fixed them so now the weird line deletion bug (that was introduced when I introduced the scroll tracking) is now fixed and tested for!

I finally got round to formally testing the control sequence parser and found a few sequences that were broken, so that was very much worth the bother.

I’m quite glad that I had some integration tests too because one of them failed midway through, indicating a bug which was due to some sequence that doesn’t start with CSI not being properly parsed. I added a unit test for that to make doubly sure that if it is broken, it’ll be a bit more obvious what is actually happening.

I’m waiting for COD: MW to update so I’ll go and add tests to the logic nomad uses for parsing control sequences, because it’s really in need of a re-write.

Then maybe I’ll actually rewrite it but we’ll see how much progress I can make.

page 14 of 27 after before