From 4e5c1aab1c80d2e2da19e249cd8cd29aff4d0104 Mon Sep 17 00:00:00 2001 From: sawka Date: Thu, 6 Oct 2022 15:17:48 -0700 Subject: [PATCH] fix termsize calculations for canvas renderer 7.2px not 8px --- src/main.tsx | 17 +++++++---------- src/model.ts | 20 ++++++++++++++------ src/sh2.less | 1 + src/term.ts | 20 ++++---------------- src/util.ts | 12 +++++++++++- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 6556e5673..ebcda919d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -11,12 +11,10 @@ import cn from "classnames"; import {TermWrap} from "./term"; import type {SessionDataType, LineType, CmdDataType, RemoteType, RemoteStateType, RemoteInstanceType, RemotePtrType, HistoryItem, HistoryQueryOpts, RemoteEditType} from "./types"; import localizedFormat from 'dayjs/plugin/localizedFormat'; -import {GlobalModel, GlobalCommandRunner, Session, Cmd, Window, Screen, ScreenWindow, riToRPtr, widthToCols} from "./model"; +import {GlobalModel, GlobalCommandRunner, Session, Cmd, Window, Screen, ScreenWindow, riToRPtr, widthToCols, termWidthFromCols, termHeightFromRows} from "./model"; dayjs.extend(localizedFormat) -const CellHeightPx = 16; -const CellWidthPx = 8; const RemotePtyRows = 8; const RemotePtyCols = 80; const PasswordUnchangedSentinel = "--unchanged--"; @@ -352,9 +350,8 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width ); } let termLoaded = this.termLoaded.get(); - let termWidth = Math.max(Math.trunc((width - 20)/CellWidthPx), 10); let usedRows = sw.getUsedRows(cmd, width); - let totalHeight = CellHeightPx * usedRows; + let termHeight = termHeightFromRows(usedRows); let remote = model.getRemote(cmd.remoteId); let status = cmd.getStatus(); let termOpts = cmd.getTermOpts(); @@ -390,7 +387,7 @@ class LineCmd extends React.Component<{sw : ScreenWindow, line : LineType, width
-
+
(loading)
@@ -917,14 +914,14 @@ class InfoRemoteShow extends React.Component<{}, {}> { -
+
input is only allowed while status is 'connecting'
-
+
); @@ -1619,10 +1616,10 @@ class CmdInput extends React.Component<{}, {}> { let infoMsg = inputModel.infoMsg.get(); let hasInfo = (infoMsg != null); let remoteShow = (infoMsg != null && !isBlank(infoMsg.ptyremoteid)); - let focusVal = model.getFocusedLine(); + let focusVal = inputModel.physicalInputFocused.get(); return (
-
+
diff --git a/src/model.ts b/src/model.ts index cfe103afa..88f121cc4 100644 --- a/src/model.ts +++ b/src/model.ts @@ -2,26 +2,34 @@ import * as mobx from "mobx"; import {sprintf} from "sprintf-js"; import {boundMethod} from "autobind-decorator"; import {debounce} from "throttle-debounce"; -import {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData} from "./util"; +import {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData, boundInt} from "./util"; import {TermWrap} from "./term"; import {v4 as uuidv4} from "uuid"; import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, RemotePtrType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, UIContextType, HistoryInfoType, HistoryQueryOpts, FeInputPacketType, TermWinSize, RemoteInputPacketType} from "./types"; import {WSControl} from "./ws"; var GlobalUser = "sawka"; -const DefaultCellWidth = 8; +const DefaultCellWidth = 7.203125; const DefaultCellHeight = 16; const RemotePtyRows = 8; // also in main.tsx const RemotePtyCols = 80; +const MinTermCols = 10; +const MaxTermCols = 1024; function widthToCols(width : number) : number { let cols = Math.trunc((width - 25) / DefaultCellWidth) - 1; - if (cols < 0) { - return 0; - } + cols = boundInt(cols, MinTermCols, MaxTermCols); return cols; } +function termWidthFromCols(cols : number) : number { + return Math.ceil(DefaultCellWidth*cols) + 15; +} + +function termHeightFromRows(rows : number) : number { + return Math.ceil(DefaultCellHeight*rows); +} + type OV = mobx.IObservableValue; type OArr = mobx.IObservableArray; type OMap = mobx.ObservableMap; @@ -1963,6 +1971,6 @@ if ((window as any).GlobalModal == null) { GlobalModel = (window as any).GlobalModel; GlobalCommandRunner = (window as any).GlobalCommandRunner; -export {Model, Session, Window, GlobalModel, GlobalCommandRunner, Cmd, Screen, ScreenWindow, riToRPtr, widthToCols}; +export {Model, Session, Window, GlobalModel, GlobalCommandRunner, Cmd, Screen, ScreenWindow, riToRPtr, widthToCols, termWidthFromCols, termHeightFromRows}; diff --git a/src/sh2.less b/src/sh2.less index e21c5f9f3..90139ff19 100644 --- a/src/sh2.less +++ b/src/sh2.less @@ -456,6 +456,7 @@ html, body, #main { border-top: 1px solid #777; overflow: hidden; flex-shrink: 0; + position: relative; &:nth-child(2) { margin: 0px 5px 5px 5px; diff --git a/src/term.ts b/src/term.ts index 1b2c8025e..ca274ecad 100644 --- a/src/term.ts +++ b/src/term.ts @@ -3,7 +3,8 @@ import {Terminal} from 'xterm'; import {sprintf} from "sprintf-js"; import {boundMethod} from "autobind-decorator"; import {v4 as uuidv4} from "uuid"; -import {GlobalModel} from "./model"; +import {GlobalModel, widthToCols} from "./model"; +import {boundInt} from "./util"; import type {TermOptsType, TermWinSize} from "./types"; type DataUpdate = { @@ -16,21 +17,9 @@ type WindowSize = { width: number, }; -const DefaultCellWidth = 8; -const DefaultCellHeight = 16; const MinTermCols = 10; const MaxTermCols = 1024; -function boundInt(ival : number, minVal : number, maxVal : number) : number { - if (ival < minVal) { - return minVal; - } - if (ival > maxVal) { - return maxVal; - } - return ival; -} - type TermContext = {sessionId? : string, cmdId? : string, remoteId? : string}; // cmd-instance @@ -67,11 +56,10 @@ class TermWrap { this.termSize = {rows: termOpts.rows, cols: termOpts.cols}; } else { - let cols = Math.trunc((winSize.width - 25) / DefaultCellWidth) - 1; - cols = boundInt(cols, MinTermCols, MaxTermCols); + let cols = widthToCols(winSize.width); this.termSize = {rows: termOpts.rows, cols: cols}; } - this.terminal = new Terminal({rows: this.termSize.rows, cols: this.termSize.cols, fontSize: 14, theme: {foreground: "#d3d7cf"}}); + this.terminal = new Terminal({rows: this.termSize.rows, cols: this.termSize.cols, fontSize: 12, fontFamily: "JetBrains Mono", theme: {foreground: "#d3d7cf"}}); this.terminal._core._inputHandler._parser.setErrorHandler((state) => { this.numParseErrors++; return state; diff --git a/src/util.ts b/src/util.ts index 8c2372268..1fb92d73d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -162,4 +162,14 @@ function parseEnv0(envStr64 : string) : Map { return rtn; } -export {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData, parseEnv0}; +function boundInt(ival : number, minVal : number, maxVal : number) : number { + if (ival < minVal) { + return minVal; + } + if (ival > maxVal) { + return maxVal; + } + return ival; +} + +export {handleJsonFetchResponse, base64ToArray, genMergeData, genMergeSimpleData, parseEnv0, boundInt};