@@ -3,6 +3,7 @@ import {Contextmenu} from "./contextMenu.js";
33import { Editor } from "./editor/editor.js" ;
44import { Console } from "./emulator/console.js" ;
55import { Etab } from "./executeTab/etab.js" ;
6+ import { instructions } from "./fetches.js" ;
67import { I18n } from "./i18n.js" ;
78import { Project } from "./projects/project.js" ;
89import { ProjFiles } from "./projects/projectFiles.js" ;
@@ -140,6 +141,146 @@ runButton.textContent = I18n.run.run();
140141actionRow . append ( runButton ) ;
141142menu . bindContextmenu ( runButton , undefined , undefined , true ) ;
142143
144+ const helpMenu = new Contextmenu ( "help" ) ;
145+
146+ helpMenu . addButton (
147+ ( ) => I18n . help . help ( ) ,
148+ ( ) => {
149+ const menu = document . createElement ( "dialog" ) ;
150+ document . body . append ( menu ) ;
151+
152+ const title = document . createElement ( "h2" ) ;
153+ title . textContent = I18n . help . webhelp ( ) ;
154+
155+ const tabs = document . createElement ( "div" ) ;
156+ tabs . classList . add ( "flexltr" , "tabStyle" ) ;
157+
158+ const body = document . createElement ( "div" ) ;
159+ body . classList . add ( "flexttb" ) ;
160+
161+ const riscv = document . createElement ( "button" ) ;
162+ riscv . textContent = I18n . help . riscv ( ) ;
163+ let lastSelected = riscv ;
164+ riscv . onclick = ( ) => {
165+ body . innerHTML = "" ;
166+ lastSelected . classList . remove ( "selected" ) ;
167+ lastSelected = riscv ;
168+ riscv . classList . add ( "selected" ) ;
169+ const riscvButtons = document . createElement ( "div" ) ;
170+ riscvButtons . classList . add ( "flexltr" , "tabStyle" ) ;
171+
172+ const riscvBody = document . createElement ( "div" ) ;
173+
174+ const fakes = new Set ( [ "fake" , "veryFake" ] ) ;
175+
176+ const inst = document . createElement ( "button" ) ;
177+ riscvButtons . append ( inst ) ;
178+ let lastSelectedInst = inst ;
179+ inst . textContent = I18n . help . basicInstructions ( ) ;
180+ inst . onclick = ( ) => {
181+ riscvBody . innerHTML = "" ;
182+ lastSelectedInst . classList . remove ( "selected" ) ;
183+ lastSelectedInst = inst ;
184+ inst . classList . add ( "selected" ) ;
185+ const insts = document . createElement ( "table" ) ;
186+ const heightLimitTable = document . createElement ( "div" ) ;
187+ heightLimitTable . classList . add ( "heightLimitTable" ) ;
188+ const instList = instructions
189+ . filter ( ( e ) => ! fakes . has ( e . type ) )
190+ . map ( ( e ) => {
191+ const b = I18n . instructions [ e . name as keyof typeof I18n . instructions ] ;
192+ return [ b . shortDesc ( ) , b . addDescs , b . addDescs ( "$$$" ) . split ( "$$$" ) [ 0 ] . length ] as const ;
193+ } ) ;
194+ const spaces = instList . reduce ( ( acc , cur ) => Math . max ( acc , cur [ 2 ] ) , 0 ) ;
195+ for ( const [ short , desc , len ] of instList ) {
196+ const tr = document . createElement ( "tr" ) ;
197+ const td = document . createElement ( "td" ) ;
198+ insts . append ( tr ) ;
199+ tr . append ( td ) ;
200+ td . textContent = desc ( " " . repeat ( spaces - len + 3 ) + short ) . split ( "\n" ) [ 0 ] ;
201+ }
202+ riscvBody . append ( heightLimitTable ) ;
203+ heightLimitTable . append ( insts ) ;
204+ } ;
205+
206+ const ainst = document . createElement ( "button" ) ;
207+ riscvButtons . append ( ainst ) ;
208+ ainst . textContent = I18n . help . extInstructions ( ) ;
209+ ainst . onclick = ( ) => {
210+ riscvBody . innerHTML = "" ;
211+ lastSelectedInst . classList . remove ( "selected" ) ;
212+ lastSelectedInst = ainst ;
213+ ainst . classList . add ( "selected" ) ;
214+ const insts = document . createElement ( "table" ) ;
215+ const heightLimitTable = document . createElement ( "div" ) ;
216+ heightLimitTable . classList . add ( "heightLimitTable" ) ;
217+ const instList = instructions
218+ . filter ( ( e ) => fakes . has ( e . type ) )
219+ . map ( ( e ) => {
220+ const b = I18n . instructions [ e . name as keyof typeof I18n . instructions ] ;
221+ return [ b . shortDesc ( ) , b . addDescs , b . addDescs ( "$$$" ) . split ( "$$$" ) [ 0 ] . length ] as const ;
222+ } ) ;
223+ const spaces = instList . reduce ( ( acc , cur ) => Math . max ( acc , cur [ 2 ] ) , 0 ) ;
224+ for ( const [ short , desc , len ] of instList ) {
225+ const tr = document . createElement ( "tr" ) ;
226+ const td = document . createElement ( "td" ) ;
227+ insts . append ( tr ) ;
228+ tr . append ( td ) ;
229+ td . textContent = desc ( " " . repeat ( spaces - len + 3 ) + short ) . split ( "\n" ) [ 0 ] ;
230+ }
231+ riscvBody . append ( heightLimitTable ) ;
232+ heightLimitTable . append ( insts ) ;
233+ } ;
234+
235+ const dirs = document . createElement ( "button" ) ;
236+ riscvButtons . append ( dirs ) ;
237+ dirs . textContent = I18n . help . dirs ( ) ;
238+ dirs . onclick = ( ) => {
239+ riscvBody . innerHTML = "" ;
240+ lastSelectedInst . classList . remove ( "selected" ) ;
241+ lastSelectedInst = dirs ;
242+ dirs . classList . add ( "selected" ) ;
243+ const insts = document . createElement ( "table" ) ;
244+ const heightLimitTable = document . createElement ( "div" ) ;
245+ heightLimitTable . classList . add ( "heightLimitTable" ) ;
246+ const keys = Object . keys (
247+ I18n . translations [ 0 ] . directives ,
248+ ) as ( keyof typeof I18n . directives ) [ ] as ( keyof typeof I18n . directives ) [ ] ;
249+ const spaces = keys . reduce ( ( acc , cur ) => Math . max ( acc , cur . length ) , 0 ) ;
250+ for ( const key of keys ) {
251+ const tr = document . createElement ( "tr" ) ;
252+ const td = document . createElement ( "td" ) ;
253+ insts . append ( tr ) ;
254+ tr . append ( td ) ;
255+ td . textContent = "." + key + " " . repeat ( spaces - key . length + 3 ) + I18n . directives [ key ] ( ) ;
256+ }
257+ riscvBody . append ( heightLimitTable ) ;
258+ heightLimitTable . append ( insts ) ;
259+ } ;
260+
261+ inst . click ( ) ;
262+
263+ body . append ( riscvButtons , riscvBody ) ;
264+ } ;
265+ riscv . click ( ) ;
266+
267+ tabs . append ( riscv ) ;
268+ const close = document . createElement ( "button" ) ;
269+ close . textContent = I18n . help . close ( ) ;
270+ close . onclick = ( ) => {
271+ menu . close ( ) ;
272+ } ;
273+ menu . append ( title , tabs , body , close ) ;
274+ menu . setAttribute ( "closedBy" , "any" ) ;
275+ menu . showModal ( ) ;
276+ } ,
277+ ) ;
278+
279+ const helpButton = document . createElement ( "button" ) ;
280+ helpButton . textContent = I18n . help . help ( ) ;
281+ actionRow . append ( helpButton ) ;
282+ helpMenu . bindContextmenu ( helpButton , undefined , undefined , true ) ;
283+
143284const area = document . getElementById ( "area" ) as HTMLElement ;
144285if ( ! area ) throw Error ( "area not found" ) ;
145286let editors : Editor [ ] = [ ] ;
0 commit comments