Commit ff7e8f3a authored by ibuler's avatar ibuler

[Update] 根据操作系统调整terminal 行高

parent 88619fc4
...@@ -151,4 +151,4 @@ ...@@ -151,4 +151,4 @@
"prefix": "app" "prefix": "app"
} }
} }
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ import {Component, Input, OnInit, OnChanges} from '@angular/core'; ...@@ -2,6 +2,7 @@ import {Component, Input, OnInit, OnChanges} from '@angular/core';
import {Terminal} from 'xterm'; import {Terminal} from 'xterm';
import {HttpService, LogService} from '@app/services'; import {HttpService, LogService} from '@app/services';
import {Replay} from '@app/model'; import {Replay} from '@app/model';
import {newTerminal} from '@app/utils/common';
function zeroPad(num, minLength) { function zeroPad(num, minLength) {
let str = num.toString(); let str = num.toString();
...@@ -80,14 +81,7 @@ export class ElementReplayJsonComponent implements OnInit { ...@@ -80,14 +81,7 @@ export class ElementReplayJsonComponent implements OnInit {
constructor(private _http: HttpService) {} constructor(private _http: HttpService) {}
ngOnInit() { ngOnInit() {
this.term = new Terminal({ this.term = newTerminal(14);
fontFamily: '"Monaco", "Consolas", "monospace"',
fontSize: 14,
rightClickSelectsWord: true,
theme: {
background: '#1f1b1b'
}
});
if (this.replay.src !== 'READY') { if (this.replay.src !== 'READY') {
this._http.getReplayData(this.replay.src) this._http.getReplayData(this.replay.src)
.subscribe( .subscribe(
......
...@@ -4,6 +4,7 @@ import {View} from '@app/model'; ...@@ -4,6 +4,7 @@ import {View} from '@app/model';
import {LogService, SettingService, UUIDService} from '@app/services'; import {LogService, SettingService, UUIDService} from '@app/services';
import {Socket} from '@app/utils/socket'; import {Socket} from '@app/utils/socket';
import {getWsSocket, translate} from '@app/globals'; import {getWsSocket, translate} from '@app/globals';
import {newTerminal} from '@app/utils/common';
@Component({ @Component({
...@@ -38,15 +39,7 @@ export class ElementSshTermComponent implements OnInit, OnDestroy { ...@@ -38,15 +39,7 @@ export class ElementSshTermComponent implements OnInit, OnDestroy {
newTerm() { newTerm() {
const fontSize = this.settingSvc.setting.fontSize; const fontSize = this.settingSvc.setting.fontSize;
this.term = new Terminal({ this.term = newTerminal(fontSize);
fontFamily: 'monaco, Consolas, "Lucida Console", monospace',
lineHeight: 1.2,
fontSize: fontSize,
rightClickSelectsWord: true,
theme: {
background: '#1f1b1b'
}
});
this.view.Term = this.term; this.view.Term = this.term;
this.term.attachCustomKeyEventHandler(e => { this.term.attachCustomKeyEventHandler(e => {
if (e.ctrlKey && e.key === 'c' && this.term.hasSelection()) { if (e.ctrlKey && e.key === 'c' && this.term.hasSelection()) {
......
import {Terminal} from 'xterm';
export function groupBy(array, f) { export function groupBy(array, f) {
const groups = {}; const groups = {};
array.forEach( function( o ) { array.forEach( function( o ) {
...@@ -9,3 +11,23 @@ export function groupBy(array, f) { ...@@ -9,3 +11,23 @@ export function groupBy(array, f) {
return groups[group]; return groups[group];
}); });
} }
export function newTerminal(fontSize?: number) {
if (!fontSize || fontSize < 5 || fontSize > 50) {
fontSize = 13;
}
const ua = navigator.userAgent.toLowerCase();
let lineHeight = 1;
if (ua.indexOf('windows') !== -1) {
lineHeight = 1.2;
}
return new Terminal({
fontFamily: 'monaco, Consolas, "Lucida Console", monospace',
lineHeight: lineHeight,
fontSize: fontSize,
rightClickSelectsWord: true,
theme: {
background: '#1f1b1b'
}
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment