-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: add custom themes for runner * fix: add the :theme command * fix: add readme about theme
- Loading branch information
1 parent
44af7ab
commit e968b41
Showing
10 changed files
with
292 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/** | ||
* Override themes for your terminal here | ||
* See default here: https://github.com/mterm-io/mterm/blob/main/src/renderer/src/assets/runner.css | ||
*/ | ||
|
||
/* | ||
* prepend .runner-container__commander_mode | ||
* to apply styles only for commander mode | ||
*/ | ||
.runner-container { | ||
background: rgba(27, 27, 31, 0.89); | ||
color: white; | ||
} | ||
.runner-container__commander_mode .runner-result { | ||
} | ||
|
||
.runner-input-container { | ||
} | ||
|
||
.runner-input { | ||
} | ||
|
||
.runner-input-field { | ||
} | ||
|
||
.runner-input-field { | ||
} | ||
.runner-input-field:focus { | ||
} | ||
|
||
.runner-container { | ||
} | ||
|
||
.runner-tabs { | ||
} | ||
|
||
.runner-tabs-title { | ||
} | ||
|
||
.runner-tabs-title-active { | ||
} | ||
.runner-spacer { | ||
} | ||
|
||
.runner-context { | ||
} | ||
|
||
.runner-main { | ||
} | ||
|
||
.runner-editor { | ||
} | ||
|
||
|
||
.runner-editor-header { | ||
} | ||
|
||
.runner-editor-header-result { | ||
} | ||
.runner-editor-header-result::-webkit-scrollbar { | ||
} | ||
.runner-editor-header-result::-webkit-scrollbar-corner { | ||
} | ||
.runner-editor-header-result::-webkit-scrollbar-thumb { | ||
} | ||
.runner-editor-header-result pre { | ||
} | ||
.runner-context-folder { | ||
} | ||
|
||
.runner-history { | ||
} | ||
|
||
.runner-history::-webkit-scrollbar { | ||
} | ||
.runner-history::-webkit-scrollbar-corner { | ||
} | ||
.runner-history::-webkit-scrollbar-thumb { | ||
} | ||
.runner-history-item { | ||
} | ||
.runner-history-item:hover { | ||
} | ||
.runner-history-selected { | ||
} | ||
.runner-history-running { | ||
} | ||
.runner-history-complete { | ||
} | ||
.runner-history-aborted { | ||
} | ||
.runner-history-error { | ||
} | ||
|
||
.runner-history::-webkit-scrollbar-track { | ||
} | ||
|
||
.runner-result-error { | ||
} | ||
.runner-result { | ||
} | ||
|
||
.space { | ||
} | ||
.runner-info { | ||
} | ||
.toggle-button-slider { | ||
} | ||
.toggle-button-circle { | ||
} | ||
.toggle-button { | ||
} | ||
.toggle-button-spacer { | ||
} | ||
.toggle-button.toggle-button-on .toggle-button-slider { | ||
} | ||
|
||
.runner-result::-webkit-scrollbar { | ||
} | ||
.runner-result::-webkit-scrollbar-corner { | ||
} | ||
.runner-result::-webkit-scrollbar-thumb { | ||
} | ||
.contextmenu.tab-context-menu { | ||
} | ||
.tab-context-menu > .contextmenu__item { | ||
} | ||
.tab-context-menu > .contextmenu__item:hover { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ExecuteContext } from '../execute-context' | ||
import { errorModal } from '../../index' | ||
|
||
export default { | ||
command: ':theme', | ||
alias: [':css'], | ||
async task(context: ExecuteContext, task?: string): Promise<void> { | ||
context.out('') | ||
if (!task) { | ||
if (!context.profile) { | ||
context.out( | ||
'No profile file to edit, make sure your ~/mterm/settings.json defaultProfile is set' | ||
) | ||
return | ||
} | ||
|
||
const profileThemeLocation = context.workspace.theme.getProfileThemeLocation(context.profile) | ||
if (!profileThemeLocation) { | ||
context.out( | ||
'No theme location was found for the default profile, please check your settings!' | ||
) | ||
return | ||
} | ||
|
||
await context.edit(profileThemeLocation, async () => { | ||
context.out('Saved theme file!\n') | ||
|
||
try { | ||
await context.workspace.theme.load() | ||
} catch (e) { | ||
console.log(e) | ||
await errorModal.showError(e) | ||
} | ||
|
||
context.out('Theme reloaded\n') | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Workspace } from './workspace' | ||
import { ProfileMap } from './runtime' | ||
import { DEFAULT_PROFILE, DEFAULT_PROFILES } from '../../constants' | ||
import { pathExists, readFile, writeFile } from 'fs-extra' | ||
import { log } from '../logger' | ||
|
||
export class Theme { | ||
public themes: Map<string, string> = new Map() | ||
constructor( | ||
public workspace: Workspace, | ||
public defaultThemeLocation: string | ||
) {} | ||
|
||
getProfileThemeLocation(profileKey: string): string { | ||
const profiles = this.workspace.settings.get<ProfileMap>('profiles', DEFAULT_PROFILES) | ||
if (profileKey === 'default') { | ||
profileKey = this.workspace.settings.get<string>('defaultProfile', DEFAULT_PROFILE) | ||
} | ||
let theme = profiles[profileKey]?.theme | ||
if (theme) { | ||
theme = this.workspace.resolve(theme) | ||
} | ||
return theme | ||
} | ||
async load(): Promise<void> { | ||
this.themes.clear() | ||
//get profiles | ||
const profiles = this.workspace.settings.get<ProfileMap>('profiles', DEFAULT_PROFILES) | ||
const cache = {} | ||
|
||
const getDefaultTheme = async (): Promise<string> => { | ||
if (cache[this.defaultThemeLocation]) { | ||
return cache[this.defaultThemeLocation] | ||
} | ||
|
||
const cssBuffer = await readFile(this.defaultThemeLocation) | ||
const css = cssBuffer.toString() | ||
|
||
cache[this.defaultThemeLocation] = css | ||
|
||
return css | ||
} | ||
|
||
for (const profileKey in profiles) { | ||
const profile = profiles[profileKey] | ||
const cssFileLocation = this.workspace.resolve(profile.theme) | ||
|
||
let css = cache[cssFileLocation] | ||
if (!css) { | ||
const isExist = await pathExists(cssFileLocation) | ||
if (!isExist) { | ||
log( | ||
`profile = ${profileKey} is mapped to css file @ ${profile.theme}. could not find @ ${cssFileLocation} - creating default` | ||
) | ||
css = await getDefaultTheme() | ||
|
||
await writeFile(cssFileLocation, css, 'utf-8') | ||
} else { | ||
const cssFileBuffer = await readFile(cssFileLocation) | ||
css = cssFileBuffer.toString() | ||
} | ||
|
||
cache[cssFileLocation] = css | ||
} | ||
|
||
this.themes.set(profileKey, css) | ||
} | ||
} | ||
|
||
get(profileKey: string): string { | ||
if (profileKey === 'default') { | ||
profileKey = this.workspace.settings.get<string>('defaultProfile', DEFAULT_PROFILE) | ||
} | ||
return this.themes.get(profileKey) || '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters