Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to change status bar color based on mode #1529

Merged
merged 3 commits into from
Apr 19, 2017
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ VSCodeVim is a [Visual Studio Code](https://code.visualstudio.com/) extension th
* The [EasyMotion plugin](#how-to-use-easymotion)
* The [Surround.vim plugin](#how-to-use-surround)
* The [Commentary plugin](#how-to-use-commentary)
* The [Vim-airline plugin](#statusbarcolorcontrol)
* And much more! Refer to the [roadmap](ROADMAP.md) or everything we support.

Please [report missing features/bugs on GitHub](https://github.com/VSCodeVim/Vim/issues), which will help us get to them faster.
Expand Down Expand Up @@ -213,6 +214,25 @@ Or bind ctrl+n to turn off search highlighting and `<leader>w` to save the curre
* Use a non-blinking block cursor
* Type: Boolean (Default: `false`)


#### statusBarColorControl
* Control status bar color based on current mode
* Type: Boolean (Default: `false`)

Once this is set, you need to set statusBarColors as well with these exact strings for modenames. The colors can be adjusted to suit the user.

```
"vim.statusBarColorControl": true,
"vim.statusBarColors" : {
"normal": "#005f5f",
"insert": "#5f0000",
"visual": "#5f00af",
"visualline": "#005f87",
"visualblock": "#86592d",
"replace": "#000000"
}
```

### Vim settings we support

#### ignorecase
Expand Down
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@
"vim.handleKeys": {
"type": "object",
"description": "Option to delegate certain key combinations back to VSCode to be handled natively"
},
"vim.statusBarColorControl":{
"type": "boolean",
"description": "Allow VSCodeVim to change status bar color based on mode"
},
"vim.statusBarColors": {
"type": "object",
"description": "Customize colors per mode when VSCodeVim controls status bar colors"
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface IHandleKeys {
[key: string]: boolean;
}

export interface IStatusBarColors {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can actually do a more precise type here e.g.

interfcae IStatusBarColors {
    normal: string,
    visual: string,
    // ...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For super mega bonus points you could use TypeScript's mapped types to ENSURE that every mode has a color by mapping from our ModeNames object. Sort of like this:

interface IStatusBarColors { [Key in keyof ModeNames]: string }

Mapped types are awesome.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes that is a good idea instead of string, string for sure

[key: string]: string;
}

/**
* Every Vim option we support should
* 1. Be added to contribution section of `package.json`.
Expand Down Expand Up @@ -215,6 +219,16 @@ class ConfigurationClass {
*/
startInInsertMode = false;

/**
* Start in insert mode?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to update the docstring here. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looking out for me :)

*/
statusBarColorControl = false;

/**
* Status bar colors to change to based on mode
*/
statusBarColors: IStatusBarColors = {};

/**
* Color of search highlights.
*/
Expand Down
18 changes: 17 additions & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1795,12 +1795,19 @@ export class ModeHandler implements vscode.Disposable {

this._vimState.editor.setDecorations(this._searchHighlightDecoration, searchRanges);


for (let i = 0; i < this.vimState.postponedCodeViewChanges.length; i++) {
let viewChange = this.vimState.postponedCodeViewChanges[i];
await vscode.commands.executeCommand(viewChange.command, viewChange.args);
}

// If user wants to change status bar color based on mode
if (Configuration.statusBarColorControl) {
let colorToSet = Configuration.statusBarColors[this._vimState.currentModeName().toLowerCase()];
if (colorToSet !== undefined) {
this.setStatusBarColor(colorToSet);
}
}

this.vimState.postponedCodeViewChanges = [];

if (this.currentMode.name === ModeName.SearchInProgressMode) {
Expand Down Expand Up @@ -1863,6 +1870,15 @@ export class ModeHandler implements vscode.Disposable {
ModeHandler._statusBarItem.show();
}

setStatusBarColor(color: string): void {
vscode.workspace.getConfiguration("workbench.experimental").update("colorCustomizations",
{
"statusBarBackground": `${color}`,
"statusBarNoFolderBackground": `${color}`,
"statusBarDebuggingBackground": `${color}`
});
}

// Return true if a new undo point should be created based on brackets and parenthesis
private createUndoPointForBrackets(vimState: VimState): boolean {
// }])> keys all start a new undo state when directly next to an {[(< opening character
Expand Down