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

Issue 428 v1 sending rows and cols #430

Merged
merged 9 commits into from
Oct 30, 2023
17 changes: 17 additions & 0 deletions __mocks__/xterm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class Terminal {
}
element = {
addEventListener: vi.fn(),
parentElement: {
clientHeight: 480,
clientWidth: 640
}
}
constructor (props) {
this.out = ""
Expand Down Expand Up @@ -62,5 +66,18 @@ export class Terminal {
const ev = new KeyboardEvent("keydown", { key })
this.keyHandler( { domEvent: ev } )
}
resize:(columns: number, rows: number) => void = vi.fn();
_core = {
_renderService: {
dimensions: {
css: {
cell: {
width: 5,
height: 11
}
}
}
}
}
}

6 changes: 3 additions & 3 deletions aatp/http_webrtc/http_webrtc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pinch_max_y_velocity = 0.1`
await page.screenshot({ path: `/result/2.png` })
await expect(page.locator('.pane')).toHaveCount(2)
})
test('a pane can be close', async() => {
sleep(500)
test('a pane can be closed', async() => {
await sleep(500)
const exitState = await page.evaluate(() => {
try {
window.terminal7.activeG.activeW.activeP.d.send("exit\n")
Expand All @@ -120,7 +120,7 @@ pinch_max_y_velocity = 0.1`
await page.screenshot({ path: `/result/second.png` })
const lines = await page.evaluate(() =>
window.terminal7.activeG.activeW.activeP.t.buffer.active.length)
expect(lines).toEqual(38)
await expect(lines).toEqual(38)
await page.evaluate(async() => {
const gate = window.terminal7.activeG
gate.disengage().then(() => {
Expand Down
3 changes: 1 addition & 2 deletions aatp/ui/ui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ insecure=true`)
await expect(page.locator('#t0')).toBeVisible()
await sleep(500)
await page.keyboard.press('ArrowDown')
await page.keyboard.press('ArrowDown')
await page.keyboard.press('Enter')
await expect(page.locator('.windows-container')).toBeHidden()
})
Expand All @@ -104,7 +103,7 @@ insecure=true`)
await page.screenshot({ path: `/result/2.png` })
await page.locator('.tabbar .reset').click()
await expect(page.locator('#t0')).toBeVisible()
sleep(20)
await sleep(20)
await page.keyboard.press('Enter')
await expect(page.locator('#t0')).toBeHidden()
await expect(page.locator('.pane')).toHaveCount(1)
Expand Down
15 changes: 9 additions & 6 deletions src/gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export class Gate {
/*
* returns an array of panes
*/
panes() {
panes(): Pane[] {
const r = []
this.t7.cells.forEach(c => {
if (c instanceof Pane && (c.gate == this))
Expand All @@ -388,10 +388,11 @@ export class Gate {
reset() {
this.t7.map.shell.runCommand("reset", [this.name])
}
setLayout(state: ServerPayload = null) {
setLayout(state: ServerPayload = null, fromPresenter = false) {
console.log("in setLayout", state)
const winLen = this.windows.length
this.fontScale = 1
if(this.fitScreen)
this.fontScale = 1
// got an empty state
if ((state == null) || !(state.windows instanceof Array) || (state.windows.length == 0)) {
// create the first window and pane
Expand All @@ -410,7 +411,7 @@ export class Gate {
if (this.layoutWidth != state.width || this.layoutHeight != state.height) {
this.layoutWidth = state.width
this.layoutHeight = state.height
this.fitScreen = false
if (fromPresenter) this.fitScreen = false
this.scaleContainer()
}
state.windows.forEach(w => {
Expand Down Expand Up @@ -476,7 +477,9 @@ export class Gate {
container.style.transformOrigin = "top left"
}
this.panes().forEach(p => {
p.t.options.fontSize = Math.floor(scale * p.fontSize)
// NOTE: the step of changing the font size is 0.5, there is no visual change when doing smaller steps
const fontSize = p.fontSize * scale
p.t.options.fontSize = Math.floor(fontSize) + (String(fontSize).includes('.') ? .5 : 0)
})
this.fontScale = scale
}
Expand Down Expand Up @@ -698,7 +701,7 @@ export class Gate {
this.session.onStateChange = (state, failure?) => this.onSessionState(state, failure)
this.session.onCMD = msg => {
if (msg.type == "set_payload") {
this.setLayout(msg.args.payload)
this.setLayout(msg.args.payload, true)
}
}
this.t7.log("opening session")
Expand Down
28 changes: 22 additions & 6 deletions src/pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ const ABIT = 10,
caseSensitive: true,
}

export interface SerializedPane {
sx: number,
sy: number,
xoff: number,
yoff: number,
fontSize: number,
channelID: number,
active: boolean,
zoomed: boolean,
rows: number,
cols: number
}

export class Pane extends Cell {
active = false
aLeader = false
Expand Down Expand Up @@ -201,7 +214,8 @@ export class Pane extends Cell {
this.fontSize += by
if (this.fontSize < 6) this.fontSize = 6
else if (this.fontSize > 30) this.fontSize = 30
this.t.options.fontSize = this.fontSize * this.gate.fontScale
const fontSize = this.fontSize * this.gate.fontScale
this.t.options.fontSize = Math.floor(fontSize) + (String(fontSize).includes('.') ? .5 : 0)
this.fit()
this.gate.sendState()
}
Expand Down Expand Up @@ -298,7 +312,7 @@ export class Pane extends Cell {
// returns true is size was changed
// TODO: make it async
fit(cb = null) {
if (!this.t) {
if (!this.t || !this.gate?.fitScreen) {
if (cb instanceof Function)
cb(this)
return
Expand All @@ -307,7 +321,7 @@ export class Pane extends Cell {
const oldc = this.t.cols

// there's no point in fitting when in the middle of a restore
// it happens in the eend anyway
// it happens in the end anyway
try {
this.fitAddon.fit()
} catch (e) {
Expand Down Expand Up @@ -706,7 +720,7 @@ export class Pane extends Cell {
this.unzoom()
super.close()
}
dump() {
dump(): SerializedPane {
const cell = {
sx: this.sx,
sy: this.sy,
Expand All @@ -715,14 +729,16 @@ export class Pane extends Cell {
fontSize: this.fontSize,
channelID: null,
active: false,
zoomed: false
zoomed: false,
rows: this.t.rows,
cols: this.t.cols
}
cell.channelID = this.channelID
if (this.w.activeP && this == this.w.activeP)
cell.active = true
if (this.zoomed)
cell.zoomed = true
return cell as this
return cell
}
// listening for terminal selection changes
selectionChanged() {
Expand Down
19 changes: 17 additions & 2 deletions src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,22 @@ export class Window {
thisCell.yoff = thatCell.yoff
thisCell.fontSize = thatCell.fontSize
if (thisCell.t) {
thisCell.t.options.fontSize = thatCell.fontSize * this.gate.fontScale
thisCell.fit()
// NOTE: the step of changing the font size is 0.5, there is no visual change when doing smaller steps
const fontSize = thatCell.fontSize * this.gate.fontScale
thisCell.t.options.fontSize = Math.floor(fontSize) + (String(fontSize).includes('.') ? .5 : 0)

const availableHeight = thisCell.t.element.parentElement.clientHeight
const availableWidth = thisCell.t.element.parentElement.clientWidth

const adjustFontSize = (availableWidth: number, availableHeight: number) => {
const charDims: { width: number, height: number } = thisCell.t._core._renderService.dimensions.css.cell
if (charDims.width * thatCell.cols > availableWidth || charDims.height * thatCell.rows > availableHeight) {
thisCell.t.options.fontSize -= .5
adjustFontSize(availableWidth, availableHeight)
}
}
adjustFontSize(availableWidth, availableHeight)
thisCell.t.resize(thatCell.cols, thatCell.rows)
}
if (thatCell.active)
thisCell.focus()
Expand All @@ -275,6 +289,7 @@ export class Window {
setTimeout(() => zoomed.zoom(), 100)
console.log("will zoom in 100ms")
}
newLayout.refreshDividers()
DmitryPorotov marked this conversation as resolved.
Show resolved Hide resolved
return newLayout

}
Expand Down