Skip to content

Commit

Permalink
feat(statusline): combine status line items (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Sep 11, 2023
1 parent 7c9dc96 commit 7f0de58
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/status_line.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
import * as vscode from "vscode";
import { Disposable, StatusBarAlignment, StatusBarItem, window, workspace } from "vscode";

export class StatusLineController implements vscode.Disposable {
private modeItem: vscode.StatusBarItem;
private commandItem: vscode.StatusBarItem;
private msgItem: vscode.StatusBarItem;
// !Maybe we can support &statusline

export class StatusLineController implements Disposable {
private _modeText = "";
private _statusText = "";
private _msgText = "";
private _seperator = " - ";

private statusBar: StatusBarItem;

public constructor() {
this.modeItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 10);
this.commandItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 5);
this.msgItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1);
this.statusBar = window.createStatusBarItem(StatusBarAlignment.Left, 10);
this._seperator = workspace.getConfiguration("window").get("titleSeparator", this._seperator);
}

public set modeString(str: string) {
if (!str) {
this.modeItem.hide();
private refreshStatusBar() {

Check warning on line 18 in src/status_line.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macos-latest)

Missing return type on function

Check warning on line 18 in src/status_line.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Missing return type on function

Check warning on line 18 in src/status_line.ts

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

Missing return type on function
const items = [];
this._modeText.length && items.push(this._modeText);
this._statusText.length && items.push(this._statusText);
this._msgText.length && items.push(this._msgText);
if (items.length) {
this.statusBar.text = items.join(this._seperator);
this.statusBar.show();
} else {
this.modeItem.text = str;
this.modeItem.show();
this.statusBar.hide();
}
}

public set modeString(str: string) {
this._modeText = str;
this.refreshStatusBar();
}

public set statusString(str: string) {
if (!str) {
this.commandItem.hide();
} else {
this.commandItem.text = str;
this.commandItem.show();
}
this._statusText = str;
this.refreshStatusBar();
}

public set msgString(str: string) {
if (!str) {
this.msgItem.hide();
} else {
this.msgItem.text = str;
this.msgItem.show();
}
this._msgText = str;
this.refreshStatusBar();
}

public dispose(): void {
this.commandItem.dispose();
this.modeItem.dispose();
this.msgItem.dispose();
this.statusBar.dispose();
}
}

0 comments on commit 7f0de58

Please sign in to comment.