diff --git a/backend/types/preferences.go b/backend/types/preferences.go index 18b73ff..0a9d8ad 100644 --- a/backend/types/preferences.go +++ b/backend/types/preferences.go @@ -6,6 +6,7 @@ type Preferences struct { Behavior PreferencesBehavior `json:"behavior" yaml:"behavior"` General PreferencesGeneral `json:"general" yaml:"general"` Editor PreferencesEditor `json:"editor" yaml:"editor"` + Cli PreferencesCli `json:"cli" yaml:"cli"` } func NewPreferences() Preferences { @@ -28,6 +29,9 @@ func NewPreferences() Preferences { ShowLineNum: true, ShowFolding: true, }, + Cli: PreferencesCli{ + FontSize: consts.DEFAULT_FONT_SIZE, + }, } } @@ -61,3 +65,8 @@ type PreferencesEditor struct { ShowLineNum bool `json:"showLineNum" yaml:"show_line_num"` ShowFolding bool `json:"showFolding" yaml:"show_folding"` } + +type PreferencesCli struct { + FontFamily []string `json:"fontFamily" yaml:"font_family,omitempty"` + FontSize int `json:"fontSize" yaml:"font_size"` +} diff --git a/frontend/src/components/content_value/ContentCli.vue b/frontend/src/components/content_value/ContentCli.vue index 17532d3..ff20afb 100644 --- a/frontend/src/components/content_value/ContentCli.vue +++ b/frontend/src/components/content_value/ContentCli.vue @@ -32,10 +32,11 @@ let fitAddonInst = null * @return {{fitAddon: xterm-addon-fit.FitAddon, term: Terminal}} */ const newTerm = () => { + const { fontSize = 14, fontFamily = 'Courier New' } = prefStore.cliFont const term = new Terminal({ allowProposedApi: true, - fontFamily: prefStore.general.fontFamily, - fontSize: prefStore.general.fontSize || 14, + fontFamily, + fontSize, cursorBlink: true, disableStdin: false, screenReaderMode: true, @@ -90,21 +91,12 @@ defineExpose({ resizeTerm, }) -// watch( -// () => prefStore.general.font, -// (font = undefined) => { -// if (termInst != null) { -// termInst.options.fontFamily = font || 'Courier New' -// } -// resizeTerm() -// }, -// ) - watch( - () => prefStore.general.fontSize, - (fontSize) => { + () => prefStore.cliFont, + ({ fontSize = 14, fontFamily = 'Courier New' }) => { if (termInst != null) { termInst.options.fontSize = fontSize + termInst.options.fontFamily = fontFamily } resizeTerm() }, diff --git a/frontend/src/components/dialogs/PreferencesDialog.vue b/frontend/src/components/dialogs/PreferencesDialog.vue index 38e5645..7badefc 100644 --- a/frontend/src/components/dialogs/PreferencesDialog.vue +++ b/frontend/src/components/dialogs/PreferencesDialog.vue @@ -187,6 +187,36 @@ const onClose = () => { + + + + + + + + + + + + + + diff --git a/frontend/src/langs/en-us.json b/frontend/src/langs/en-us.json index 625d7c3..efa9178 100644 --- a/frontend/src/langs/en-us.json +++ b/frontend/src/langs/en-us.json @@ -54,6 +54,9 @@ "name": "Editor", "show_linenum": "Show Line Numbers", "show_folding": "Enable Code Folding" + }, + "cli": { + "name": "Command Line" } }, "interface": { diff --git a/frontend/src/langs/zh-cn.json b/frontend/src/langs/zh-cn.json index 319ef10..47ac8ef 100644 --- a/frontend/src/langs/zh-cn.json +++ b/frontend/src/langs/zh-cn.json @@ -54,6 +54,9 @@ "name": "编辑器", "show_linenum": "显示行号", "show_folding": "启用代码折叠" + }, + "cli": { + "name": "命令行" } }, "interface": { diff --git a/frontend/src/stores/preferences.js b/frontend/src/stores/preferences.js index 71b0030..a7f027a 100644 --- a/frontend/src/stores/preferences.js +++ b/frontend/src/stores/preferences.js @@ -59,6 +59,10 @@ const usePreferencesStore = defineStore('preferences', { showLineNum: true, showFolding: true, }, + cli: { + fontFamily: [], + fontSize: 14, + }, lastPref: {}, fontList: [], }), @@ -167,6 +171,26 @@ const usePreferencesStore = defineStore('preferences', { return fontStyle }, + /** + * current cli font + * @return {{fontSize: string, fontFamily?: string}} + */ + cliFont() { + const fontStyle = { + fontSize: this.cli.fontSize || 14, + } + if (!isEmpty(this.cli.fontFamily)) { + fontStyle['fontFamily'] = join( + map(this.cli.fontFamily, (f) => `"${f}"`), + ',', + ) + } + if (isEmpty(fontStyle['fontFamily'])) { + fontStyle['fontFamily'] = ['Courier New'] + } + return fontStyle + }, + /** * get current language setting * @return {string} @@ -264,7 +288,7 @@ const usePreferencesStore = defineStore('preferences', { * @returns {Promise} */ async savePreferences() { - const pf = pick(this, ['behavior', 'general', 'editor']) + const pf = pick(this, ['behavior', 'general', 'editor', 'cli']) const { success, msg } = await SetPreferences(pf) return success === true },