Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/media-preview/src/binarySizeStatusBarEntry.ts
4772 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as vscode from 'vscode';
7
import { PreviewStatusBarEntry } from './ownedStatusBarEntry';
8
9
10
class BinarySize {
11
static readonly KB = 1024;
12
static readonly MB = BinarySize.KB * BinarySize.KB;
13
static readonly GB = BinarySize.MB * BinarySize.KB;
14
static readonly TB = BinarySize.GB * BinarySize.KB;
15
16
static formatSize(size: number): string {
17
if (size < BinarySize.KB) {
18
return vscode.l10n.t("{0}B", size);
19
}
20
21
if (size < BinarySize.MB) {
22
return vscode.l10n.t("{0}KB", (size / BinarySize.KB).toFixed(2));
23
}
24
25
if (size < BinarySize.GB) {
26
return vscode.l10n.t("{0}MB", (size / BinarySize.MB).toFixed(2));
27
}
28
29
if (size < BinarySize.TB) {
30
return vscode.l10n.t("{0}GB", (size / BinarySize.GB).toFixed(2));
31
}
32
33
return vscode.l10n.t("{0}TB", (size / BinarySize.TB).toFixed(2));
34
}
35
}
36
37
export class BinarySizeStatusBarEntry extends PreviewStatusBarEntry {
38
39
constructor() {
40
super('status.imagePreview.binarySize', vscode.l10n.t("Image Binary Size"), vscode.StatusBarAlignment.Right, 100);
41
}
42
43
public show(owner: unknown, size: number | undefined) {
44
if (typeof size === 'number') {
45
super.showItem(owner, BinarySize.formatSize(size));
46
} else {
47
this.hide(owner);
48
}
49
}
50
}
51
52