From 1eb1ef713b7e117b9bbdcffd19cc9f56bae212db Mon Sep 17 00:00:00 2001 From: Divyanshu Agrawal Date: Sat, 18 Nov 2023 15:17:36 +0530 Subject: [PATCH] Add remote message and update README. Date: Sat Nov 18 15:17:36 2023 +0530 Committer: Divyanshu Agrawal --- README.md | 13 ++++----- package.json | 8 +++--- src/compiler.ts | 30 ++++++++++++--------- src/preferences.ts | 4 +-- src/types.ts | 2 +- src/webview/frontend/App.tsx | 45 ++++++++++++++++++++++++++----- src/webview/frontend/CaseView.tsx | 23 +++++++++------- src/webview/frontend/app.css | 26 ++++++++++++------ static/remote-message.txt | 1 + 9 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 static/remote-message.txt diff --git a/README.md b/README.md index 129907a..37aa527 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,12 @@ [![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fagrawal-d%2Fcph%2Fbadge%3Fref%3Dmain&style=flat)](https://actions-badge.atrox.dev/agrawal-d/cph/goto?ref=main) [![Downloads](https://img.shields.io/visual-studio-marketplace/d/DivyanshuAgrawal.competitive-programming-helper)](https://marketplace.visualstudio.com/items?itemName=DivyanshuAgrawal.competitive-programming-helper) -This extension allows you to quickly compile, run and judge competitive -programming problems from within VS Code. You can automatically download -testcases write & test your own problems. Once you are done, you can submit your -solutions directly with the click of a button! +Quickly compile, run and judge competitive programming problems in VS Code. +Automatically download testcases , or write & test your own problems. +Once you are done, easily your solutions directly with the click of a button! -Using the competitive companion browser extension, cph supports a large number -of popular platforms like Codeforces, Codechef, TopCoder etc. +Cph supports a large number of popular platforms like Codeforces, Codechef, TopCoder etc. +with the help of competitive companion browser extension ![Screenshot](screenshots/screenshot-main.png) @@ -66,8 +65,6 @@ You can contribute to this extension in many ways: **Before creating a Pull Request, please create an issue to discuss the approach. It makes reviewing and accepting the PR much easier.** -Since July 2023, CPH is being maintained by @tesla59. - ## License Copyright (C) 2023 Divyanshu Agrawal diff --git a/package.json b/package.json index ec09d4f..0f625ec 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/src/compiler.ts b/src/compiler.ts index c5dd72d..234f2f3 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -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'; @@ -164,29 +164,33 @@ export const compileFile = async (srcPath: string): Promise => { }); 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', diff --git a/src/preferences.ts b/src/preferences.ts index d6afa1e..ade807a 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -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'); diff --git a/src/types.ts b/src/types.ts index c53c130..b0a9288 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,7 +3,7 @@ export type prefSection = | 'general.saveLocation' | 'general.defaultLanguage' | 'general.timeOut' - | 'general.zeroExitCodeIsWarning' + | 'general.hideStderrorWhenCompiledOK' | 'general.ignoreSTDERROR' | 'general.firstTime' | 'general.useShortCodeForcesName' diff --git a/src/webview/frontend/App.tsx b/src/webview/frontend/App.tsx index 8500152..0d885b3 100644 --- a/src/webview/frontend/App.tsx +++ b/src/webview/frontend/App.tsx @@ -34,6 +34,7 @@ function Judge(props: { const [notification, setNotification] = useState(null); const [waitingForSubmit, setWaitingForSubmit] = useState(false); const [onlineJudgeEnv, setOnlineJudgeEnv] = useState(false); + const [remoteMessage, setRemoteMessage] = useState(''); // Update problem if cases change. The only place where `updateProblem` is // allowed to ensure sync. @@ -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; @@ -373,11 +389,28 @@ function Judge(props: {
- + Set ONLINE_JUDGE +
+
+ +
+

{remoteMessage}

+
@@ -390,7 +423,7 @@ function Judge(props: { {' '} - Run All + Run All
@@ -412,7 +445,7 @@ function Judge(props: { {' '} - Stop + Stop {' '} - Help + Help
diff --git a/src/webview/frontend/CaseView.tsx b/src/webview/frontend/CaseView.tsx index ec97912..2f406fd 100644 --- a/src/webview/frontend/CaseView.tsx +++ b/src/webview/frontend/CaseView.tsx @@ -137,20 +137,25 @@ export default function CaseView(props: { )} -  Testcase {props.num} +  TC {props.num} {running && Running} {result && !running && ( - - - {result.pass ? 'Passed' : 'Failed'} + <> + + +     + {result.pass ? 'Passed' : 'Failed'} + {timeText} - + )}
diff --git a/src/webview/frontend/app.css b/src/webview/frontend/app.css index 9287f18..a21bc4b 100644 --- a/src/webview/frontend/app.css +++ b/src/webview/frontend/app.css @@ -25,6 +25,14 @@ body { max-width: 800px; } +.oj { + vertical-align: bottom; +} + +* { + border-radius: 2px; +} + #app { margin-bottom: 100px; } @@ -51,7 +59,7 @@ body { color: white; padding: 2px 5px 2px 5px; font-size: 80%; - border-radius: 5px; + border-radius: 4px; } a.btn { @@ -177,7 +185,7 @@ textarea:active { .btn { padding: 2px 5px 2px 5px; - background: #3393cc91; + background: #2fadf5a7; color: white; outline: none; margin-right: 4px; @@ -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 { @@ -265,7 +273,6 @@ button:disabled { .result-data { font-size: 1.15em; - margin-left: 5px; } .result-pass { @@ -291,7 +298,6 @@ button:disabled { .case { border-left: 5px solid var(--vscode-input-background); - border-radius: 0px; } .case.running { @@ -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); } @@ -427,4 +433,8 @@ body.vscode-light .case-number { .noSpaceWarning .ui { display: block !important; } + + .action-text { + display: none; + } } diff --git a/static/remote-message.txt b/static/remote-message.txt new file mode 100644 index 0000000..486e2cf --- /dev/null +++ b/static/remote-message.txt @@ -0,0 +1 @@ +©️ Divyanshu Agrawal. AGPL-3 software. \ No newline at end of file