add profiles to config

This commit is contained in:
Labhansh Agrawal 2023-06-29 11:51:51 +05:30
parent 632bc73053
commit f0316e90c9
12 changed files with 533 additions and 378 deletions

92
lib/config.d.ts vendored
View file

@ -19,7 +19,44 @@ export type ColorMap = {
yellow: string;
};
export type configOptions = {
type profileConfigOptions = {
/** for environment variables */
env: {[k: string]: string};
/**
* the shell to run when spawning a new session (e.g. /usr/local/bin/fish)
* if left empty, your system's login shell will be used by default
*
* Windows
* - Make sure to use a full path if the binary name doesn't work
* - Remove `--login` in shellArgs
*
* Windows Subsystem for Linux (WSL) - previously Bash on Windows
* - Example: `C:\\Windows\\System32\\wsl.exe`
*
* Git-bash on Windows
* - Example: `C:\\Program Files\\Git\\bin\\bash.exe`
*
* PowerShell on Windows
* - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
*
* Cygwin
* - Example: `C:\\cygwin64\\bin\\bash.exe`
*
* Git Bash
* - Example: `C:\\Program Files\\Git\\git-cmd.exe`
* Then Add `--command=usr/bin/bash.exe` to shellArgs
*/
shell: string;
/**
* for setting shell arguments (e.g. for using interactive shellArgs: `['-i']`)
* by default `['--login']` will be used
*/
shellArgs: string[];
/** set custom startup directory (must be an absolute path) */
workingDirectory: string;
};
type rootConfigOptions = {
/**
* if `true` (default), Hyper will update plugins every 5 hours
* you can also set it to a custom time e.g. `1d` or `2h`
@ -74,8 +111,6 @@ export type configOptions = {
disableAutoUpdates: boolean;
/** if `false` Hyper will use ligatures provided by some fonts */
disableLigatures: boolean;
/** for environment variables */
env: {[k: string]: string};
/** font family with optional fallbacks */
fontFamily: string;
/** default font size in pixels for all tabs */
@ -122,36 +157,6 @@ export type configOptions = {
scrollback: number;
/** terminal selection color */
selectionColor: string;
/**
* the shell to run when spawning a new session (e.g. /usr/local/bin/fish)
* if left empty, your system's login shell will be used by default
*
* Windows
* - Make sure to use a full path if the binary name doesn't work
* - Remove `--login` in shellArgs
*
* Windows Subsystem for Linux (WSL) - previously Bash on Windows
* - Example: `C:\\Windows\\System32\\wsl.exe`
*
* Git-bash on Windows
* - Example: `C:\\Program Files\\Git\\bin\\bash.exe`
*
* PowerShell on Windows
* - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
*
* Cygwin
* - Example: `C:\\cygwin64\\bin\\bash.exe`
*
* Git Bash
* - Example: `C:\\Program Files\\Git\\git-cmd.exe`
* Then Add `--command=usr/bin/bash.exe` to shellArgs
*/
shell: string;
/**
* for setting shell arguments (e.g. for using interactive shellArgs: `['-i']`)
* by default `['--login']` will be used
*/
shellArgs: string[];
/**
* if you're using a Linux setup which show native menus, set to false
*
@ -184,10 +189,27 @@ export type configOptions = {
webLinksActivationKey: 'ctrl' | 'alt' | 'meta' | 'shift' | '';
/** Initial window size in pixels */
windowSize?: [number, number];
/** set custom startup directory (must be an absolute path) */
workingDirectory: string;
};
export type configOptions = rootConfigOptions &
profileConfigOptions & {
/**
* The default profile name to use when launching a new session
*/
defaultProfile: string;
/**
* A list of profiles to use
*/
profiles: {
name: string;
/**
* Specify all the options you want to override for each profile.
* Options set here override the defaults set in the root.
*/
config: Partial<profileConfigOptions>;
}[];
};
export type rawConfig = {
config?: configOptions;
/**

4
lib/hyper.d.ts vendored
View file

@ -39,7 +39,7 @@ export type ITermState = Immutable<{
export type cursorShapes = 'BEAM' | 'UNDERLINE' | 'BLOCK';
import type {FontWeight, IWindowsPty, Terminal} from 'xterm';
import type {ColorMap} from './config';
import type {ColorMap, configOptions} from './config';
export type uiState = Immutable<{
_lastUpdate: number | null;
@ -105,6 +105,8 @@ export type uiState = Immutable<{
webGLRenderer: boolean;
webLinksActivationKey: 'ctrl' | 'alt' | 'meta' | 'shift' | '';
windowsPty?: IWindowsPty;
defaultProfile: string;
profiles: configOptions['profiles'];
}>;
export type session = {

View file

@ -113,7 +113,9 @@ const initial: uiState = Immutable<Mutable<uiState>>({
webLinksActivationKey: '',
macOptionSelectionMode: 'vertical',
disableLigatures: true,
screenReaderMode: false
screenReaderMode: false,
defaultProfile: '',
profiles: []
});
const reducer: IUiReducer = (state = initial, action) => {
@ -287,6 +289,14 @@ const reducer: IUiReducer = (state = initial, action) => {
ret.imageSupport = config.imageSupport;
}
if (config.defaultProfile !== undefined) {
ret.defaultProfile = config.defaultProfile;
}
if (config.profiles !== undefined) {
ret.profiles = config.profiles;
}
ret._lastUpdate = now;
return ret;

View file

@ -5,7 +5,7 @@ import {require as remoteRequire} from '@electron/remote';
const plugins = remoteRequire('./plugins') as typeof import('../../app/plugins');
export function getConfig() {
return plugins.getDecoratedConfig();
return plugins.getDecoratedConfig(plugins.getDefaultProfile());
}
export function subscribe(fn: (event: Electron.IpcRendererEvent, ...args: any[]) => void) {