Moon Engine

Share
Moon Engine
Photo by Mark Tegethoff / Unsplash

This is a project that I worked on during the Christmas break last year and ... I procrastinated for a while to even start writing this

So let get start

Here is the design of the Moon Engine, it leverages the iBus system in Linux to allow a custom panels showing when user types.

If you ever used sogou it is similar to that, there is also already a similar project call ibus-typing-booster where does pretty much the same thing but... much better.

I decided to make moon engine for no other reason than my spelling issues and from what I know about LLMs they are really good a decrypting my text messages, here is an example:

I leveraged AI to help me write this part, due to grammar and spelling

If you've ever used a Chinese or Japanese keyboard on Linux, you've used IBus. It's the input method framework that is between your keyboard and every app, and you can write your own engine for it. That's what this project is: my own IBus engine for English that suggests words as I type. Spoilers it is awful

The idea is simple: keep track of the current word the user is typing and use the dictionary to suggest different words that we can show to the user.

So it was pretty simple from the start, keeping a word buffer and displaying that word buffer on the screen using the panel through IBus. The only part that was tricky was the input shortcuts to determine if the user is still typing or has completed the word. In this case it was just using space to determine the state of the system. Using the spacebar to transition from the typing state to committing the word, and Ctrl + 1–5 to pick one of the suggestions.

I also added a passthrough toggle. Ctrl + Shift + M turns the engine off so keys go straight to the app, for when it gets in the way, like in a terminal. This is actually when I felt, damn, why are we making this, why isn't there a way to do automatic detection? Oh, there was, but why didn't I write it? Well... I kinda just forgot about it.

There is a background job feeding the LLM the current context of the words the user has typed into the interface / application, and trying to fix the spelling and grammar of what the user is trying to write.

I ran into a few issues, though. First, the UI. I wanted the Sogou UI where I can have a custom IBus panel, but the CSS I wrote never applied, no idea why. Digging into it, it might just be an issue with X11 and the older display server.

The IBus system sucks in Linux. It never works as intended. I call the surrounding text API, guess what? Empty text, nothing returns. Why? It depends on the application owner to implement it. What in the actual Fox.

This project was intended to be a macOS add-on to the desktop keyboard, but I got confused by all the Swift docs.

Reference:

https://github.com/epicseven-cup/moon