Skip to content

Commit

Permalink
feat: add fontFamily, letterSpacing, lineHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
billchurch committed Jul 31, 2022
1 parent 140e1e2 commit 97f3088
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
24 changes: 21 additions & 3 deletions README.md
Expand Up @@ -107,7 +107,13 @@ docker run --name webssh2 -d -p 2222:2222 -v `pwd`/app/config.json:/usr/src/conf

* **bellStyle** - _string_ - Style of terminal bell: ("sound"|"none"). **Default:** "sound". **Enforced Values:** "sound", "none"

* **fontSize** - _integer_ - Size of terminal font. **Default:** "12".
* **fontSize** - _number_ - Size of terminal font. **Default:** 12

* **fontFamily** - _string_ - Font family

* **letterSpacing** - _number_ - Letter spacing

* **lineHeight** - _number_ - Line height

## GET request vars

Expand All @@ -129,7 +135,13 @@ docker run --name webssh2 -d -p 2222:2222 -v `pwd`/app/config.json:/usr/src/conf

* **bellStyle** - _string_ - Style of terminal bell: ("sound"|"none"). **Default:** "sound". **Enforced Values:** "sound", "none"

* **fontSize** - _integer_ - Size of terminal font. **Default:** "12".
* **fontSize** - _number_ - Size of terminal font. **Default:** "12"

* **fontFamily** - _string_ - Font family

* **letterSpacing** - _number_ - Letter spacing

* **lineHeight** - _integer_ - Line height

## Headers

Expand Down Expand Up @@ -174,7 +186,13 @@ docker run --name webssh2 -d -p 2222:2222 -v `pwd`/app/config.json:/usr/src/conf

* **terminal.bellStyle** - _string_ - Style of terminal bell: (sound|none). **Default:** "sound".

* **terminal.fontSize** - _integer_ - Size of terminal font. **Default:** 14.
* **terminal.fontSize** - _number_ - Size of terminal font. **Default:** 14.

* **terminal.fontFamily** - _string_ - Font family

* **terminal.letterSpacing** - _number_ - Letter spacing

* **terminal.lineHeight** - _number_ - Line height

* **header.text** - _string_ - Specify header text, defaults to `My Header` but may also be set to `null`. When set to `null` no header bar will be displayed on the client.

Expand Down
3 changes: 3 additions & 0 deletions app/client/src/js/index.ts
Expand Up @@ -176,6 +176,9 @@ socket.on(
tabStopWidth: number;
bellStyle: 'none' | 'sound';
fontSize: number;
fontFamily: string;
letterSpacing: number;
lineHeight: number;
}) => {
term.options = data;
}
Expand Down
4 changes: 2 additions & 2 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
@@ -1,6 +1,6 @@
{
"name": "webssh2",
"version": "0.4.7-alpha.1",
"version": "0.4.7-alpha.2",
"ignore": [
".gitignore"
],
Expand Down
53 changes: 49 additions & 4 deletions app/server/routes.js
Expand Up @@ -30,7 +30,16 @@ exports.connect = function connect(req, res) {
let { host, port } = config.ssh;
let { text: header, background: headerBackground } = config.header;
let { term: sshterm, readyTimeout } = config.ssh;
let { cursorBlink, scrollback, tabStopWidth, bellStyle, fontSize } = config.terminal;
let {
cursorBlink,
scrollback,
tabStopWidth,
bellStyle,
fontSize,
fontFamily,
letterSpacing,
lineHeight,
} = config.terminal;

// capture, assign, and validate variables

Expand All @@ -50,59 +59,92 @@ exports.connect = function connect(req, res) {

if (req.body.port && validator.isInt(`${req.body.port}`, { min: 1, max: 65535 }))
port = req.body.port;

if (req.body.header) header = req.body.header;

if (req.body.headerBackground) {
headerBackground = req.body.headerBackground;
console.log(`background: ${req.body.headerBackground}`);
}

if (req.body.sshterm && /^(([a-z]|[A-Z]|\d|[!^(){}\-_~])+)?\w$/.test(req.body.sshterm))
sshterm = req.body.sshterm;

if (req.body.cursorBlink && validator.isBoolean(`${req.body.cursorBlink}`))
cursorBlink = parseBool(req.body.cursorBlink);

if (req.body.scrollback && validator.isInt(`${req.body.scrollback}`, { min: 1, max: 200000 }))
scrollback = req.body.scrollback;
if (req.body.tabStopWidth) tabStopWidth = req.body.tabStopWidth;

if (req.body.tabStopWidth && validator.isInt(`${req.body.tabStopWidth}`, { min: 1, max: 100 }))
tabStopWidth = req.body.tabStopWidth;

if (req.body.bellStyle && ['sound', 'none'].indexOf(req.body.bellStyle) > -1)
bellStyle = req.body.bellStyle;

if (
req.body.readyTimeout &&
validator.isInt(`${req.body.readyTimeout}`, { min: 1, max: 300000 })
)
readyTimeout = req.body.readyTimeout;
if (req.body.fontSize && validator.isInt(`${req.body.fontSize}`, { min: 1, max: 300000 }))

if (req.body.fontSize && validator.isNumeric(`${req.body.fontSize}`))
fontSize = req.body.fontSize;

if (req.body.fontFamily) fontFamily = req.body.fontFamily;

if (req.body.letterSpacing && validator.isNumeric(`${req.body.letterSpacing}`))
letterSpacing = req.body.letterSpacing;

if (req.body.lineHeight && validator.isNumeric(`${req.body.lineHeight}`))
lineHeight = req.body.lineHeight;
}

if (req.method === 'GET') {
if (req.query?.port && validator.isInt(`${req.query.port}`, { min: 1, max: 65535 }))
port = req.query.port;

if (req.query?.header) header = req.query.header;

if (req.query?.headerBackground) headerBackground = req.query.headerBackground;

if (req.query?.sshterm && /^(([a-z]|[A-Z]|\d|[!^(){}\-_~])+)?\w$/.test(req.query.sshterm))
sshterm = req.query.sshterm;

if (req.query?.cursorBlink && validator.isBoolean(`${req.query.cursorBlink}`))
cursorBlink = parseBool(req.query.cursorBlink);

if (
req.query?.scrollback &&
validator.isInt(`${req.query.scrollback}`, { min: 1, max: 200000 })
)
scrollback = req.query.scrollback;

if (
req.query?.tabStopWidth &&
validator.isInt(`${req.query.tabStopWidth}`, { min: 1, max: 100 })
)
tabStopWidth = req.query.tabStopWidth;

if (req.query?.bellStyle && ['sound', 'none'].indexOf(req.query.bellStyle) > -1)
bellStyle = req.query.bellStyle;

if (
req.query?.readyTimeout &&
validator.isInt(`${req.query.readyTimeout}`, { min: 1, max: 300000 })
)
readyTimeout = req.query.readyTimeout;
if (req.query?.fontSize && validator.isInt(`${req.query.fontSize}`, { min: 1, max: 300000 }))

if (req.query?.fontSize && validator.isNumeric(`${req.query.fontSize}`))
fontSize = req.query.fontSize;

if (req.query?.fontFamily) fontFamily = req.query.fontFamily;

if (req.query?.lineHeight && validator.isNumeric(`${req.query.lineHeight}`))
lineHeight = req.query.lineHeight;

if (req.query?.letterSpacing && validator.isNumeric(`${req.query.letterSpacing}`))
letterSpacing = req.query.letterSpacing;
}

req.session.ssh = {
Expand All @@ -125,6 +167,9 @@ exports.connect = function connect(req, res) {
tabStopWidth,
bellStyle,
fontSize,
fontFamily,
letterSpacing,
lineHeight,
},
allowreplay:
config.options.challengeButton ||
Expand Down

0 comments on commit 97f3088

Please sign in to comment.