@@ -45,6 +45,7 @@ const languages = [
4545 name : "Urdu" ,
4646 i18nName : "اردو" ,
4747 direction : "rtl" ,
48+ fontFamily : "'Kawkab Mono'" ,
4849 style : {
4950 direction : "rtl"
5051 }
@@ -64,13 +65,15 @@ const languages = [
6465 code2 : "en" ,
6566 name : "English" ,
6667 i18nName : "English" ,
68+ fontFamily : "'Hack', 'Courier New', monospaced"
6769 }
6870]
6971
7072
7173const IDE = ( { basicSetup, ...props } ) => {
7274
73- const { isDarkTheme } = useColorMode ( ) ;
75+ const { colorMode } = useColorMode ( ) ;
76+ const isDarkTheme = colorMode === "dark" ;
7477 const [ editorCode , setEditorCode ] = useState ( initialCodes [ 1 ] . en ) ;
7578 const [ code , setCode ] = useState ( initialCodes [ 1 ] . en ) ;
7679
@@ -140,27 +143,27 @@ const initialCodes = [
140143 {
141144 id : "hello_world" ,
142145 name : "Simple Hello World" ,
143- en : `display ("Hello world!")`
146+ en : `print ("Hello world!")`
144147 } ,
145148 {
146149 id : "conditionals" ,
147150 name : "If/Else" ,
148151 en : `something = 2
149152
150153if something == 1:
151- display ("Hello")
154+ print ("Hello")
152155elif something == 2:
153- display ("World")
156+ print ("World")
154157else:
155- display ("Didn't understand...")`
158+ print ("Didn't understand...")`
156159 } ,
157160 {
158161 id : "loop" ,
159162 name : "Loop" ,
160163 en : `things = ['💻', '📷', '🧸']
161164
162165for thing in things:
163- display (thing)
166+ print (thing)
164167`
165168 } ,
166169{
@@ -170,7 +173,7 @@ for thing in things:
170173 f.write("chad")
171174
172175with open("chad.txt", "r") as f:
173- display (f.read())`
176+ print (f.read())`
174177}
175178]
176179
@@ -180,6 +183,9 @@ export default function Home() {
180183
181184 const [ editorCode , setEditorCode ] = useState ( initialCodes [ 0 ] . en ) ;
182185 const [ code , setCode ] = useState ( "" ) ;
186+
187+ const [ outputCode , setOutputCode ] = useState ( "" ) ;
188+
183189 const [ isWaitingForCode , setIsWaitingForCode ] = useState ( false ) ;
184190 const [ isDetected , setIsDetected ] = useState ( false ) ;
185191
@@ -188,6 +194,18 @@ export default function Home() {
188194 const [ sourceLanguage , setSourceLanguage ] = useState ( languages . find ( l => l . code2 === "en" ) )
189195 const [ targetLanguage , setTargetLanguage ] = useState ( languages . find ( ( l ) => l . default ) ) ;
190196
197+ const dummyOutputTerminal = document . getElementById ( "dummy-output-terminal" ) ;
198+
199+ useEffect ( ( ) => {
200+ if ( ! dummyOutputTerminal ) return ;
201+
202+ dummyOutputTerminal . addEventListener ( "change" , ( e ) => {
203+ console . log ( "e.target.value" , e . target . value ) ;
204+ setOutputCode ( e . target . value ) ;
205+ } )
206+ // console.log("dummyOutputTerminal:", dummyOutputTerminal.innerHTML)
207+ // setTimeout(() => setOutputCode(document.getElementById("dummy-output-terminal").innerHTML), 400);
208+ } )
191209
192210 useEffect ( ( ) => {
193211 console . log ( `targetLanguage: ${ targetLanguage . id } ` ) ;
@@ -372,11 +390,13 @@ export default function Home() {
372390 fontSize = { "1rem" }
373391 style = { {
374392 flex : "1 1 auto" ,
375- fontFamily : "Hack, 'Courier New', monospaced" ,
393+ fontFamily : sourceLanguage ?. fontFamily || "Hack, 'Courier New', monospaced" ,
376394 fontSize : "1.15rem" ,
377395 margin : "12px" ,
378396 borderRadius : "8px" ,
379397 overflow : "hidden" ,
398+ direction : sourceLanguage ?. direction || "ltr" ,
399+
380400 } }
381401 />
382402 </ div >
@@ -409,15 +429,15 @@ export default function Home() {
409429 }
410430</ select >
411431< IDE
412- id = "python-code-editor "
413- value = { code
414- . replaceAll ( "display" , "دکھاو" )
415- . replaceAll ( "things" , "چیزیں" )
416- . replaceAll ( "thing" , "چیز" )
417- . replaceAll ( "for" , "ہر" )
418- . replaceAll ( "in" , "اندر" )
419- . replaceAll ( ":" , ":" )
420- }
432+ id = "python-code-editor2 "
433+ // value={code
434+ // .replaceAll("display", "دکھاو")
435+ // .replaceAll("things", "چیزیں")
436+ // .replaceAll("thing", "چیز")
437+ // .replaceAll("for", "ہر")
438+ // .replaceAll("in", "اندر")
439+ // .replaceAll(":", ":")
440+ // }
421441 mode = "python"
422442 // theme="monokai"
423443 // onChange={text => setEditorCode(text)}
@@ -432,11 +452,14 @@ export default function Home() {
432452 fontSize : "1.15rem" ,
433453 // textAlign: "right",
434454 direction : targetLanguage ?. direction || "ltr" ,
435-
455+ fontFamily : targetLanguage ?. fontFamily || undefined ,
436456 margin : "12px" ,
437457 borderRadius : "8px" ,
438- overflow : "hidden" ,
458+ height : "200px" ,
459+ overflow : "auto" ,
460+ // height: "100%",
439461 opacity : isWaitingForCode ? 0.5 : 0.97 ,
462+ whiteSpace : "nowrap"
440463 } }
441464 readOnly = { true }
442465 // background={'#000fff'}
@@ -523,17 +546,93 @@ packages = [
523546 </py-config> */ }
524547
525548{ /* <py-env>{`- universalpython`}</py-env> */ }
526- < py-script style = { {
549+ < py-script
550+ id = "output-terminal"
551+ style = { {
527552 fontFamily : "Hack, 'Courier New', monospaced" ,
528553 marginBottom : "1rem" ,
529554 display : "flex" ,
530555 flexDirection : "column" ,
531- overflowY : "scroll " ,
556+ overflowY : "auto " ,
532557 maxHeight : "300px" ,
533558 padding : "12px 18px 0px" ,
534559 } } key = { code } >
535- { code . toString ( ) }
560+ { `
561+ from urdupython import (run_module, SCRIPTDIR);
562+ from js import document;
563+ import os;
564+ import sys;
565+
566+ original_code = """${ code . toString ( ) } """;
567+ with open('file', 'w') as sys.stdout:
568+ english_code = run_module(
569+ mode="lex",
570+ code=original_code,
571+ args={
572+ 'translate': True,
573+ 'dictionary': os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'),
574+ 'reverse': False,
575+ 'keep': False,
576+ 'keep_only': False,
577+ 'return': True,
578+ }
579+ );
580+ # display(english_code);
581+ print = display
582+ exec(english_code);
583+
584+ translated_code = run_module(
585+ mode="lex",
586+ code=english_code,
587+ args={
588+ 'translate': True,
589+ 'dictionary': os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'),
590+ 'reverse': False,
591+ 'keep': False,
592+ 'keep_only': False,
593+ 'return': True,
594+ }
595+ );
596+ # display(translated_code)
597+ # code = code.replace("print", "display");
598+ element = document.getElementById("python-code-editor2");
599+ # display(element.innerHTML)
600+ element.innerHTML = translated_code.replace("\\n", "<br/>").replace(" ", " ")
601+ # .replace(" ", " ");
602+
603+ `
604+
605+ }
536606 </ py-script >
607+
608+ { /* <input id="dummy-output-terminal" /> */ }
609+ { /*
610+
611+
612+ <py-script key={code}>{`
613+ from urdupython import (run_module, SCRIPTDIR);
614+ import os;
615+ import sys;
616+ with open('file', 'w') as sys.stdout:
617+ code = run_module(
618+ mode="lex",
619+ code="""${code.toString()}""",
620+ args={
621+ 'translate': False,
622+ 'dictionary': os.path.join(SCRIPTDIR, 'languages/ur/ur_native.lang.yaml'),
623+ 'reverse': False,
624+ 'keep': False,
625+ 'keep_only': False,
626+ 'return': True,
627+ }
628+ );
629+ display(code);
630+ eval(code);
631+ # element = document.getElementById("dummy-output-terminal");
632+ # element.value = code;
633+ `
634+ }
635+ </py-script> */ }
537636 </ div >
538637
539638 </ div >
0 commit comments