Skip to content

Commit

Permalink
Add remote message and update README.
Browse files Browse the repository at this point in the history
Date:      Sat Nov 18 15:17:36 2023 +0530
Committer: Divyanshu Agrawal <[email protected]>
  • Loading branch information
agrawal-d committed Nov 18, 2023
1 parent 6c55771 commit 7a50e94
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 43 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "GPL-3.0-or-later",
"icon": "icon.png",
"publisher": "DivyanshuAgrawal",
"version": "5.13.0",
"version": "5.14.0",
"engines": {
"vscode": "^1.52.0"
},
Expand Down Expand Up @@ -74,10 +74,10 @@
"default": 3000,
"description": "The time in ms for which a testcase is run before it is killed ( timed-out )."
},
"cph.general.zeroExitCodeIsWarning": {
"cph.general.hideStderrorWhenCompiledOK": {
"type": "boolean",
"default": false,
"description": "If enabled, zero exit code when compilation will be considered as warning and will not cause the compilation to fail."
"default": true,
"description": "Ignore and don't show stderror when compilation exit code is zero."
},
"cph.general.ignoreSTDERROR": {
"type": "boolean",
Expand Down
30 changes: 17 additions & 13 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spawn } from 'child_process';
import path from 'path';
import {
getSaveLocationPref,
getZeroExitCodeIsWarningPref,
getHideStderrorWhenCompiledOK,
} from './preferences';
import * as vscode from 'vscode';
import { getJudgeViewProvider } from './extension';
Expand Down Expand Up @@ -164,29 +164,33 @@ export const compileFile = async (srcPath: string): Promise<boolean> => {
});

compiler.on('exit', (exitcode) => {
if (
(!getZeroExitCodeIsWarningPref() || exitcode !== 0) &&
(exitcode === 1 || error !== '')
) {
ocWrite('Errors while compiling:\n' + error);
const exitCode = exitcode || 0;
const hideWarningsWhenCompiledOK = getHideStderrorWhenCompiledOK();

if (exitCode !== 0) {
ocWrite(
`Exit code: ${exitCode} Errors while compiling:\n` + error,
);
ocShow();
console.error('Compilation failed');
resolve(false);
getJudgeViewProvider().extensionToJudgeViewMessage({
command: 'compiling-stop',
});
getJudgeViewProvider().extensionToJudgeViewMessage({
command: 'not-running',
});
resolve(false);
return;
} else if (
getZeroExitCodeIsWarningPref() &&
exitcode === 0 &&
error !== ''
) {
ocWrite('Warnings while compiling:\n' + error);
}

if (!hideWarningsWhenCompiledOK && error.trim() !== '') {
ocWrite(
`Exit code: ${exitCode} Warnings while compiling:\n ` +
error,
);
ocShow();
}

console.log('Compilation passed');
getJudgeViewProvider().extensionToJudgeViewMessage({
command: 'compiling-stop',
Expand Down
4 changes: 2 additions & 2 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const getSaveLocationPref = (): string => {
return pref;
};

export const getZeroExitCodeIsWarningPref = (): string =>
getPreference('general.zeroExitCodeIsWarning');
export const getHideStderrorWhenCompiledOK = (): boolean =>
getPreference('general.hideStderrorWhenCompiledOK');

export const getIgnoreSTDERRORPref = (): string =>
getPreference('general.ignoreSTDERROR');
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type prefSection =
| 'general.saveLocation'
| 'general.defaultLanguage'
| 'general.timeOut'
| 'general.zeroExitCodeIsWarning'
| 'general.hideStderrorWhenCompiledOK'
| 'general.ignoreSTDERROR'
| 'general.firstTime'
| 'general.useShortCodeForcesName'
Expand Down
45 changes: 39 additions & 6 deletions src/webview/frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Judge(props: {
const [notification, setNotification] = useState<string | null>(null);
const [waitingForSubmit, setWaitingForSubmit] = useState<boolean>(false);
const [onlineJudgeEnv, setOnlineJudgeEnv] = useState<boolean>(false);
const [remoteMessage, setRemoteMessage] = useState<string>('');

// Update problem if cases change. The only place where `updateProblem` is
// allowed to ensure sync.
Expand All @@ -45,6 +46,21 @@ function Judge(props: {
});
}, [cases]);

useEffect(() => {
console.log('Fetching remote text message');
const url =
'https://github.com/agrawal-d/cph/raw/main/static/remote-message.txt';
try {
fetch(url, { mode: 'no-cors' }).then((response) => {
response.text().then((text) => {
setRemoteMessage(text);
});
});
} catch (err) {
console.error('Error fetching remote-message.txt: ', err);
}
}, []);

useEffect(() => {
const fn = (event: any) => {
const data: VSToWebViewMessage = event.data;
Expand Down Expand Up @@ -373,11 +389,28 @@ function Judge(props: {

<br />
<span onClick={toggleOnlineJudgeEnv}>
<input type="checkbox" checked={onlineJudgeEnv} />
<input
type="checkbox"
className="oj"
checked={onlineJudgeEnv}
/>
<span>
Set <code>ONLINE_JUDGE</code>
</span>
</span>
<br />
<br />
<div>
<small>
<a href="https://rb.gy/vw82u5" className="btn">
<i className="codicon codicon-feedback"></i>{' '}
Feedback
</a>
</small>
</div>
<div className="remote-message">
<p>{remoteMessage}</p>
</div>
</div>

<div className="actions">
Expand All @@ -390,7 +423,7 @@ function Judge(props: {
<span className="icon">
<i className="codicon codicon-debug-restart"></i>
</span>{' '}
Run All
<span className="action-text">Run All</span>
</button>
<button
className="btn btn-green"
Expand All @@ -400,7 +433,7 @@ function Judge(props: {
<span className="icon">
<i className="codicon codicon-add"></i>
</span>{' '}
New
<span className="action-text">New</span>
</button>
</div>
<div className="row">
Expand All @@ -412,7 +445,7 @@ function Judge(props: {
<span className="icon">
<i className="codicon codicon-circle-slash"></i>
</span>{' '}
Stop
<span className="action-text">Stop</span>
</button>
<a
className="btn"
Expand All @@ -422,7 +455,7 @@ function Judge(props: {
<span className="icon">
<i className="codicon codicon-question"></i>
</span>{' '}
Help
<span className="action-text">Help</span>
</a>
<button
className="btn btn-red right"
Expand All @@ -432,7 +465,7 @@ function Judge(props: {
<span className="icon">
<i className="codicon codicon-trash"></i>
</span>{' '}
Delete
<span className="action-text">Delete</span>
</button>
</div>
</div>
Expand Down
23 changes: 14 additions & 9 deletions src/webview/frontend/CaseView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,25 @@ export default function CaseView(props: {
</span>
</span>
)}
&nbsp;Testcase {props.num}
&nbsp;TC {props.num}
</span>
{running && <span className="running-text">Running</span>}
{result && !running && (
<span className="result-data">
<span
className={
result.pass ? 'result-pass' : 'result-fail'
}
>
{result.pass ? 'Passed' : 'Failed'}
<>
<span className="result-data">
<span
className={
result.pass
? 'result-pass'
: 'result-fail'
}
>
&nbsp; &nbsp;
{result.pass ? 'Passed' : 'Failed'}
</span>
</span>
<span className="exec-time">{timeText}</span>
</span>
</>
)}
</div>
<div className="time">
Expand Down
26 changes: 18 additions & 8 deletions src/webview/frontend/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ body {
max-width: 800px;
}

.oj {
vertical-align: bottom;
}

* {
border-radius: 2px;
}

#app {
margin-bottom: 100px;
}
Expand All @@ -51,7 +59,7 @@ body {
color: white;
padding: 2px 5px 2px 5px;
font-size: 80%;
border-radius: 5px;
border-radius: 4px;
}

a.btn {
Expand Down Expand Up @@ -177,7 +185,7 @@ textarea:active {

.btn {
padding: 2px 5px 2px 5px;
background: #3393cc91;
background: #2fadf5a7;
color: white;
outline: none;
margin-right: 4px;
Expand All @@ -192,16 +200,16 @@ textarea:active {
}

.btn-green {
background: #70b92791;
background: #8ae33291;
}
.btn-red {
background: #b9274391;
background: #eb244c91;
}
.btn:focus {
border-color: var(--vscode-focusBorder);
}
.btn-orange {
background: orange;
background: rgba(244, 164, 15, 0.781);
}

.btn-submit {
Expand Down Expand Up @@ -265,7 +273,6 @@ button:disabled {

.result-data {
font-size: 1.15em;
margin-left: 5px;
}

.result-pass {
Expand All @@ -291,7 +298,6 @@ button:disabled {

.case {
border-left: 5px solid var(--vscode-input-background);
border-radius: 0px;
}

.case.running {
Expand Down Expand Up @@ -398,7 +404,7 @@ body.vscode-light .case-number {
display: inline;
}

@media only screen and (max-width: 365px) {
@media only screen and (max-width: 370px) {
.actions {
border-top: 1px solid rgba(0, 0, 0, 0.5);
}
Expand Down Expand Up @@ -427,4 +433,8 @@ body.vscode-light .case-number {
.noSpaceWarning .ui {
display: block !important;
}

.action-text {
display: none;
}
}

0 comments on commit 7a50e94

Please sign in to comment.