Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/app/dto/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ type TerminalInfo struct {
LineHeight string `json:"lineHeight"`
LetterSpacing string `json:"letterSpacing"`
FontSize string `json:"fontSize"`
FontFamily string `json:"fontFamily"`
CursorBlink string `json:"cursorBlink"`
CursorStyle string `json:"cursorStyle"`
Scrollback string `json:"scrollback"`
Expand Down
3 changes: 3 additions & 0 deletions core/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ func (u *SettingService) UpdateTerminal(req dto.TerminalInfo) error {
if err := settingRepo.Update("FontSize", req.FontSize); err != nil {
return err
}
if err := settingRepo.Update("FontFamily", req.FontFamily); err != nil {
return err
}
if err := settingRepo.Update("CursorBlink", req.CursorBlink); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions core/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func Init() {
migrations.AdjustXpackNode,
migrations.UpdateAiAgentsMenu,
migrations.AddDashboardCarouselSetting,
migrations.AddTerminalFontFamily,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
20 changes: 20 additions & 0 deletions core/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,23 @@ var UpdateAiAgentsMenu = &gormigrate.Migration{
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}

var AddTerminalFontFamily = &gormigrate.Migration{
ID: "20260212-add-terminal-font-family",
Migrate: func(tx *gorm.DB) error {
var addSettingsIfMissing = func(tx *gorm.DB, key, value string) error {
var setting model.Setting
if err := tx.Where("key = ?", key).First(&setting).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return tx.Create(&model.Setting{Key: key, Value: value}).Error
}
return err
}
return nil
}
if err := addSettingsIfMissing(tx, "FontFamily", ""); err != nil {
return err
}
return nil
},
}
1 change: 1 addition & 0 deletions frontend/src/api/interface/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export namespace Setting {
lineHeight: string;
letterSpacing: string;
fontSize: string;
fontFamily: string;
cursorBlink: string;
cursorStyle: string;
scrollback: string;
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/terminal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ watch([lineHeight, fontSize, letterSpacing], ([newLineHeight, newFontSize, newLe
term.value.options.fontSize = newFontSize;
changeTerminalSize();
});
const fontFamily = computed(() => terminalStore.fontFamily);
watch(fontFamily, (newFontFamily) => {
const defaultFontFamily = "Monaco, Menlo, Consolas, 'Courier New', monospace";
term.value.options.fontFamily = newFontFamily || defaultFontFamily;
});
const cursorStyle = computed(() => terminalStore.cursorStyle);
watch(cursorStyle, (newCursorStyle) => {
term.value.options.cursorStyle = newCursorStyle;
Expand Down Expand Up @@ -77,10 +82,14 @@ const acceptParams = (props: WsProps) => {

const newTerm = () => {
const background = getComputedStyle(document.documentElement).getPropertyValue('--panel-terminal-bg-color').trim();
const defaultFontFamily = "Monaco, Menlo, Consolas, 'Courier New', monospace";
// fontFamily 从后端获取,如果为空则使用默认值
const fontFamily = terminalStore.fontFamily || defaultFontFamily;

term.value = new Terminal({
lineHeight: terminalStore.lineHeight || 1.2,
fontSize: terminalStore.fontSize || 12,
fontFamily: "Monaco, Menlo, Consolas, 'Courier New', monospace",
fontFamily: fontFamily,
theme: {
background: background,
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,9 @@ const message = {
lineHeight: 'Line Height',
letterSpacing: 'Letter Spacing',
fontSize: 'Font Size',
fontFamily: 'Custom Font',
fontFamilyHelper:
'Leave empty to use default fonts. If you enter a custom font name, ensure the font is installed on your local system, otherwise the default font will be used',
cursorBlink: 'Cursor Blink',
cursorStyle: 'Cursor Style',
cursorUnderline: 'Underline',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,9 @@ const message = {
lineHeight: 'Altura de línea',
letterSpacing: 'Espaciado de letras',
fontSize: 'Tamaño de fuente',
fontFamily: 'Fuente personalizada',
fontFamilyHelper:
'Dejar vacío para usar fuentes predeterminadas. Si ingresa un nombre de fuente personalizado, asegúrese de que la fuente esté instalada en su sistema operativo local, de lo contrario se renderizará con la fuente predeterminada',
cursorBlink: 'Parpadeo del cursor',
cursorStyle: 'Estilo de cursor',
cursorUnderline: 'Subrayado',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,9 @@ const message = {
key: '秘密鍵',
keyPassword: '秘密キーパスワード',
emptyTerminal: '現在接続されている端子はありません。',
fontFamily: 'カスタムフォント',
fontFamilyHelper:
'空欄の場合はデフォルトフォントを使用します。カスタムフォント名を入力する場合は、ローカルOSにそのフォントがインストールされていることを確認してください。インストールされていない場合はデフォルトフォントでレンダリングされます',
},
toolbox: {
common: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,9 @@ const message = {
key: '개인 키',
keyPassword: '개인 키 비밀번호',
emptyTerminal: '현재 연결된 터미널이 없습니다.',
fontFamily: '사용자 정의 글꼴',
fontFamilyHelper:
'비워두면 기본 글꼴을 사용합니다. 사용자 정의 글꼴 이름을 입력한 후에는 로컬 운영 체제에 해당 글꼴이 설치되어 있는지 확인하세요. 그렇지 않으면 기본 글꼴로 렌더링됩니다',
},
toolbox: {
common: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,9 @@ const message = {
key: 'Kunci peribadi',
keyPassword: 'Kata laluan kunci peribadi',
emptyTerminal: 'Tiada terminal yang sedang disambungkan.',
fontFamily: 'Fon tersuai',
fontFamilyHelper:
'Biarkan kosong untuk menggunakan fon lalai. Jika anda memasukkan nama fon tersuai, pastikan fon tersebut dipasang pada sistem operasi tempatan anda, jika tidak ia akan dipaparkan dengan fon lalai',
},
toolbox: {
common: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,9 @@ const message = {
key: 'Chave privada',
keyPassword: 'Senha da chave privada',
emptyTerminal: 'Nenhum terminal está conectado no momento.',
fontFamily: 'Fonte personalizada',
fontFamilyHelper:
'Deixe em branco para usar fontes padrão. Se você inserir um nome de fonte personalizado, certifique-se de que a fonte esteja instalada no seu sistema operacional local, caso contrário será renderizada com a fonte padrão',
},
toolbox: {
common: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,9 @@ const message = {
key: 'Приватный ключ',
keyPassword: 'Пароль приватного ключа',
emptyTerminal: 'В настоящее время нет подключенных терминалов.',
fontFamily: 'Пользовательский шрифт',
fontFamilyHelper:
'Оставьте пустым для использования шрифтов по умолчанию. Если вы введете имя пользовательского шрифта, убедитесь, что шрифт установлен в вашей локальной операционной системе, иначе будет использован шрифт по умолчанию',
},
toolbox: {
common: {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,9 @@ const message = {
lineHeight: 'Satır Yüksekliği',
letterSpacing: 'Harf Aralığı',
fontSize: 'Font Boyutu',
fontFamily: 'Özel yazı tipi',
fontFamilyHelper:
'Varsayılan yazı tiplerini kullanmak için boş bırakın. Özel bir yazı tipi adı girerseniz, yazı tipinin yerel işletim sisteminizde yüklü olduğundan emin olun, aksi takdirde varsayılan yazı tipiyle işlenecektir',
cursorBlink: 'İmleç Yanıp Sönme',
cursorStyle: 'İmleç Stili',
cursorUnderline: 'Alt Çizgi',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,9 @@ const message = {
lineHeight: '字體行高',
letterSpacing: '字體間距',
fontSize: '字體大小',
fontFamily: '自訂字體',
fontFamilyHelper:
'留空則使用預設字體。輸入自訂字體名稱後,需確保本機作業系統已安裝該字體,否則將使用預設字體渲染',
cursorBlink: '游標閃爍',
cursorStyle: '游標樣式',
cursorUnderline: '下劃線',
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,9 @@ const message = {
lineHeight: '字体行高',
letterSpacing: '字体间距',
fontSize: '字体大小',
fontFamily: '自定义字体',
fontFamilyHelper:
'留空则使用默认字体。输入自定义字体名后,需确保本地操作系统已安装该字体,否则将使用默认字体渲染',
cursorBlink: '光标闪烁',
cursorStyle: '光标样式',
cursorUnderline: '下划线',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/store/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface TerminalState {
lineHeight: number;
letterSpacing: number;
fontSize: number;
fontFamily: string;
cursorBlink: string;
cursorStyle: string;
scrollback: number;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/store/modules/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const TerminalStore = defineStore({
lineHeight: 1.2,
letterSpacing: 1.2,
fontSize: 12,
fontFamily: '',
cursorBlink: 'enable',
cursorStyle: 'underline',
scrollback: 1000,
Expand All @@ -23,6 +24,9 @@ export const TerminalStore = defineStore({
setFontSize(fontSize: number) {
this.fontSize = fontSize;
},
setFontFamily(fontFamily: string) {
this.fontFamily = fontFamily;
},
setCursorBlink(cursorBlink: string) {
this.cursorBlink = cursorBlink;
},
Expand Down
26 changes: 25 additions & 1 deletion frontend/src/views/terminal/setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@
@change="changeItem()"
/>
</el-form-item>
<el-form-item :label="$t('terminal.fontFamily')">
<el-input
class="formInput"
v-model="form.fontFamily"
:placeholder="$t('terminal.fontFamily')"
@change="changeItem()"
/>
<span class="input-help">{{ $t('terminal.fontFamilyHelper') }}</span>
</el-form-item>

<el-form-item>
<div class="terminal" ref="terminalElement"></div>
Expand Down Expand Up @@ -142,6 +151,7 @@ const form = reactive({
lineHeight: 1.2,
letterSpacing: 1.2,
fontSize: 12,
fontFamily: '',
cursorBlink: 'Enable',
cursorStyle: 'underline',
scrollback: 1000,
Expand All @@ -168,11 +178,15 @@ const search = async (withReset?: boolean) => {
form.lineHeight = Number(res.data.lineHeight);
form.letterSpacing = Number(res.data.letterSpacing);
form.fontSize = Number(res.data.fontSize);
form.fontFamily = res.data.fontFamily || '';
form.cursorBlink = res.data.cursorBlink;
form.cursorStyle = res.data.cursorStyle;
form.scrollback = Number(res.data.scrollback);
form.scrollSensitivity = Number(res.data.scrollSensitivity);

// 同步到 store,确保已打开的终端也能使用新字体
terminalStore.setFontFamily(res.data.fontFamily || '');

if (withReset) {
changeItem();
}
Expand Down Expand Up @@ -221,10 +235,13 @@ const submitChangeShow = async () => {
};

const iniTerm = () => {
const defaultFontFamily = "Monaco, Menlo, Consolas, 'Courier New', monospace";
const fontFamily = form.fontFamily || defaultFontFamily;

term.value = new Terminal({
lineHeight: 1.2,
fontSize: 12,
fontFamily: "Monaco, Menlo, Consolas, 'Courier New', monospace",
fontFamily: fontFamily,
theme: {
background: '#000000',
},
Expand All @@ -240,9 +257,13 @@ const iniTerm = () => {
};

const changeItem = () => {
const defaultFontFamily = "Monaco, Menlo, Consolas, 'Courier New', monospace";
const fontFamily = form.fontFamily || defaultFontFamily;

term.value.options.lineHeight = form.lineHeight;
term.value.options.letterSpacing = form.letterSpacing;
term.value.options.fontSize = form.fontSize;
term.value.options.fontFamily = fontFamily;
term.value.options.cursorBlink = form.cursorBlink === 'Enable';
term.value.options.cursorStyle = form.cursorStyle;
term.value.options.scrollback = form.scrollback;
Expand All @@ -255,6 +276,7 @@ const onSetDefault = () => {
form.lineHeight = 1.2;
form.letterSpacing = 0;
form.fontSize = 12;
form.fontFamily = '';
form.cursorBlink = 'Enable';
form.cursorStyle = 'block';
form.scrollback = 1000;
Expand All @@ -274,6 +296,7 @@ const onSave = () => {
lineHeight: form.lineHeight + '',
letterSpacing: form.letterSpacing + '',
fontSize: form.fontSize + '',
fontFamily: form.fontFamily,
cursorBlink: form.cursorBlink,
cursorStyle: form.cursorStyle,
scrollback: form.scrollback + '',
Expand All @@ -286,6 +309,7 @@ const onSave = () => {
terminalStore.setLineHeight(form.lineHeight);
terminalStore.setLetterSpacing(form.letterSpacing);
terminalStore.setFontSize(form.fontSize);
terminalStore.setFontFamily(form.fontFamily);
terminalStore.setCursorBlink(form.cursorBlink);
terminalStore.setCursorStyle(form.cursorStyle);
terminalStore.setScrollback(form.scrollback);
Expand Down
Loading