Open akshayphdk opened 6 years ago
You're right, kilo does not handle changing the terminal size. I didn't add that because I didn't want to make too many changes to the original code, and it didn't bother me very much to not have that feature.
openemacs is a fork of kilo that adds a bunch of features, including resizing the window. The code is in a slightly different style from original kilo, but you should get a pretty good idea how to implement window resizing from this commit: https://github.com/practicalswift/openemacs/commit/7ff8025000c4a284e1631dbe6ba020daba7a8988. It uses Unix signals to listen for window resize events, specifically the SIGWINCH (SIGnal WINdow CHange) signal.
So yeah, I'm leaving implementing this feature as an exercise for the reader. π
As for your second issue, it doesn't sound like it should be a problem. It's the way kilo is written. For simplicity, it doesn't refresh the screen except on keypresses. The only thing this really affects is how the status message is supposed to disappear after a few seconds, but won't actually disappear until you press a key. As a lazy programmer we could say that's a feature rather than a bug: it makes sure the user is present to be able to see the message before it disappears. π
But if you're experiencing other issues caused by that while loop, can you be more specific what the problem is? Is it causing flickering? It shouldn't be, but I know there is a lot of weird and inconsistent behaviour with the way read()
works in raw mode in Windows (if you happen to be using Windows)...
No. I'm not facing any issues like flickering. I am running this in an Ubuntu VM. Thanks for the prompt and detailed answer. :)
Great, glad to hear! Let me know if you have any problems implementing that window resizing signal handler (if you do choose to try and implement it).
Sure. Thanks. :) Will do it once I am through with the rest of the steps. :) So keeping this open to address any issues that may arise later related to window resizing.
awesome, i to was having the same issue, glad i came across this π
Hi,
Thanks for this amazing tutorial. I have been trying to use C in a meaningful way for the longest time and this is a perfect place to start. I am following the tutorial and currently I am on step 49. I have noticed the following issues so far:
Whenever I resize the terminal window, the E.screenrows and E.screencols are not updated. This is because the initEditor() method is called only once before the while(1) loop. So while the screen does get refreshed, the "size of the canvas" doesn't change.
Because of the while loop in editorReadKey(), while the read() method does time out after 0.1 seconds, it still doesn't break the loop unless a key is pressed. Because it is still stuck in a loop, the method call doesn't return anything, resulting in the screen also not being refreshed till a key is pressed.
I scrolled through the rest of the steps, and I didn't see this issue being addressed anywhere. This can be a bigger issue than flickering, which is addressed in the tutorial. I am new to using github, and to the open-source world, so apologies in advance if I am wrong here. Just trying to learn :)