Skip to content

Implement the Dimensions effect for xterm.js.#34

Merged
noelwelsh merged 5 commits intocreativescala:mainfrom
LSUDOKO:fix#24
May 15, 2025
Merged

Implement the Dimensions effect for xterm.js.#34
noelwelsh merged 5 commits intocreativescala:mainfrom
LSUDOKO:fix#24

Conversation

@LSUDOKO
Copy link
Contributor

@LSUDOKO LSUDOKO commented May 11, 2025

Fixes #24: Implement Dimensions effect for xterm.js

This commit implements the Dimensions effect for the xterm.js backend, enabling users to get the terminal's columns and rows, and to resize the terminal.

Key Changes:

  1. core/js/src/main/scala/terminus/XtermJsTerminal.scala:

    • Added the necessary facade methods to interact with xterm.js's dimension properties and resize functionality:
      • def cols: Int
      • def rows: Int
      • def resize(cols: Int, rows: Int): Unit
  2. core/js/src/main/scala/terminus/XtermJsOptions.scala:

    • Modified the apply method to ensure a consistent parameter order for dimensions: cols: Int = 80, rows: Int = 24.
  3. core/js/src/main/scala/terminus/Terminal.scala:

    • The Terminal class now extends the effect.Dimensions trait.
    • Implemented getDimensions to retrieve the current terminal dimensions (TerminalDimensions(terminal.cols, terminal.rows)).
    • Implemented setDimensions to resize the terminal using terminal.resize(dimensions.columns, dimensions.rows).
    • Added a dimensions helper object within the Terminal companion object for a cleaner API (e.g., Terminal.dimensions.get).
    • Updated the run method (that accepts id, cols, rows) to call XtermJsOptions with the cols parameter first, then rows, maintaining consistency.

These changes provide the core functionality requested in issue #24 for the xterm.js environment. The coreJS/test suite passes with these modifications.
image

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.

Looks good apart from one change.

}
type Program[A] = Terminal ?=> A

object Terminal extends Color, Cursor, Format, Erase, Writer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should extend Dimensions

@noelwelsh noelwelsh merged commit 79bb155 into creativescala:main May 15, 2025
6 checks passed
@noelwelsh
Copy link
Contributor

Thanks!

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.

Implement Dimensions for xterm.js

3 participants