Skip to content

Commit

Permalink
fix unicode support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kun Chen committed May 1, 2023
1 parent ff415d4 commit 997e4f1
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 8 deletions.
1 change: 1 addition & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"node-fetch": "^2.6.7",
"node-loader": "^2.0.0",
"node-pty": "^0.10.1",
"os-locale": "^6.0.2",
"vm": "^0.1.0",
"webpack": "^5.72.0",
"winston": "^3.8.2"
Expand Down
13 changes: 11 additions & 2 deletions apps/app/src/nativeBridge/modules/terminalModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BrowserWindow } from 'electron';
import { app, BrowserWindow } from 'electron';
import { IPty } from 'node-pty';
import os from 'os';
import { osLocaleSync } from 'os-locale';

import { moduleEvent, moduleFunction, NativeBridgeModule, nativeBridgeModule } from '../module';
import { Logger } from './common/logger';
Expand All @@ -19,10 +20,18 @@ class PTYInstance {
(process.platform === 'win32' ? 'cmd.exe' : '/bin/bash');

this.ptyProcess = require('node-pty').spawn(shell, [], {
name: 'xterm-color',
name: 'xterm-256color',
cols: cols,
rows: rows,
cwd: startupDirectory || os.homedir() || process.cwd(),
env: {
...process.env,
LANG: `${osLocaleSync().replace(/-/, '_')}.UTF-8`,
TERM: 'xterm-256color',
COLORTERM: 'truecolor',
TERM_PROGRAM: app.name,
TERM_PROGRAM_VERSION: app.getVersion(),
},
});

Logger.getInstance().log('info', `Created new terminal with id: ${id}, size: ${cols}x${rows}, shell: ${shell}`);
Expand Down
4 changes: 4 additions & 0 deletions apps/app/webpack.preload.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ module.exports = {
electron: 'commonjs electron',
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/^os-locale$/,
path.resolve(__dirname, './dist/nativeBridge/emptyPolyfill.js'),
),
new webpack.NormalModuleReplacementPlugin(
/^winston$/,
path.resolve(__dirname, './dist/nativeBridge/emptyPolyfill.js'),
Expand Down
9 changes: 8 additions & 1 deletion apps/terminal/components/Terminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DEFAULT_CONFIG } from '@terminalone/types';
import { useEffect, useRef } from 'react';
import { Terminal as XTerm } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { Unicode11Addon } from 'xterm-addon-unicode11';
import { WebglAddon } from 'xterm-addon-webgl';

import { useConfigContext } from '../../hooks/ConfigContext';
Expand All @@ -28,13 +29,19 @@ const Terminal = ({ active, shellName }: { active: boolean; shellName: string })
const xtermDiv = terminalRef.current;

// TODO: refactor this into multiple effects
const xterm = new XTerm();
const xterm = new XTerm({
allowProposedApi: true,
});

const webglAddon = new WebglAddon();
xterm.loadAddon(webglAddon);

const fitAddon = new FitAddon();
xterm.loadAddon(fitAddon);

xterm.loadAddon(new Unicode11Addon());
xterm.unicode.activeVersion = '11';

xterm.open(xtermDiv);

const terminalId = (nextId++).toString();
Expand Down
1 change: 1 addition & 0 deletions apps/terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"xterm": "^5.1.0",
"xterm-addon-canvas": "^0.3.0",
"xterm-addon-fit": "^0.7.0",
"xterm-addon-unicode11": "^0.5.0",
"xterm-addon-webgl": "^0.14.0"
},
"devDependencies": {
Expand Down
50 changes: 48 additions & 2 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terminalone/monorepo",
"productName": "Terminal One",
"version": "0.2.0",
"version": "0.2.1",
"description": "A fast, elegant and intelligent cross-platform terminal.",
"author": "Kun Chen",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export const validateConfig = (config: unknown): Config => {

export const DEFAULT_CONFIG: ResolvedConfig = {
scrollback: 10000,
cursorBlink: false,
cursorStyle: 'block',
cursorBlink: true,
cursorStyle: 'bar',
cursorWidth: 1,
fontSize: 16,
fontFamily: 'Consolas, Menlo, monospace',
Expand Down

0 comments on commit 997e4f1

Please sign in to comment.