-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Enabling terminal dimension feature #16
base: main
Are you sure you want to change the base?
Conversation
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.
I think this would benefit from a few tweaks. Also, if you run the build
command from sbt that will add copyright headers, do formatting, etc. This is necessary for CI to pass the code.
/** Functionality for getting the dimensions of the terminal */ | ||
trait Dimensions { | ||
object dimensions { | ||
def getDimensions: effect.Dimensions ?=> Unit = effect ?=> |
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.
If this is wrapped in an object named dimensions
, we don't need to name the method getDimensions
. Just get
is fine.
Alternatively it could just be getDimensions
without the wrapping object. This is not a method that is going to have a name collision, unlike the methods for setting color and moving the cursor.
@@ -47,6 +46,15 @@ class JLineTerminal(terminal: JTerminal) extends Terminal { | |||
} | |||
} | |||
|
|||
// Do we need to consider getBufferSize? |
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.
I have no idea what most of these methods do. The JLine documentation is, unfortunately, not very good.
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.
It isn't, but I followed the docs and it leads you to this.
TLDR, the getSize
method should be used in full screen mode, and getBufferSize
otherwise.
JLine doesn't have the ability to get whether it's full screen mode, so we could create another method that tries to determine whether the users terminal is in full screen mode or not. Terminus Users could have use for this.
Or, we could keep the logic local to this function
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.
It might be worth running some experiments to what the value of the two methods is. I think for most cases getSize
will do the job. I'm not sure it's possible to get things working perfectly across all terminals, but the terminals for which it won't work will be fairly obscure.
Alternatively, this has a section on getting the terminal size: https://viewsourcecode.org/snaptoken/kilo/03.rawInputAndOutput.html Reading the JLine source code might help understand which method they are using.
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.
From the terminals I have at my disposal, I couldn't see any difference in output of the two. So have just used the standard method here
0c1509a
to
263ac4c
Compare
2e03812
to
d94dd39
Compare
|
||
final case class TerminalDimensions(noOfColumns: Int, noOfRows: Int) | ||
|
||
//object TerminalDimensions { |
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.
The project didn't compile when I included this. But I did want to include some way to indicate that TerminalDimensions
and Size
are linked. Alternatively, I could add an Iso
instance to handle the mapping.
Conversely, you might not see any value in this anyway! So happy to omit
def setDimensions(dimensions: TerminalDimensions): Unit | ||
} | ||
|
||
final case class TerminalDimensions(noOfColumns: Int, noOfRows: Int) |
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.
Do you want me to add opaque types for this?
5d7fcd0
to
6ed9c9a
Compare
* Get terminal dimensions (creativescala#13) * Set terminal dimensions (creativescala#12)
6ed9c9a
to
aec3251
Compare
This will only work for terminals that support
JLine
.I added the set terminal size feature to enable testing for this issue.