|
| 1 | +--- |
| 2 | +title: Playground |
| 3 | +description: "TinyGo playground. Run Go code directly in the browser and simulate some popular development boards." |
| 4 | +--- |
| 5 | + |
| 6 | +<link rel="stylesheet" href="/playground/simulator.css"> |
| 7 | +<link rel="stylesheet" href="/playground/simulator-bootstrap.css"> |
| 8 | +<script type="module" src="/playground-play.js"></script> |
| 9 | +<style> |
| 10 | +#playground { |
| 11 | + margin-top: 1.5rem; |
| 12 | + margin-bottom: 0.75rem; |
| 13 | + display: flex; |
| 14 | + flex-direction: column; |
| 15 | +} |
| 16 | +#playground-header { |
| 17 | + display: flex; |
| 18 | + align-items: center; |
| 19 | + justify-content: space-between; |
| 20 | + flex-wrap: wrap; |
| 21 | +} |
| 22 | +#target .project-name .buttons { |
| 23 | + margin-left: 16px; |
| 24 | +} |
| 25 | +.playground-editor { |
| 26 | + min-height: 60vh; |
| 27 | + flex: 1 0 0; |
| 28 | + resize: none; |
| 29 | +} |
| 30 | +.playground-editor:not([style*="height"]) { |
| 31 | + max-height: initial; |
| 32 | +} |
| 33 | +.playground-editor .cm-scroller { |
| 34 | + flex: 1 0 0; |
| 35 | +} |
| 36 | +#middle { |
| 37 | + display: flex; |
| 38 | + flex-grow: 1; |
| 39 | + flex-direction: column; |
| 40 | + gap: 0.75rem; |
| 41 | +} |
| 42 | +#output { |
| 43 | + flex: 1 0 0; |
| 44 | +} |
| 45 | +@media (min-width: 768px) { |
| 46 | + #playground { |
| 47 | + margin-top: 5rem; |
| 48 | + /* 100% - header - padding bottom */ |
| 49 | + height: calc(100vh - 5rem - 0.75rem); |
| 50 | + } |
| 51 | + #middle { |
| 52 | + flex-direction: row; |
| 53 | + } |
| 54 | + .playground-editor { |
| 55 | + min-height: initial; |
| 56 | + } |
| 57 | +} |
| 58 | +</style> |
| 59 | +<div id="playground"> |
| 60 | + <div id="playground-header"> |
| 61 | + <h2>Playground</h2> |
| 62 | + <div> |
| 63 | + <div id="target" class="btn-group mb-2"> |
| 64 | + <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
| 65 | + Console (TinyGo) |
| 66 | + </button> |
| 67 | + <div class="dropdown-menu"> |
| 68 | + <a class="dropdown-item active" href>Console (TinyGo)</a> |
| 69 | + <span id="target-loading" class="dropdown-item disabled">Loading...</span> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + <button type="button" id="btn-flash" class="btn btn-secondary mb-2" disabled>Flash</button> |
| 73 | + <button type="button" id="btn-share" class="btn btn-secondary mb-2">Share</button> |
| 74 | + <button type="button" id="btn-about" class="btn btn-secondary mb-2" data-bs-toggle="modal" data-bs-target="#aboutModal">About</button> |
| 75 | + <a href="/tour/" class="btn btn-secondary mb-2">Tour</a> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + <div id="middle"> |
| 79 | + <div class="playground-editor" tabindex="-1"></div> |
| 80 | + <div id="output" class="simulator inline">{{< readfile "/simulator/simulator.md" >}}</div> |
| 81 | + </div> |
| 82 | + <div class="modal fade" id="aboutModal" tabindex="-1" aria-labelledby="aboutModalTitle" aria-hidden="true"> |
| 83 | + <div class="modal-dialog"> |
| 84 | + <div class="modal-content"> |
| 85 | + <div class="modal-header"> |
| 86 | + <h1 class="modal-title fs-5" id="exampleModalLabel">About TinyGo Playground</h1> |
| 87 | + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
| 88 | + </div> |
| 89 | + <div class="modal-body"> |
| 90 | + <p> |
| 91 | + The TinyGo Playground is a service provided by the TinyGo project |
| 92 | + to compile and run small code samples directly in the browser. It |
| 93 | + has been heavily inspired by the <a |
| 94 | + href="https://play.golang.org/">Go Playground</a> but differs in |
| 95 | + some significant ways: |
| 96 | + </p> |
| 97 | + <ul> |
| 98 | + <li> |
| 99 | + We use the <a href="https://github.com/tinygo-org/tinygo">TinyGo compiler</a> in addition to the main Go compiler. |
| 100 | + </li> |
| 101 | + <li> |
| 102 | + Instead of running code on the server, code is compiled to <a |
| 103 | + href="https://webassembly.org/">WebAssembly</a> and runs |
| 104 | + directly in the browser. |
| 105 | + </li> |
| 106 | + <li> |
| 107 | + It can simulate a few popular boards directly in the browser. |
| 108 | + However, please note that this is a simulation which can differ |
| 109 | + in behavior from how the program will run on an actual device. |
| 110 | + </li> |
| 111 | + <li> |
| 112 | + Boards that support drag-and-drop programming can be flashed |
| 113 | + directly using the Flash button. |
| 114 | + </li> |
| 115 | + </ul> |
| 116 | + <p> |
| 117 | + Like the Go Playground, it's possible to share code |
| 118 | + snippets. These code snippets are stored on Google's |
| 119 | + servers in the US and can be viewed by some TinyGo |
| 120 | + members. While we'll try to make sure the shared data |
| 121 | + can only be accessed by those who have the URL, we |
| 122 | + cannot guarantee security. If you accidentally shared |
| 123 | + something that should not be shared (for example, a |
| 124 | + password or personally identifying information), you can |
| 125 | + contact us at |
| 126 | + |
| 127 | + with the URL so we can remove it. |
| 128 | + </p> |
| 129 | + <p> |
| 130 | + Source code of the playground: <a |
| 131 | + href="https://github.com/tinygo-org/playground">github.com/tinygo-org/playground</a>. |
| 132 | + </p> |
| 133 | + </div> |
| 134 | + <div class="modal-footer"> |
| 135 | + <button type="button" class="btn btn-primary" data-bs-dismiss="modal">Close</button> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + <div class="modal modal-lg fade" id="shareModal" tabindex="-1" aria-labelledby="shareModalLabel" aria-hidden="true"> |
| 141 | + <div class="modal-dialog"> |
| 142 | + <div class="modal-content"> |
| 143 | + <div class="modal-header"> |
| 144 | + <h1 class="modal-title fs-5" id="shareModalLabel">Share</h1> |
| 145 | + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> |
| 146 | + </div> |
| 147 | + <div class="modal-body"> |
| 148 | + <div class="input-group"> |
| 149 | + <input type="text" class="form-control user-select-all" placeholder="Loading..." readonly/> |
| 150 | + <button class="btn btn-outline-secondary copy-to-clipboard" type="button" data-bs-toggle="tooltip" data-bs-title="Copy to clipboard" data-bs-placement="bottom" disabled><span class="fa fa-clipboard"></span></button> |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + </div> |
| 156 | +</div> |
0 commit comments