Skip to content

Commit

Permalink
Added support to set initial size of the pty process
Browse files Browse the repository at this point in the history
Since the terminal width is final in bazel there is no use for propagating resize events to the bazel process.
  • Loading branch information
LeFrosch committed Nov 22, 2024
1 parent a75264b commit cdc2020
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ class BazelExecService(private val project: Project) : Disposable {
private suspend fun execute(ctx: BlazeContext, cmdBuilder: BlazeCommand.Builder): Int {
val cmd = cmdBuilder.apply { addBlazeFlags("--curses=yes") }.build()
val root = cmd.effectiveWorkspaceRoot.orElseGet { WorkspaceRoot.fromProject(project).path() }
val size = BuildViewScope.of(ctx)?.consoleSize ?: PtyConsoleView.DEFAULT_SIZE

val cmdLine = PtyCommandLine()
.withInitialColumns(PtyOptions.COLUMNS)
.withInitialRows(PtyOptions.ROWS)
.withInitialColumns(size.columns)
.withInitialRows(size.rows)
.withExePath(cmd.binaryPath)
.withParameters(cmd.toArgumentList())
.apply { setWorkDirectory(root.pathString) } // required for backwards compatability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
import com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase
import com.intellij.openapi.project.Project
import com.intellij.util.ThreeState
import com.jediterm.core.util.TermSize
import java.util.function.Consumer

class BuildViewScope(project: Project, private val title: String) : BlazeScope {
Expand All @@ -37,6 +38,8 @@ class BuildViewScope(project: Project, private val title: String) : BlazeScope {
private var console = PtyConsoleView(project)
private var indicator = BackgroundableProcessIndicator(project, title, "Cancel", "Cancel", true)

val consoleSize: TermSize? get() = console.size

override fun onScopeBegin(ctx: BlazeContext) {
progress.start(ProgressDescriptor(title, console, ctx))

Expand Down
17 changes: 10 additions & 7 deletions base/src/com/google/idea/blaze/base/buildview/PtyConsoleView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.jediterm.terminal.TerminalStarter
import com.jediterm.terminal.TtyConnector
import com.jediterm.terminal.model.JediTerminal
import java.io.IOException
import java.util.function.Consumer
import javax.swing.JComponent

private val LOG = Logger.getInstance(PtyConsoleView::class.java)
Expand All @@ -24,9 +25,15 @@ private const val ANSI_RESET = "\u001b[0m"

class PtyConsoleView(project: Project) : ExecutionConsole {

companion object {
val DEFAULT_SIZE = TermSize(80, 24)
}

private val stream = AppendableTerminalDataStream()
private val terminal = Terminal(project, this, stream)

val size: TermSize? get() = terminal.terminalPanel.terminalSizeFromComponent

init {
terminal.start(Connector(this))
}
Expand Down Expand Up @@ -72,16 +79,11 @@ class PtyConsoleView(project: Project) : ExecutionConsole {
override fun dispose() = Unit
}

object PtyOptions {
const val COLUMNS = 80
const val ROWS = 24
}

private class Terminal(
project: Project,
parent: Disposable,
private val stream: AppendableTerminalDataStream,
) : JBTerminalWidget(project, PtyOptions.COLUMNS, PtyOptions.ROWS, JBTerminalSystemSettingsProviderBase(), null, parent) {
) : JBTerminalWidget(project, JBTerminalSystemSettingsProviderBase(), parent) {

override fun createTerminalStarter(terminal: JediTerminal, connector: TtyConnector): TerminalStarter? {
return TerminalStarter(
Expand Down Expand Up @@ -118,9 +120,10 @@ private class Connector(parent: Disposable) : TtyConnector, Disposable {

override fun close() = Unit

// The terminal size for bazel is final. No use propagating resize events to the process.
override fun resize(size: TermSize) = Unit

override fun dispose() {
connected = false
}
}
}

0 comments on commit cdc2020

Please sign in to comment.