-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #2394 - Expose terminal cursor #2397
base: develop
Are you sure you want to change the base?
Conversation
- changed TextEditor.CursorColumnShow to fix terminal:cursorcol
src/kOS.Safe/Screen/TextEditor.cs
Outdated
@@ -12,7 +12,7 @@ public class TextEditor : ScreenBuffer | |||
private int cursorColumnBuffer; | |||
private int cursorRowBuffer; | |||
|
|||
public override int CursorColumnShow { get { return cursorColumnBuffer; } } | |||
public override int CursorColumnShow { get { return CursorColumn + cursorColumnBuffer; } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. This might explain a few other weird behaviours I've seen in the past.
The problem with making a built-in for "print without linebreak" is that we already used "print" for "print with linebreak" so something like "print" and "println" would break every old script. I think at this point we are kind of stuck with being unable to do a nice built-in for "print no line feed". We could add a "putln" suffix to terminal, alongside the "put" suffix you made. Then we just change the documentation to say that the built-in |
The original decision, made before I got to the project, to make "PRINT AT" NOT move the cursor to the new location, is one of those things I'd have done differently if we had the luxury of starting from scratch. If it did move the cursor, that would have made things make more sense when trying to work with old terminal escape codes. |
That's exactly why I called it
Sounds good, I'll add that to the PR... propably tomorrow. Fits with the general "everything's a structure" that seems to be going on in kOS these days (not that I don't like that, quite the opposite).
While I'm at it, I would change the documentation of |
This is all looking good so far. I have been slow to review because of a cold this week making my brain all stuffy and miserable feeling. I think I'd prefer it if there was nothing |
Thank you. I hope you're feeling better now!
Added that. Although it's just a new suffix to terminal. The parser code for Also added a terminal:movecursor(col,row) so one can move the cursor in a single call as opposed to two sets. |
We can leave it as two implementations for now. The refactor to merge them can come later. |
Running this code in the interactive terminal causes only the (visible) cursor to advance, but no chars to show. When you now type new text into the terminal, that text appears at the beginning of the line instead of where the cursor ended up being. |
So what actually happens is that the interactive prompt uses its own linebuffer, that then replaces the line the cursor is currently in, hiding any output there. We don't want that. This also means not clearing the line the cursor is placed in - if a kerboscript dev puts the cursor in the middle of existing output, they are responsible for that, we enable that by not hiding output unexpectedly. I currently think a comparatively elegant solution would be to just have TextEditor write to the main buffer of ScreenBuffer, like everything else. Obviously need to check if that behaves well etc. Hopefully I get to that tomorrow, but could take a few days. |
Something also to check, does (this is mostly a reminder for myself, although anybody testing this might want to also look at that) EDIT: just tested this, currently newlines as part of the argument string to |
If one inputs the above repeatedly in the interactive terminal, with varying amounts of empty lines between the two lines of actual code, previous output is sometimes overwritten with the echoed input, after the input is confirmed. I.e. the echoed input looses empty lines and sometimes moves up in the buffer. So it seems the Interpreter/TextEditor/ScreenBuffer-Stack is already broken for some edge cases, this "just" adds some more of those. Not that I won't try to fix it. |
Continuing a discussion from the Discord here for better documentation. So @Dunbaratu and I agreed that scrolling the view should no longer move the cursor and instead the view should jump to the cursor when Following from that, I think that neither (A) On (B) Change I'm personally in favour of variant B. Opinions? |
- everything's a SubBuffer now - cursor/printing positions are now absolute instead of screen relative - no SplitLines strip newlines anymore - fixes scrolling moving the cursor - fixes resizing not moving the cursor correctly - fixes the interactive prompt hiding output in the same lines - fixes multiline interactive input - fixes output containing explicit newlines
This is not ready yet, with the last commit the following issues still remain:
So there will be some additional, hopefully smaller, commits to this. |
@Garek33 I sort of forgot about this PR since the last thing you said on it was "this is not ready yet". You mentioned that a few more commits to address remaining problems were coming, and I saw a few more commits after that on Feb 10, but no follow-up message saying, "I now think this is ready" so I wasn't looking at it yet. As I now go through older PR's in the history, I see this and wonder, ,"Okay, so were those commits the end of it? Was it ready after that and I just didn't know it was ready?" |
Sorry about dropping off without notice like that, but... life happened. (And apparently missing github notifications, sorry again). As far as I remember, I left this unfinished. |
Hi, sorry about leaving this unfinished for so long, but life happened and quite frankly, I wasn't playing KSP anymore. I updated the pull request:
After that and some manual testing I think this is ready. Some things I noticed, but I think are out of scope for this PR:
|
Fixes #2394
terminal
mostly as described in the Issueput
as a suffix, too. But I don't personally have a strong opinion on that and would be willing to make it a builtin or implementterminal:println
andterminal:printat
for consistency.cursorcol
orcursorrow
on the interpreter leads to the prompt moving around (but, what else would you want to achieve with that?)cursorcol
on a non-zero value, theProgram ended
-Message is offset by that