Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lgoldfinch
Copy link

@Lgoldfinch Lgoldfinch commented Feb 7, 2025

This will only work for terminals that support JLine.

I added the set terminal size feature to enable testing for this issue.

Copy link
Contributor

@noelwelsh noelwelsh left a 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 ?=>
Copy link
Contributor

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?
Copy link
Contributor

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.

Copy link
Author

@Lgoldfinch Lgoldfinch Feb 11, 2025

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

Copy link
Contributor

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.

Copy link
Author

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

@Lgoldfinch Lgoldfinch force-pushed the addTerminalDimensions branch from 0c1509a to 263ac4c Compare February 8, 2025 13:26
@Lgoldfinch Lgoldfinch force-pushed the addTerminalDimensions branch from 2e03812 to d94dd39 Compare February 23, 2025 12:01

final case class TerminalDimensions(noOfColumns: Int, noOfRows: Int)

//object TerminalDimensions {
Copy link
Author

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)
Copy link
Author

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?

@Lgoldfinch Lgoldfinch force-pushed the addTerminalDimensions branch 6 times, most recently from 5d7fcd0 to 6ed9c9a Compare February 24, 2025 17:44
* Get terminal dimensions (creativescala#13)
* Set terminal dimensions (creativescala#12)
@Lgoldfinch Lgoldfinch force-pushed the addTerminalDimensions branch from 6ed9c9a to aec3251 Compare February 24, 2025 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants