Skip to content

Commit bccc985

Browse files
committed
1 parent 57cbd5e commit bccc985

5 files changed

Lines changed: 64 additions & 21 deletions

File tree

‎package.json‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,35 @@
240240
"type": "array",
241241
"default": [],
242242
"description": "Excluded hosts when using using proxy settings"
243+
},
244+
"rest-client.fontSize": {
245+
"type": "number",
246+
"default": null,
247+
"description": "Controls the font size in pixels used in the response preview"
248+
},
249+
"rest-client.fontFamily": {
250+
"type": "string",
251+
"default": null,
252+
"description": "Controls the font family used in the response preview"
253+
},
254+
"rest-client.fontWeight": {
255+
"type": "string",
256+
"enum": [
257+
"normal",
258+
"bold",
259+
"bolder",
260+
"lighter",
261+
"100",
262+
"200",
263+
"300",
264+
"400",
265+
"500",
266+
"600",
267+
"700",
268+
"800",
269+
"900"
270+
],
271+
"description": "Controls the font weight used in the response preview"
243272
}
244273
}
245274
}

‎src/controllers/requestController.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class RequestController {
3939
this._restClientSettings = new RestClientSettings();
4040
this._httpClient = new HttpClient(this._restClientSettings);
4141

42-
this._responseTextProvider = new HttpResponseTextDocumentContentProvider(null);
42+
this._responseTextProvider = new HttpResponseTextDocumentContentProvider(null, this._restClientSettings);
4343
this._registration = workspace.registerTextDocumentContentProvider('rest-response', this._responseTextProvider);
4444
}
4545

‎src/models/configurationSettings.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export interface IRestClientSettings {
1010
rememberCookiesForSubsequentRequests: boolean;
1111
enableTelemetry: boolean;
1212
excludeHostsForProxy: string[];
13+
fontSize?: number;
14+
fontFamily: string;
15+
fontWeight: string;
1316
}
1417

1518
export class RestClientSettings implements IRestClientSettings {
@@ -22,6 +25,9 @@ export class RestClientSettings implements IRestClientSettings {
2225
rememberCookiesForSubsequentRequests: boolean;
2326
enableTelemetry: boolean;
2427
excludeHostsForProxy: string[];
28+
fontSize?: number;
29+
fontFamily: string;
30+
fontWeight: string;
2531

2632
constructor() {
2733
workspace.onDidChangeConfiguration(() => {
@@ -42,6 +48,9 @@ export class RestClientSettings implements IRestClientSettings {
4248
this.timeoutInMilliseconds = 0;
4349
}
4450
this.excludeHostsForProxy = restClientSettings.get<string[]>("excludeHostsForProxy", []);
51+
this.fontSize = restClientSettings.get<number>("fontSize", null);
52+
this.fontFamily = restClientSettings.get<string>("fontFamily", null);
53+
this.fontWeight = restClientSettings.get<string>("fontWeight", null);
4554

4655
let httpSettings = workspace.getConfiguration('http');
4756
this.proxy = httpSettings.get<string>('proxy', undefined);

‎src/views/httpResponseTextDocumentContentProvider.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { Uri, window, extensions } from 'vscode';
44
import { BaseTextDocumentContentProvider } from './baseTextDocumentContentProvider';
5+
import { RestClientSettings } from '../models/configurationSettings';
56
import { HttpResponse } from '../models/httpResponse';
67
import { MimeUtility } from '../mimeUtility';
78
import * as Constants from '../constants';
@@ -16,10 +17,12 @@ export class HttpResponseTextDocumentContentProvider extends BaseTextDocumentCon
1617
private static cssFilePath: string = path.join(extensions.getExtension(Constants.ExtensionId).extensionPath, Constants.CSSFolderName, Constants.CSSFileName);
1718

1819
response: HttpResponse;
20+
settings: RestClientSettings;
1921

20-
constructor(response: HttpResponse) {
22+
constructor(response: HttpResponse, settings: RestClientSettings) {
2123
super();
2224
this.response = response;
25+
this.settings = settings;
2326
}
2427

2528
public provideTextDocumentContent(uri: Uri): string {
@@ -40,6 +43,7 @@ ${HttpResponseTextDocumentContentProvider.formatBody(this.response.body, this.re
4043
return `
4144
<head>
4245
<link rel="stylesheet" href="${HttpResponseTextDocumentContentProvider.cssFilePath}">
46+
${this.getSettingsOverrideStyles()}
4347
</head>
4448
<body>
4549
<div>
@@ -49,6 +53,17 @@ ${HttpResponseTextDocumentContentProvider.formatBody(this.response.body, this.re
4953
}
5054
}
5155

56+
private getSettingsOverrideStyles(): string {
57+
return [
58+
'<style>',
59+
'code {',
60+
this.settings.fontFamily ? `font-family: ${this.settings.fontFamily}` : '',
61+
this.settings.fontSize ? `font-size: ${this.settings.fontSize}px;` : '',
62+
this.settings.fontWeight ? `font-weight: ${this.settings.fontWeight}` : '',
63+
'}',
64+
'</style>'].join('\n');
65+
}
66+
5267
private static formatHeaders(headers: { [key: string]: string }): string {
5368
let headerString = '';
5469
for (var header in headers) {

‎styles/rest-client.css‎

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ body.vscode-light {
33
}
44

55
body.vscode-dark {
6-
background-color: inherit
6+
background-color: inherit;
77
}
88

99
body.vscode-high-contrast {
10-
background-color: inherit
10+
background-color: inherit;
1111
}
1212

1313
.vscode-light pre .hljs-attribute {
@@ -73,37 +73,27 @@ body.vscode-high-contrast {
7373
color: #ebbbff;
7474
}
7575

76-
.vscode-light pre code {
76+
code {
7777
display: block;
7878
background: inherit;
79-
color: #4d4d4c;
80-
font-family: Menlo, Monaco, Consolas, monospace;
79+
font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
80+
font-size: 13px;
8181
line-height: 1.5;
8282
padding: 10px;
8383
white-space: pre-wrap;
8484
word-break: break-all;
8585
}
8686

87+
.vscode-light pre code {
88+
color: #4d4d4c;
89+
}
90+
8791
.vscode-dark pre code {
88-
display: block;
89-
background: inherit;
9092
color: #c5c8c6;
91-
font-family: Menlo, Monaco, Consolas, monospace;
92-
line-height: 1.5;
93-
padding: 10px;
94-
white-space: pre-wrap;
95-
word-break: break-all;
9693
}
9794

9895
.vscode-high-contrast pre code {
99-
display: block;
100-
background: inherit;
10196
color: white;
102-
font-family: Menlo, Monaco, Consolas, monospace;
103-
line-height: 1.5;
104-
padding: 10px;
105-
white-space: pre-wrap;
106-
word-break: break-all;
10797
}
10898

10999
code .line {

0 commit comments

Comments
 (0)