Advertisement
Guest User

monaco.html

a guest
Nov 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <style type="text/css">
  6. html,
  7. body {
  8. width: 100%;
  9. height: 100%;
  10. margin: 0;
  11. padding: 0;
  12. overflow: hidden;
  13. }
  14. </style>
  15. <meta charset="utf-8" />
  16. <title></title>
  17. </head>
  18. <body>
  19. <div id="container" style="width:100%;height:100%;"></div>
  20. <script src="vs/loader.js"></script>
  21. <script type="text/javascript">
  22. require.config({ paths: { 'vs': 'vs' } });
  23. // API
  24. var GetText;
  25. var SetText;
  26. var SetTheme;
  27. var SetScroll;
  28. var ShowErr;
  29. var Refresh;
  30.  
  31. // Enablers
  32. var SwitchMinimap;
  33. var SwitchReadonly;
  34. var SwitchRenderWhitespace;
  35. var SwitchLinks;
  36. var SwitchLineHeight;
  37. var SwitchFontSize;
  38. var SwitchFolding;
  39. var SwitchAutoIndent;
  40. var SwitchFontFamily;
  41. var SwitchFontLigatures;
  42. var AddIntellisense;
  43.  
  44. // Variables
  45. var editor;
  46. var Proposals = [];
  47.  
  48. require(['vs/editor/editor.main'], function () {
  49. function getDependencyProposals() {
  50. return Proposals;
  51. }
  52.  
  53. monaco.languages.registerCompletionItemProvider('lua', {
  54. provideCompletionItems: function(model, position) {
  55. return getDependencyProposals();
  56. }
  57. });
  58.  
  59. monaco.editor.defineTheme('net-theme-light', {
  60. base: 'vs',
  61. inherit: true,
  62. rules: [
  63. { token: 'global', foreground: '000000' },
  64. { token: 'keyword', foreground: 'ff6a00' },
  65. { token: 'comment', foreground: '666666' },
  66. { token: 'number', foreground: 'ffc600' },
  67. { token: 'string', foreground: 'ff8c3a' },
  68. ]
  69. });
  70.  
  71. monaco.editor.defineTheme('net-theme-dark', {
  72. base: 'vs-dark',
  73. inherit: true,
  74. rules: [
  75. { token: 'global', foreground: 'FFFFFF', fontStyle: "bold" },
  76. { token: 'keyword', foreground: 'ff6a00', fontStyle: "bold" },
  77. { token: 'comment', foreground: '666666' },
  78. { token: 'number', foreground: 'ffc600' },
  79. { token: 'string', foreground: 'ff8c3a' },
  80. ]
  81. });
  82.  
  83. editor = monaco.editor.create(document.getElementById('container'), {
  84. value: [
  85. "--[[",
  86. " Lua Script",
  87. "--]]",
  88. ].join('\n'),
  89. language: 'lua',
  90. theme: "net-theme-light",
  91. folding: true,
  92. scrollbar: {
  93. verticalHasArrows: true,
  94. },
  95. dragAndDrop: true,
  96. links: false,
  97. minimap: {
  98. enabled: false,
  99. },
  100. showFoldingControls: "always",
  101. smoothScrolling: true,
  102. });
  103.  
  104. window.onresize = function() {
  105. editor.layout();
  106. };
  107.  
  108. GetText = function() {
  109. return editor.getValue();
  110. }
  111.  
  112. SetText = function(x) {
  113. editor.setValue(x);
  114. }
  115.  
  116. SetTheme = function(themeName) {
  117. if (themeName == "Dark") {
  118. monaco.editor.setTheme("net-theme-dark");
  119. }
  120. if (themeName == "Light") {
  121. monaco.editor.setTheme("net-theme-light");
  122. }
  123. }
  124.  
  125. SwitchMinimap = function(flag) {
  126. editor.updateOptions({
  127. minimap: {
  128. enabled: flag,
  129. }
  130. });
  131. }
  132.  
  133. SwitchReadonly = function(flag) {
  134. editor.updateOptions({
  135. readOnly: flag,
  136. });
  137. }
  138.  
  139. SwitchRenderWhitespace = function(op) {
  140. editor.updateOptions({
  141. renderWhitespace: op,
  142. });
  143. }
  144.  
  145. SwitchLinks = function(flag) {
  146. editor.updateOptions({
  147. links: flag,
  148. });
  149. }
  150.  
  151. SwitchLineHeight = function(num) {
  152. editor.updateOptions({
  153. lineHeight: num,
  154. });
  155. }
  156.  
  157. SwitchFontSize = function(num) {
  158. editor.updateOptions({
  159. fontSize: num,
  160. });
  161. }
  162.  
  163. SwitchFolding = function(flag) {
  164. editor.updateOptions({
  165. folding: flag,
  166. });
  167. }
  168.  
  169. SwitchAutoIndent = function(flag) {
  170. editor.updateOptions({
  171. autoIndent: flag,
  172. });
  173. }
  174.  
  175. SwitchFontFamily = function(name) {
  176. editor.updateOptions({
  177. fontFamily: name,
  178. });
  179. }
  180.  
  181. SwitchFontLigatures = function(flag) {
  182. editor.updateOptions({
  183. fontLigatures: flag,
  184. });
  185. }
  186.  
  187.  
  188. ShowErr = function(line, column, endline, endcolumn, errMessage) {
  189. editor.revealPositionInCenter({ lineNumber: line, column: column});
  190. editor.deltaDecorations([], [
  191. {
  192. range: new monaco.Range(line, column, endline, endcolumn),
  193. options: {
  194. inlineClassName: 'squiggly-error',
  195. hoverMessage: {
  196. value: errMessage,
  197. }
  198. },
  199. },
  200. ]);
  201. }
  202.  
  203. AddIntellisense = function(l, k, d, i) {
  204. var t;
  205. switch(k)
  206. {
  207. case "Class":
  208. t = monaco.languages.CompletionItemKind.Class;
  209. break;
  210. case "Color":
  211. t = monaco.languages.CompletionItemKind.Color;
  212. break;
  213. case "Constructor":
  214. t = monaco.languages.CompletionItemKind.Constructor;
  215. break;
  216. case "Enum":
  217. t = monaco.languages.CompletionItemKind.Enum;
  218. break;
  219. case "Field":
  220. t = monaco.languages.CompletionItemKind.Field;
  221. break;
  222. case "File":
  223. t = monaco.languages.CompletionItemKind.File;
  224. break;
  225. case "Folder":
  226. t = monaco.languages.CompletionItemKind.Folder;
  227. break;
  228. case "Function":
  229. t = monaco.languages.CompletionItemKind.Function;
  230. break;
  231. case "Interface":
  232. t = monaco.languages.CompletionItemKind.Interface;
  233. break;
  234. case "Keyword":
  235. t = monaco.languages.CompletionItemKind.Keyword;
  236. break;
  237. case "Method":
  238. t = monaco.languages.CompletionItemKind.Method;
  239. break;
  240. case "Module":
  241. t = monaco.languages.CompletionItemKind.Module;
  242. break;
  243. case "Property":
  244. t = monaco.languages.CompletionItemKind.Property;
  245. break;
  246. case "Reference":
  247. t = monaco.languages.CompletionItemKind.Reference;
  248. break;
  249. case "Snippet":
  250. t = monaco.languages.CompletionItemKind.Snippet;
  251. break;
  252. case "Text":
  253. t = monaco.languages.CompletionItemKind.Text;
  254. break;
  255. case "Unit":
  256. t = monaco.languages.CompletionItemKind.Unit;
  257. break;
  258. case "Value":
  259. t = monaco.languages.CompletionItemKind.Value;
  260. break;
  261. case "Variable":
  262. t = monaco.languages.CompletionItemKind.Variable;
  263. break;
  264. }
  265.  
  266. Proposals.push({
  267. label: l,
  268. kind: t,
  269. detail: d,
  270. insertText: i
  271. });
  272. }
  273. document.getElementsByClassName("lines-content monaco-editor-background")[0].style.backgroundImage="url(https://i.imgur.com/nb7ViSd.png)"
  274. document.getElementsByClassName("margin")[0].style.backgroundImage="url(https://i.imgur.com/nb7ViSd.png)"
  275. document.getElementsByClassName("lines-content monaco-editor-background")[0].style.backgroundAttachment="fixed"
  276. document.getElementsByClassName("margin")[0].style.backgroundAttachment="fixed"
  277. document.getElementsByClassName("lines-content monaco-editor-background")[0].style.repeat="no-repeat"
  278. document.getElementsByClassName("margin")[0].style.repeat="no-repeat"
  279. SetScroll = function(line) {
  280. editor.revealLineInCenter({ lineNumber: line});
  281. }
  282.  
  283. Refresh = function() {
  284. var text = getText();
  285. setText("");
  286. editor.trigger('keyboard', 'type', {text: text});
  287. }
  288. });
  289. </script>
  290. </body>
  291. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement